Bugfix: SoundSystem now supports multiple sounds at once.

This commit is contained in:
Jan Philipp Timme 2014-11-11 13:46:26 +01:00
parent c10faf966a
commit 0a460e3ce2
1 changed files with 9 additions and 15 deletions

View File

@ -41,13 +41,6 @@ public class SoundSystem {
*/
private static CompoundControl volCtrl = null;
/**
* Internal SourceDataLine - used to pump out audio data which will
* be played then.
*/
private static SourceDataLine sourceDataLine = null;
/**
* Private constructor, this class will never be instantiated.
*/
@ -111,17 +104,18 @@ public class SoundSystem {
try {
AudioInputStream sound = SoundSystem.getAudioInputStreamByURL(fSoundURL);
sound.reset();
SoundSystem.sourceDataLine = AudioSystem.getSourceDataLine(sound.getFormat());
SoundSystem.sourceDataLine.open(sound.getFormat());
SoundSystem.sourceDataLine.start();
SourceDataLine sourceDataLine = AudioSystem.getSourceDataLine(sound.getFormat());
sourceDataLine.open(sound.getFormat());
sourceDataLine.start();
sound.reset();
byte[] b = new byte[512];
int chunksize = 16384*4;
byte[] b = new byte[chunksize];
while (sound.available() > 0) {
sound.read(b, 0, 512);
SoundSystem.sourceDataLine.write(b, 0, 512);
sound.read(b, 0, chunksize);
sourceDataLine.write(b, 0, chunksize);
}
SoundSystem.sourceDataLine.drain();
SoundSystem.sourceDataLine.close();
sourceDataLine.drain();
sourceDataLine.close();
sound.close();
} catch (Exception e) {
e.printStackTrace();