Getting an AudioStream to play more than once
Author |
Message |
Nai
|
Posted: 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.
Description: |
|
Download |
Filename: |
IMastermind.zip |
Filesize: |
58.32 KB |
Downloaded: |
105 Time(s) |
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
Nai
|
Posted: 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.
|
|
|
|
|
|
|
|