From c6c1f08ab6b26cc933e900cabba82801d78866d7 Mon Sep 17 00:00:00 2001 From: Natan Date: Fri, 18 Oct 2024 19:08:28 -0300 Subject: [PATCH] Fix music --- .../teavm/webaudio/howler/HowlMusic.java | 38 ++++++++++++++----- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/backends/backend-teavm/src/main/java/com/github/xpenatan/gdx/backends/teavm/webaudio/howler/HowlMusic.java b/backends/backend-teavm/src/main/java/com/github/xpenatan/gdx/backends/teavm/webaudio/howler/HowlMusic.java index 63dbe125..ef634835 100644 --- a/backends/backend-teavm/src/main/java/com/github/xpenatan/gdx/backends/teavm/webaudio/howler/HowlMusic.java +++ b/backends/backend-teavm/src/main/java/com/github/xpenatan/gdx/backends/teavm/webaudio/howler/HowlMusic.java @@ -14,6 +14,7 @@ public HowlMusic(FileHandle fileHandle) { byte[] bytes = fileHandle.readBytes(); ArrayBufferViewWrapper data = TypedArrays.getTypedArray(bytes); howl = Howl.create(data); + soundId = -1; } @Override @@ -28,7 +29,9 @@ public void play() { @Override public void pause() { - howl.pause(soundId); + if(soundId != -1) { + howl.pause(soundId); + } } @Override @@ -39,38 +42,55 @@ public void stop() { @Override public boolean isPlaying() { - return howl.isPlaying(soundId); + if(soundId != -1) { + return howl.isPlaying(soundId); + } + return false; } @Override public void setLooping(boolean isLooping) { - howl.setLoop(isLooping, soundId); + if(soundId != -1) { + howl.setLoop(isLooping, soundId); + } } @Override public boolean isLooping() { - return howl.getLoop(soundId); + if(soundId != -1) { + return howl.getLoop(soundId); + } + return false; } @Override public void setVolume(float volume) { - howl.setVolume(volume, soundId); + if(soundId != -1) { + howl.setVolume(volume, soundId); + } } @Override public float getVolume() { - return howl.getVolume(soundId); + if(soundId != -1) { + return howl.getVolume(soundId); + } + return 0f; } @Override public void setPan(float pan, float volume) { - howl.setStereo(pan, soundId); - howl.setVolume(volume, soundId); + if(soundId != -1) { + howl.setStereo(pan, soundId); + howl.setVolume(volume, soundId); + } } @Override public void setPosition(float position) { - howl.setSeek(position, soundId); + if(soundId != -1) { + howl.setSeek(position, soundId); + } } @Override