From 3cc1555d7c14e8f23ee21a3bac3ae5435da5a7e3 Mon Sep 17 00:00:00 2001 From: Jamie Stackhouse Date: Thu, 15 Apr 2021 12:36:22 -0300 Subject: [PATCH] bugfix: DEFAULT=YES on caption tracks was not being respected. 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. --- src/controller/subtitle-track-controller.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/controller/subtitle-track-controller.ts b/src/controller/subtitle-track-controller.ts index 473f2520c06..e27786bed15 100644 --- a/src/controller/subtitle-track-controller.ts +++ b/src/controller/subtitle-track-controller.ts @@ -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, }; @@ -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;