Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Getting an AudioStream to play more than once
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Nai




PostPosted: Fri Apr 22, 2011 10:06 pm   Post subject: Getting an AudioStream to play more than once

I'm trying to make a GUI program that involves playing a sound when buttons are pressed. I got the sound to play once when I click a button for the first time, but if I try to click the buttons again after the first time, the audio will not play. It's like the AudioStream objects I'm using to play the sounds can only be played once? Here's basically the code I'm using:

code:

//I've imported these packages at the start of the program
import sun.audio.*;
import java.io.*;

//At the beginning of my class declaration, I declare the AudioStream variables
static AudioStream blip, boing, uhOh, sub;

//In the init() method,
blip = new AudioStream(new FileInputStream("blip.wav") );
boing = new AudioStream (new FileInputStream ("Boing.wav"));
uhOh = new AudioStream (new FileInputStream ("Uh-Oh.wav"));
sub = new AudioStream (new FileInputStream ("sub.wav"));

//And then when a button is clicked, this should execute
AudioPlayer.player.start(blip);


I've also attached a zip file with the whole thing if you care to look at it. Any ideas for this would be helpful, thanks.



IMastermind.zip
 Description:

Download
 Filename:  IMastermind.zip
 Filesize:  58.32 KB
 Downloaded:  105 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
Nai




PostPosted: Sun Apr 24, 2011 2:45 pm   Post subject: RE:Getting an AudioStream to play more than once

Ok, I got it so never mind. It Involed a Thread.sleep () right after the playing of the clip, and then closing the audiostream and re-opening it.
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 2 Posts ]
Jump to:   


Style:  
Search: