Skip to content

Commit

Permalink
Desktop: Add null checks to volume (#87)
Browse files Browse the repository at this point in the history
* Add null checks to volume

* Null music if MockAudio

I don't really like this solution but can\'t see a better one.

* More readable with the ternary tbh
  • Loading branch information
Frosty-J authored Mar 3, 2024
1 parent 33d224e commit 7ea9070
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@

package com.badlogic.gdx.video;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.backends.lwjgl3.audio.mock.MockAudio;

import java.nio.ByteBuffer;

public class VideoPlayerDesktop extends CommonVideoPlayerDesktop {
@Override
Music createMusic (VideoDecoder decoder, ByteBuffer audioBuffer, int audioChannels, int sampleRate) {
if (Gdx.audio.getClass() == MockAudio.class) return null;
return new RawMusic(decoder, audioBuffer, audioChannels, sampleRate);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -310,11 +310,12 @@ public boolean isPlaying () {

@Override
public void setVolume (float volume) {
audio.setVolume(volume);
if (audio != null) audio.setVolume(volume);
}

@Override
public float getVolume () {
if (audio == null) return 0;
return audio.getVolume();
}

Expand Down

0 comments on commit 7ea9070

Please sign in to comment.