From 2d12aec9b425da4d768af30a92fbc14dfa4f87c7 Mon Sep 17 00:00:00 2001 From: gnattu Date: Sun, 22 Sep 2024 00:36:29 +0800 Subject: [PATCH] Only load subtitle when direct play/remux --- src/plugins/htmlVideoPlayer/plugin.js | 52 ++++++++++++++++++++++----- 1 file changed, 44 insertions(+), 8 deletions(-) diff --git a/src/plugins/htmlVideoPlayer/plugin.js b/src/plugins/htmlVideoPlayer/plugin.js index 46a3062a11..908248e6a4 100644 --- a/src/plugins/htmlVideoPlayer/plugin.js +++ b/src/plugins/htmlVideoPlayer/plugin.js @@ -1,6 +1,7 @@ import DOMPurify from 'dompurify'; import browser from '../../scripts/browser'; +import appSettings from '../../scripts/settings/appSettings'; import { appHost } from '../../components/apphost'; import loading from '../../components/loading/loading'; import dom from '../../scripts/dom'; @@ -1566,15 +1567,50 @@ export class HtmlVideoPlayer { return t.Index === streamIndex; })[0]; - this.setTrackForDisplay(this.#mediaElement, track, targetTextTrackIndex); - if (enableNativeTrackSupport(this._currentPlayOptions?.mediaSource, track)) { - if (streamIndex !== -1) { - this.setCueAppearance(); - } + // This play method can only check if it is real direct play, and will mark Remux as Transcode as well + const isDirectPlay = this._currentPlayOptions.playMethod === "DirectPlay"; + const burnInWhenTranscoding = appSettings.alwaysBurnInSubtitleWhenTranscoding(); + + if (!isDirectPlay && burnInWhenTranscoding) { + const apiClient = ServerConnections.getApiClient(this._currentPlayOptions.item.ServerId); + const sessionPromise = apiClient.getSessions({ + deviceId: apiClient.deviceId() + }).then(function (sessions) { + return sessions[0] || {};; + }, function () { + return Promise.resolve({}); + }); + + const player = this; + + sessionPromise.then((s) => { + if (!s.TranscodingInfo || s.TranscodingInfo?.IsVideoDirect) { + player.setTrackForDisplay(player.#mediaElement, track, targetTextTrackIndex); + if (enableNativeTrackSupport(player._currentPlayOptions?.mediaSource, track)) { + if (streamIndex !== -1) { + player.setCueAppearance(); + } + } else { + // null these out to disable the player's native display (handled below) + streamIndex = -1; + track = null; + } + } else { + // unset stream when switching to transcode + player.setTrackForDisplay(player.#mediaElement, null, -1); + } + }) } else { - // null these out to disable the player's native display (handled below) - streamIndex = -1; - track = null; + this.setTrackForDisplay(this.#mediaElement, track, targetTextTrackIndex); + if (enableNativeTrackSupport(this._currentPlayOptions?.mediaSource, track)) { + if (streamIndex !== -1) { + this.setCueAppearance(); + } + } else { + // null these out to disable the player's native display (handled below) + streamIndex = -1; + track = null; + } } }