v2.4.0: fixed music not properly pausing if tracks are switched

This commit is contained in:
Evan Debenham
2024-02-25 13:18:29 -05:00
parent aa507c7efc
commit 19ac7e7a45

View File

@@ -150,7 +150,7 @@ public enum Music {
} }
public synchronized void update(){ public synchronized void update(){
if (fadeTotal > 0f){ if (fadeTotal > 0f && !paused){
fadeTime += Game.elapsed; fadeTime += Game.elapsed;
if (player != null) { if (player != null) {
@@ -217,7 +217,7 @@ public enum Music {
player = Gdx.audio.newMusic(Gdx.files.internal(track)); player = Gdx.audio.newMusic(Gdx.files.internal(track));
player.setLooping(looping); player.setLooping(looping);
player.setVolume(volumeWithFade()); player.setVolume(volumeWithFade());
player.play(); if (!paused) player.play();
if (listener != null) { if (listener != null) {
player.setOnCompletionListener(listener); player.setOnCompletionListener(listener);
} }
@@ -233,13 +233,17 @@ public enum Music {
stop(); stop();
} }
private boolean paused = false;
public synchronized void pause() { public synchronized void pause() {
paused = true;
if (player != null) { if (player != null) {
player.pause(); player.pause();
} }
} }
public synchronized void resume() { public synchronized void resume() {
paused = false;
if (player != null) { if (player != null) {
player.play(); player.play();
player.setLooping(looping); player.setLooping(looping);