Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a bug that lead to wrong selection of initial WebVTT track #4086

Merged
merged 1 commit into from
Nov 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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