1
\$\begingroup\$

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.

\$\endgroup\$
4
  • \$\begingroup\$ I've just tested it again on Windows and it works flawlessly. The problem only happens on Linux. \$\endgroup\$ – Diogo Schneider Apr 13 '14 at 22:45
  • \$\begingroup\$ Is there some sort of playback position you can reset to 0 between calls, or some sort of loop property you can set to true? \$\endgroup\$ – ashes999 Apr 14 '14 at 4:20
  • \$\begingroup\$ Not as far as I can see from these objects' methods. But even if there was a 'loop' field, it would be a problem because the sound would probably repeat itself infinitely. \$\endgroup\$ – Diogo Schneider Apr 14 '14 at 12:06
  • 1
    \$\begingroup\$ Well, since this is a Linux-only issue I have posted a bug to OpenJDK and just disabled sound if a Linux OS is detected. The code runs perfect in Mac OS X and Windows. \$\endgroup\$ – Diogo Schneider Apr 20 '14 at 15:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.