add showingSubtitle control

This commit is contained in:
redSpoutnik 2019-04-08 20:21:16 +02:00
parent b3716dc20b
commit 275fd078e2

View File

@ -188,6 +188,7 @@ define(['browser', 'require', 'events', 'apphost', 'loading', 'dom', 'playbackMa
var currentAssRenderer; var currentAssRenderer;
var customTrackIndex = -1; var customTrackIndex = -1;
var showTrackOffset = false;
var currentTrackOffset; var currentTrackOffset;
var videoSubtitlesElem; var videoSubtitlesElem;
@ -545,6 +546,18 @@ define(['browser', 'require', 'events', 'apphost', 'loading', 'dom', 'playbackMa
setCurrentTrackElement(index); setCurrentTrackElement(index);
}; };
self.enableShowingSubtitleOffset = function() {
showTrackOffset = true;
}
self.disableShowingSubtitleOffset = function() {
showTrackOffset = false;
}
self.isShowingSubtitleOffsetEnabled = function() {
return showTrackOffset;
}
self.setSubtitleOffset = function(offset) { self.setSubtitleOffset = function(offset) {
var offsetValue = parseFloat(offset); var offsetValue = parseFloat(offset);
@ -552,7 +565,7 @@ define(['browser', 'require', 'events', 'apphost', 'loading', 'dom', 'playbackMa
var mediaStreamTextTracks = getMediaStreamTextTracks(self._currentPlayOptions.mediaSource); var mediaStreamTextTracks = getMediaStreamTextTracks(self._currentPlayOptions.mediaSource);
Array.from(videoElement.textTracks) Array.from(videoElement.textTracks)
.filter(trackElement => { .filter((trackElement) => {
if (customTrackIndex === -1 ) { if (customTrackIndex === -1 ) {
// get showing .vtt textTacks // get showing .vtt textTacks
return trackElement.mode === 'showing'; return trackElement.mode === 'showing';
@ -563,7 +576,7 @@ define(['browser', 'require', 'events', 'apphost', 'loading', 'dom', 'playbackMa
}) })
.forEach(trackElement => { .forEach(trackElement => {
var track = mediaStreamTextTracks.filter(stream => { var track = mediaStreamTextTracks.filter((stream) => {
return ("textTrack" + stream.Index) === trackElement.id; return ("textTrack" + stream.Index) === trackElement.id;
})[0]; })[0];
@ -596,7 +609,7 @@ define(['browser', 'require', 'events', 'apphost', 'loading', 'dom', 'playbackMa
if(currentTrack.cues) { if(currentTrack.cues) {
Array.from(currentTrack.cues) Array.from(currentTrack.cues)
.forEach(cue => { .forEach((cue) => {
cue.startTime -= offsetValue; cue.startTime -= offsetValue;
cue.endTime -= offsetValue; cue.endTime -= offsetValue;
}); });
@ -604,6 +617,10 @@ define(['browser', 'require', 'events', 'apphost', 'loading', 'dom', 'playbackMa
} }
self.getSubtitleOffset = function() {
return currentTrackOffset;
}
function isAudioStreamSupported(stream, deviceProfile) { function isAudioStreamSupported(stream, deviceProfile) {
var codec = (stream.Codec || '').toLowerCase(); var codec = (stream.Codec || '').toLowerCase();