Support switching tracks when music completes

This commit is contained in:
drdev
2014-06-29 03:22:46 +00:00
parent 4a78323b3c
commit 7c821455aa
6 changed files with 29 additions and 11 deletions

View File

@@ -1,7 +1,7 @@
package forge.sound;
public interface IAudioMusic {
void play();
void play(final Runnable onComplete);
void pause();
void resume();
void stop();

View File

@@ -18,6 +18,7 @@ import java.util.Map;
*
*/
public class SoundSystem {
public static final int DELAY = 30;
private static final IAudioClip emptySound = new NoSoundClip();
private static final Map<SoundEffectType, IAudioClip> loadedClips = new EnumMap<SoundEffectType, IAudioClip>(SoundEffectType.class);
@@ -181,7 +182,18 @@ public class SoundSystem {
try {
currentTrack = GuiBase.getInterface().createAudioMusic(filename);
currentTrack.play();
currentTrack.play(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(SoundSystem.DELAY);
}
catch (InterruptedException ex) {
ex.printStackTrace();
}
changeBackgroundTrack(); //change track when music completes on its own
}
});
}
catch (Exception ex) {
System.err.println("Unable to load music file: " + filename);