From bccb1e6147cc9d06cf7f9041d79828bdd570da68 Mon Sep 17 00:00:00 2001 From: redSpoutnik <15638041+redSpoutnik@users.noreply.github.com> Date: Sun, 13 Oct 2019 14:10:51 +0200 Subject: [PATCH] Fix subtitle sync for .ass --- src/components/htmlvideoplayer/plugin.js | 45 ++++++++++++------------ 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/src/components/htmlvideoplayer/plugin.js b/src/components/htmlvideoplayer/plugin.js index 79b135fdad..41ddcf56f7 100644 --- a/src/components/htmlvideoplayer/plugin.js +++ b/src/components/htmlvideoplayer/plugin.js @@ -575,35 +575,34 @@ define(['browser', 'require', 'events', 'apphost', 'loading', 'dom', 'playbackMa self.setSubtitleOffset = function(offset) { var offsetValue = parseFloat(offset); - var videoElement = self._mediaElement; - var mediaStreamTextTracks = getMediaStreamTextTracks(self._currentPlayOptions.mediaSource); - Array.from(videoElement.textTracks) - .filter(function(trackElement) { - // get showing .vtt textTacks - var isVttTrackShowing = trackElement.mode === 'showing'; - // get current .ass textTrack - var isAssTrackShowing = ("textTrack" + customTrackIndex) === trackElement.id; - - return isVttTrackShowing || isAssTrackShowing; - }) - .forEach(function(trackElement) { + // if .ass currently rendering + if(currentAssRenderer){ + updateCurrentTrackOffset(offsetValue); + } else { + var videoElement = self._mediaElement; + var mediaStreamTextTracks = getMediaStreamTextTracks(self._currentPlayOptions.mediaSource); - var track = customTrackIndex === -1 ? null : mediaStreamTextTracks.filter(function (t) { - return t.Index === customTrackIndex; - })[0]; + Array.from(videoElement.textTracks) + .filter(function(trackElement) { + // get showing .vtt textTacks + return trackElement.mode === 'showing'; + }) + .forEach(function(trackElement) { - if(track) { - offsetValue = updateCurrentTrackOffset(offsetValue); - var format = (track.Codec || '').toLowerCase(); - if (format !== 'ass' && format !== 'ssa') { + var track = customTrackIndex === -1 ? null : mediaStreamTextTracks.filter(function (t) { + return t.Index === customTrackIndex; + })[0]; + + if(track) { + offsetValue = updateCurrentTrackOffset(offsetValue); setVttSubtitleOffset(trackElement, offsetValue); + } else { + console.log("No available track, cannot apply offset : " + offsetValue); } - } else { - console.log("No available track, cannot apply offset : " + offsetValue); - } - }); + }); + } }; function updateCurrentTrackOffset(offsetValue) {