From f33699ad8a341383b422fba8bca92343a5ef494d Mon Sep 17 00:00:00 2001 From: Ivan Schurawel Date: Sun, 9 Oct 2022 22:33:08 -0400 Subject: [PATCH] fix: only show secondary if primary sill valid, remove resolveOnClick --- src/controllers/playback/video/index.js | 18 +++++++++++++++--- src/plugins/htmlVideoPlayer/plugin.js | 24 +++++++++++++++++------- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/src/controllers/playback/video/index.js b/src/controllers/playback/video/index.js index 6ca0f59b4..dfbf714c7 100644 --- a/src/controllers/playback/video/index.js +++ b/src/controllers/playback/video/index.js @@ -1062,8 +1062,21 @@ import { setBackdropTransparency, TRANSPARENCY_LEVEL } from '../../../components return opt; }); - // Only show option if: player has support, has more than 1 subtitle track, has valid secondary tracks, primary subtitle is not off - if (playbackManager.hasSecondarySubtitleSupport(player) && streams.length > 1 && secondaryStreams.length > 0 && currentIndex !== -1) { + /** + * Only show option if: + * - player has support + * - has more than 1 subtitle track + * - has valid secondary tracks + * - primary subtitle is not off + * - primary subtitle is `External` + */ + if ( + playbackManager.hasSecondarySubtitleSupport(player) && + streams.length > 1 && + secondaryStreams.length > 0 && + currentIndex !== -1 && + playbackManager.isSubtitleStreamExternal(currentIndex, player) + ) { const secondarySubtitleMenuItem = { name: globalize.translate('SecondarySubtitles'), id: 'secondarysubtitle' @@ -1077,7 +1090,6 @@ import { setBackdropTransparency, TRANSPARENCY_LEVEL } from '../../../components actionsheet.show({ title: globalize.translate('Subtitles'), items: menuItems, - resolveOnClick: true, positionTo: positionTo }).then(function (id) { if (id === 'secondarysubtitle') { diff --git a/src/plugins/htmlVideoPlayer/plugin.js b/src/plugins/htmlVideoPlayer/plugin.js index 74a824706..d00ff53d2 100644 --- a/src/plugins/htmlVideoPlayer/plugin.js +++ b/src/plugins/htmlVideoPlayer/plugin.js @@ -471,15 +471,30 @@ function tryRemoveElement(elem) { destroyFlvPlayer(this); destroyCastPlayer(this); + let secondaryTrackValid = true; + this.#subtitleTrackIndexToSetOnPlaying = options.mediaSource.DefaultSubtitleStreamIndex == null ? -1 : options.mediaSource.DefaultSubtitleStreamIndex; if (this.#subtitleTrackIndexToSetOnPlaying != null && this.#subtitleTrackIndexToSetOnPlaying >= 0) { const initialSubtitleStream = options.mediaSource.MediaStreams[this.#subtitleTrackIndexToSetOnPlaying]; if (!initialSubtitleStream || initialSubtitleStream.DeliveryMethod === 'Encode') { this.#subtitleTrackIndexToSetOnPlaying = -1; } + // secondary track should not be shown if primary track is no longer `External` or is not on + if (initialSubtitleStream && initialSubtitleStream.DeliveryMethod !== 'External') { + secondaryTrackValid = false; + } + } else { + secondaryTrackValid = false; } - // Continue using the secondary track that has been set during this watch session - const currentSecondaryTrackIndex = playbackManager.getSecondarySubtitleStreamIndex(); + + // Get the secondary track that has been set during this watch session + let currentSecondaryTrackIndex = playbackManager.getSecondarySubtitleStreamIndex(); + + if (!secondaryTrackValid) { + currentSecondaryTrackIndex = -1; + playbackManager.setSecondarySubtitleStreamIndex(currentSecondaryTrackIndex); + } + this.#secondarySubtitleTrackIndexToSetOnPlaying = currentSecondaryTrackIndex == null ? -1 : currentSecondaryTrackIndex; if (this.#secondarySubtitleTrackIndexToSetOnPlaying != null && this.#secondarySubtitleTrackIndexToSetOnPlaying >= 0) { const initialSecondarySubtitleStream = options.mediaSource.MediaStreams[this.#secondarySubtitleTrackIndexToSetOnPlaying]; @@ -1118,11 +1133,6 @@ function tryRemoveElement(elem) { * @private */ destroyCustomTrack(videoElement, targetTrackIndex) { - if (this.#resizeObserver) { - this.#resizeObserver.disconnect(); - this.#resizeObserver = null; - } - this.destroyCustomRenderedTrackElements(targetTrackIndex); this.destroyNativeTracks(videoElement, targetTrackIndex); this.destroyStoredTrackInfo(targetTrackIndex);