Bugfix: SoundSystem now supports multiple sounds at once.
This commit is contained in:
parent
c10faf966a
commit
0a460e3ce2
@ -41,13 +41,6 @@ public class SoundSystem {
|
|||||||
*/
|
*/
|
||||||
private static CompoundControl volCtrl = null;
|
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.
|
* Private constructor, this class will never be instantiated.
|
||||||
*/
|
*/
|
||||||
@ -111,17 +104,18 @@ public class SoundSystem {
|
|||||||
try {
|
try {
|
||||||
AudioInputStream sound = SoundSystem.getAudioInputStreamByURL(fSoundURL);
|
AudioInputStream sound = SoundSystem.getAudioInputStreamByURL(fSoundURL);
|
||||||
sound.reset();
|
sound.reset();
|
||||||
SoundSystem.sourceDataLine = AudioSystem.getSourceDataLine(sound.getFormat());
|
SourceDataLine sourceDataLine = AudioSystem.getSourceDataLine(sound.getFormat());
|
||||||
SoundSystem.sourceDataLine.open(sound.getFormat());
|
sourceDataLine.open(sound.getFormat());
|
||||||
SoundSystem.sourceDataLine.start();
|
sourceDataLine.start();
|
||||||
sound.reset();
|
sound.reset();
|
||||||
byte[] b = new byte[512];
|
int chunksize = 16384*4;
|
||||||
|
byte[] b = new byte[chunksize];
|
||||||
while (sound.available() > 0) {
|
while (sound.available() > 0) {
|
||||||
sound.read(b, 0, 512);
|
sound.read(b, 0, chunksize);
|
||||||
SoundSystem.sourceDataLine.write(b, 0, 512);
|
sourceDataLine.write(b, 0, chunksize);
|
||||||
}
|
}
|
||||||
SoundSystem.sourceDataLine.drain();
|
sourceDataLine.drain();
|
||||||
SoundSystem.sourceDataLine.close();
|
sourceDataLine.close();
|
||||||
sound.close();
|
sound.close();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
Loading…
Reference in New Issue
Block a user