Playing repeated sound in Java
- by Diogo Schneider
I'm trying to play sounds in a Java game with the following code:
AudioStream audioStream = new AudioStream(stream);
AudioPlayer.player.start(audioStream);
The stream variable is just an InputStream to the resource. By the first time this code is called, the sound is played as expected, but by the second time the program just hangs, not even an exception is thrown.
I don't know what's going on or how to prevent this. If I try closing either stream or audioStream after the above code, the program doesn't hang, but no sound is ever played at all.
Any tips are welcome, thanks.