From 13a81396bd5183d1f2c00c517936c54efaa61db3 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Sat, 23 Sep 2023 20:44:09 +0200 Subject: Bug 1455 - GLMediaPlayer: Add isAutioMuted() query on volume and earmark audio-volume if not initialized and set it when AudioSink becomes available Setting the audio volume before initialization shall impact GLMediaPlayer when it becomes initialized. Further add a query if audio is muted, merely based on volume. --- .../com/jogamp/opengl/util/av/GLMediaPlayer.java | 3 +++ .../jogamp/opengl/util/av/GLMediaPlayerImpl.java | 27 ++++++++++++++++++---- 2 files changed, 25 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/jogl/classes/com/jogamp/opengl/util/av/GLMediaPlayer.java b/src/jogl/classes/com/jogamp/opengl/util/av/GLMediaPlayer.java index 51724d240..3e4d589f3 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/av/GLMediaPlayer.java +++ b/src/jogl/classes/com/jogamp/opengl/util/av/GLMediaPlayer.java @@ -545,6 +545,9 @@ public interface GLMediaPlayer extends TextureSequence { /** Returns the audio volume. */ public float getAudioVolume(); + /** Returns true if audio is muted, i.e. {@link #setAudioVolume(float)} to zero. */ + public boolean isAudioMuted(); + /** * Starts or resumes the StreamWorker decoding thread. *

diff --git a/src/jogl/classes/jogamp/opengl/util/av/GLMediaPlayerImpl.java b/src/jogl/classes/jogamp/opengl/util/av/GLMediaPlayerImpl.java index 3ca5f9aac..8859d537e 100644 --- a/src/jogl/classes/jogamp/opengl/util/av/GLMediaPlayerImpl.java +++ b/src/jogl/classes/jogamp/opengl/util/av/GLMediaPlayerImpl.java @@ -59,6 +59,7 @@ import com.jogamp.common.util.InterruptSource; import com.jogamp.common.util.LFRingbuffer; import com.jogamp.common.util.Ringbuffer; import com.jogamp.common.util.WorkerThread; +import com.jogamp.math.FloatUtil; import com.jogamp.opengl.GLExtensions; import com.jogamp.opengl.util.av.GLMediaPlayer; import com.jogamp.opengl.util.glsl.ShaderCode; @@ -533,6 +534,12 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer { getAudioVolumeImpl(); return audioVolume; } + + @Override + public boolean isAudioMuted() { + return FloatUtil.isZero(audioVolume); + } + /** * Override if not using AudioSink, or AudioSink's {@link AudioSink#getVolume()} is not sufficient! */ @@ -542,21 +549,30 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer { } } + private static final float clipAudioVolume(final float v) { + if( v < 0.01f ) { + return 0.0f; + } else if( Math.abs(1.0f - v) < 0.01f ) { + return 1.0f; + } + return v; + } + @Override public boolean setAudioVolume(float v) { synchronized( stateLock ) { final float preVolume = audioVolume; boolean res = false; + v = clipAudioVolume(v); if(State.Uninitialized != state ) { - if( Math.abs(v) < 0.01f ) { - v = 0.0f; - } else if( Math.abs(1.0f - v) < 0.01f ) { - v = 1.0f; - } if( setAudioVolumeImpl(v) ) { audioVolume = v; res = true; } + } else { + // earmark .. + audioVolume = v; + res = true; } if(DEBUG) { System.err.println("setAudioVolume("+v+"): "+state+", "+preVolume+" -> "+audioVolume+", "+toString()); } return res; @@ -682,6 +698,7 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer { removeAllTextureFrames(gl); if( State.Uninitialized != state ) { initGLImpl(gl); + setAudioVolume( audioVolume ); // update volume if(DEBUG) { System.err.println("initGLImpl.X "+this); } -- cgit v1.2.3