From ee72b89f6ee3400d5b86802a5d1325772ba75460 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Velad=20Galv=C3=A1n?= Date: Fri, 22 Nov 2024 06:52:13 +0100 Subject: [PATCH] feat(UI): Add config to show the audio codec in the audio selector (#7644) --- ui/audio_language_selection.js | 3 ++- ui/externs/ui.js | 6 +++++- ui/language_utils.js | 11 ++++++----- ui/text_selection.js | 3 ++- ui/ui.js | 1 + 5 files changed, 16 insertions(+), 8 deletions(-) diff --git a/ui/audio_language_selection.js b/ui/audio_language_selection.js index c252f1ddc4..07d34bc4ab 100644 --- a/ui/audio_language_selection.js +++ b/ui/audio_language_selection.js @@ -73,7 +73,8 @@ shaka.ui.AudioLanguageSelection = class extends shaka.ui.SettingsMenu { (track) => this.onAudioTrackSelected_(track), /* updateChosen= */ true, this.currentSelection, this.localization, this.controls.getConfig().trackLabelFormat, - this.controls.getConfig().showAudioChannelCountVariants); + this.controls.getConfig().showAudioChannelCountVariants, + this.controls.getConfig().showAudioCodec); shaka.ui.Utils.focusOnTheChosenItem(this.menu); this.controls.dispatchEvent( diff --git a/ui/externs/ui.js b/ui/externs/ui.js index b297bae074..737d90e8a4 100644 --- a/ui/externs/ui.js +++ b/ui/externs/ui.js @@ -98,7 +98,8 @@ shaka.extern.UIVolumeBarColors; * displayInVrMode: boolean, * defaultVrProjectionMode: string, * setupMediaSession: boolean, - * preferVideoFullScreenInVisionOS: boolean + * preferVideoFullScreenInVisionOS: boolean, + * showAudioCodec: boolean * }} * * @property {!Array.} controlPanelElements @@ -261,6 +262,9 @@ shaka.extern.UIVolumeBarColors; * experiences that are only allowed with the fullscreen of the video element * itself. * Defaults to false. + * @property {boolean} showAudioCodec + * Show the audio codec if the language has more than one audio codec. + * Defaults to true. * @exportDoc */ shaka.extern.UIConfiguration; diff --git a/ui/language_utils.js b/ui/language_utils.js index dab269510d..395b79b20f 100644 --- a/ui/language_utils.js +++ b/ui/language_utils.js @@ -27,10 +27,11 @@ shaka.ui.LanguageUtils = class { * @param {shaka.ui.Localization} localization * @param {shaka.ui.Overlay.TrackLabelFormat} trackLabelFormat * @param {boolean} showAudioChannelCountVariants + * @param {boolean} showAudioCodec */ static updateTracks(tracks, langMenu, onTrackSelected, updateChosen, currentSelectionElement, localization, trackLabelFormat, - showAudioChannelCountVariants) { + showAudioChannelCountVariants, showAudioCodec) { const LocIds = shaka.ui.Locales.Ids; // TODO: Do the benefits of having this common code in a method still @@ -82,7 +83,7 @@ shaka.ui.LanguageUtils = class { if (showAudioChannelCountVariants && channelsCount != null) { keys.push(channelsCount); } - if (hasDifferentAudioCodecs(language) && audioCodec) { + if (showAudioCodec && hasDifferentAudioCodecs(language) && audioCodec) { keys.push(audioCodec); } if (label && @@ -162,7 +163,7 @@ shaka.ui.LanguageUtils = class { shaka.ui.LanguageUtils.getLanguageName(language, localization); switch (trackLabelFormat) { case shaka.ui.Overlay.TrackLabelFormat.LANGUAGE: - if (hasDifferentAudioCodecs(language)) { + if (showAudioCodec && hasDifferentAudioCodecs(language)) { span.textContent += getAudioCodecName(audioCodec); } if (showAudioChannelCountVariants) { @@ -173,7 +174,7 @@ shaka.ui.LanguageUtils = class { } break; case shaka.ui.Overlay.TrackLabelFormat.ROLE: - if (hasDifferentAudioCodecs(language)) { + if (showAudioCodec && hasDifferentAudioCodecs(language)) { span.textContent += getAudioCodecName(audioCodec); } if (showAudioChannelCountVariants) { @@ -192,7 +193,7 @@ shaka.ui.LanguageUtils = class { } break; case shaka.ui.Overlay.TrackLabelFormat.LANGUAGE_ROLE: - if (hasDifferentAudioCodecs(language)) { + if (showAudioCodec && hasDifferentAudioCodecs(language)) { span.textContent += getAudioCodecName(audioCodec); } if (showAudioChannelCountVariants) { diff --git a/ui/text_selection.js b/ui/text_selection.js index 4e9ef60a41..dfb4318dd8 100644 --- a/ui/text_selection.js +++ b/ui/text_selection.js @@ -140,7 +140,8 @@ shaka.ui.TextSelection = class extends shaka.ui.SettingsMenu { this.currentSelection, this.localization, this.controls.getConfig().textTrackLabelFormat, - this.controls.getConfig().showAudioChannelCountVariants); + this.controls.getConfig().showAudioChannelCountVariants, + this.controls.getConfig().showAudioCodec); // Add the Off button const offButton = shaka.util.Dom.createButton(); diff --git a/ui/ui.js b/ui/ui.js index 346e30ea72..b7cf584c0c 100644 --- a/ui/ui.js +++ b/ui/ui.js @@ -274,6 +274,7 @@ shaka.ui.Overlay = class { defaultVrProjectionMode: 'equirectangular', setupMediaSession: true, preferVideoFullScreenInVisionOS: false, + showAudioCodec: true, }; // eslint-disable-next-line no-restricted-syntax