aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2023-09-23 20:44:09 +0200
committerSven Gothel <[email protected]>2023-09-23 20:44:09 +0200
commit13a81396bd5183d1f2c00c517936c54efaa61db3 (patch)
tree5ad6a6d5b808092ef013c8413e187382d242d5f6 /src
parent84b26f9efcd62cc8c41bf3cd867482080d16d7a0 (diff)
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.
Diffstat (limited to 'src')
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/av/GLMediaPlayer.java3
-rw-r--r--src/jogl/classes/jogamp/opengl/util/av/GLMediaPlayerImpl.java27
2 files changed, 25 insertions, 5 deletions
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 <i>StreamWorker</i> decoding thread.
* <p>
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);
}