Skip to content

Commit

Permalink
bugfix: DEFAULT=YES on caption tracks was not being respected.
Browse files Browse the repository at this point in the history
Reason for this was because the subtitle grouping wasn't populating the
tracks before the findTrackId function was called. So, it was looking
over an empty array on the first invocation of the function.

By moving it, it now has the correct behaviour and the default track is
selected.

Closes #3780.
  • Loading branch information
itsjamie committed Apr 15, 2021
1 parent ce0cba1 commit 3cc1555
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/controller/subtitle-track-controller.ts
Expand Up @@ -191,13 +191,15 @@ class SubtitleTrackController extends BasePlaylistController {
const lastTrack = this.tracksInGroup
? this.tracksInGroup[this.trackId]
: undefined;
const initialTrackId =
this.findTrackId(lastTrack?.name) || this.findTrackId();

const subtitleTracks = this.tracks.filter(
(track): boolean => !textGroupId || track.groupId === textGroupId
);
this.groupId = textGroupId;
this.tracksInGroup = subtitleTracks;
const initialTrackId =
this.findTrackId(lastTrack?.name) || this.findTrackId();
this.groupId = textGroupId;

const subtitleTracksUpdated: SubtitleTracksUpdatedData = {
subtitleTracks,
};
Expand All @@ -213,9 +215,9 @@ class SubtitleTrackController extends BasePlaylistController {
}

private findTrackId(name?: string): number {
const audioTracks = this.tracksInGroup;
for (let i = 0; i < audioTracks.length; i++) {
const track = audioTracks[i];
const textTracks = this.tracksInGroup;
for (let i = 0; i < textTracks.length; i++) {
const track = textTracks[i];
if (!this.selectDefaultTrack || track.default) {
if (!name || name === track.name) {
return track.id;
Expand Down

0 comments on commit 3cc1555

Please sign in to comment.