From 0b908ee7fc80344118d3fa6d4d92ebb082968cb3 Mon Sep 17 00:00:00 2001 From: Sven Göthel Date: Sat, 27 Jan 2024 07:37:09 +0100 Subject: GraphUI MediaPlayer Widget: Support switching audio and subtitle streams, show their language as a button - press to switch to next --- .../com/jogamp/graph/ui/widgets/MediaPlayer.java | 61 +++++++++++++++++++--- 1 file changed, 54 insertions(+), 7 deletions(-) (limited to 'src/graphui/classes/com/jogamp') diff --git a/src/graphui/classes/com/jogamp/graph/ui/widgets/MediaPlayer.java b/src/graphui/classes/com/jogamp/graph/ui/widgets/MediaPlayer.java index bd106f1b0..283e566f5 100644 --- a/src/graphui/classes/com/jogamp/graph/ui/widgets/MediaPlayer.java +++ b/src/graphui/classes/com/jogamp/graph/ui/widgets/MediaPlayer.java @@ -29,6 +29,7 @@ package com.jogamp.graph.ui.widgets; import java.io.IOException; import java.util.List; +import java.util.Locale; import java.util.concurrent.atomic.AtomicReference; import com.jogamp.common.av.PTS; @@ -112,7 +113,7 @@ public class MediaPlayer extends Widget { final float zEpsilon = scene.getZEpsilon(16); final float ctrlZOffset = zEpsilon * 20f; - final int ctrlCellsInt = 9; + final int ctrlCellsInt = 10+2; final int ctrlCells = Math.max(customCtrls.size() + ctrlCellsInt, 13); final float ctrlCellWidth = (aratio-2*BorderSzS)/ctrlCells; @@ -147,6 +148,13 @@ public class MediaPlayer extends Widget { playButton.setName("mp.play"); playButton.setSpacing(SymSpacing, FixedSymSize).setPerp().setColor(CtrlCellCol); + final Button audioLabel = new Button(renderModes, fontInfo, "audio\nund", CtrlButtonWidth, CtrlButtonHeight, zEpsilon); + audioLabel.setName("mp.audio_lang").setToggleable(false); + audioLabel.setPerp().setColor(CtrlCellCol); + final Button subLabel = new Button(renderModes, fontInfo, "sub\nund", CtrlButtonWidth, CtrlButtonHeight, zEpsilon); + subLabel.setName("mp.sub_lang").setToggleable(false); + subLabel.setPerp().setColor(CtrlCellCol); + { mButton.setVerbose(false).addDefaultEventListener().setTextureLetterbox(letterBox); mPlayer.setAudioVolume( 0f ); @@ -156,11 +164,13 @@ public class MediaPlayer extends Widget { @Override public void attributesChanged(final GLMediaPlayer mp, final EventMask eventMask, final long when) { - if( DEBUG ) { + if( DEBUG || true ) { System.err.println("MediaButton AttributesChanges: "+eventMask+", when "+when); System.err.println("MediaButton State: "+mp); } if( eventMask.isSet(GLMediaPlayer.EventMask.Bit.Init) ) { + audioLabel.setText("audio\n"+mp.getLang(mp.getAID())); + subLabel.setText("sub\n"+mp.getLang(mp.getSID())); ctrlSlider.setMinMax(new Vec2f(0, mp.getDuration()), 0); if( DEBUG ) { System.err.println(mp.toString()); @@ -429,9 +439,29 @@ public class MediaPlayer extends Widget { button.setToolTip(new TooltipText("Volume", fontInfo, toolTipScaleY)); } { // 8 + audioLabel.onClicked((final Shape s) -> { + final int next_aid = mPlayer.getNextAID(); + if( mPlayer.getAID() != next_aid ) { + mPlayer.switchStream(mPlayer.getVID(), next_aid, mPlayer.getSID()); + } + }); + ctrlGroup.addShape(audioLabel); + audioLabel.setToolTip(new TooltipText("Audio Language", fontInfo, toolTipScaleY)); + } + { // 9 + subLabel.onClicked((final Shape s) -> { + final int next_sid = mPlayer.getNextSID(); + if( mPlayer.getSID() != next_sid ) { + mPlayer.switchStream(mPlayer.getVID(), mPlayer.getAID(), next_sid); + } + }); + ctrlGroup.addShape(subLabel); + subLabel.setToolTip(new TooltipText("Subtitle Language", fontInfo, toolTipScaleY)); + } + { // 10 ctrlGroup.addShape(timeLabel); } - for(int i=8; i