Skip to content

Commit

Permalink
Fix a bug that lead to wrong selection of initial WebVTT track (#4086)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsilhavy committed Nov 10, 2022
1 parent b63d175 commit 9d65cb5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 29 deletions.
1 change: 0 additions & 1 deletion src/streaming/Stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,6 @@ function Stream(config) {

if (embeddedMediaInfos.length > 0) {
mediaController.setInitialMediaSettingsForType(type, streamInfo);
textController.setInitialSettings(mediaController.getInitialSettings(type));
textController.addMediaInfosToBuffer(streamInfo, type, embeddedMediaInfos);
}

Expand Down
37 changes: 9 additions & 28 deletions src/streaming/text/TextController.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,14 @@ function TextController(config) {
vttParser,
ttmlParser,
eventBus,
defaultSettings,
initialSettingsSet,
allTracksAreDisabled,
forceTextStreaming,
textTracksAdded,
disableTextBeforeTextTracksAdded;

function setup() {
defaultSettings = null;
forceTextStreaming = false;
textTracksAdded = false;
initialSettingsSet = false;
disableTextBeforeTextTracksAdded = false;

vttParser = VTTParser(context).getInstance();
Expand All @@ -79,7 +75,6 @@ function TextController(config) {
}

function initialize() {
eventBus.on(Events.CURRENT_TRACK_CHANGED, _onCurrentTrackChanged, instance);
eventBus.on(Events.TEXT_TRACKS_QUEUE_INITIALIZED, _onTextTracksAdded, instance);
}

Expand Down Expand Up @@ -161,11 +156,6 @@ function TextController(config) {
textSourceBuffers[streamId].addEmbeddedTrack(mediaInfo);
}

function setInitialSettings(settings) {
defaultSettings = settings;
initialSettingsSet = true;
}

function _onTextTracksAdded(e) {
let tracks = e.tracks;
let index = e.index;
Expand All @@ -177,7 +167,15 @@ function TextController(config) {
// disable text at startup if explicitly configured with setTextDefaultEnabled(false) or if there is no defaultSettings (configuration or from domStorage)
setTextTrack(streamId, -1);
} else {
if (defaultSettings) {
const currentTrack = mediaController.getCurrentTrackFor(Constants.TEXT, streamId);
if (currentTrack) {
const defaultSettings = {
lang: currentTrack.lang,
role: currentTrack.roles[0],
index: currentTrack.index,
codec: currentTrack.codec,
accessibility: currentTrack.accessibility[0]
};
tracks.some((item, idx) => {
// matchSettings is compatible with setTextDefaultLanguage and setInitialSettings
if (mediaController.matchSettings(defaultSettings, item)) {
Expand All @@ -202,21 +200,6 @@ function TextController(config) {
textTracksAdded = true;
}

function _onCurrentTrackChanged(event) {
if (!initialSettingsSet && event && event.newMediaInfo) {
let mediaInfo = event.newMediaInfo;
if (mediaInfo.type === Constants.TEXT) {
defaultSettings = {
lang: mediaInfo.lang,
role: mediaInfo.roles[0],
index: mediaInfo.index,
codec: mediaInfo.codec,
accessibility: mediaInfo.accessibility[0]
};
}
}
}

function enableText(streamId, enable) {
checkParameterType(enable, 'boolean');
if (isTextEnabled() !== enable) {
Expand Down Expand Up @@ -352,7 +335,6 @@ function TextController(config) {

function reset() {
resetInitialSettings();
eventBus.off(Events.CURRENT_TRACK_CHANGED, _onCurrentTrackChanged, instance);
eventBus.off(Events.TEXT_TRACKS_QUEUE_INITIALIZED, _onTextTracksAdded, instance);

Object.keys(textSourceBuffers).forEach((key) => {
Expand All @@ -369,7 +351,6 @@ function TextController(config) {
getTextSourceBuffer,
getAllTracksAreDisabled,
addEmbeddedTrack,
setInitialSettings,
enableText,
isTextEnabled,
setTextTrack,
Expand Down

0 comments on commit 9d65cb5

Please sign in to comment.