Skip to content

Commit

Permalink
Do not filter out TextTracks with kind of "captions" from API subtitl…
Browse files Browse the repository at this point in the history
…eTrack selection (#5297)

Fixes #5292

Commit:
4029b6d [4029b6d]
Parents: d097760
Author: @dstreet26
  • Loading branch information
dstreet26 authored and robwalch committed Mar 17, 2023
1 parent 747e15f commit 848c5cb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/controller/subtitle-track-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,10 @@ function filterSubtitleTracks(textTrackList: TextTrackList): TextTrack[] {
for (let i = 0; i < textTrackList.length; i++) {
const track = textTrackList[i];
// Edge adds a track without a label; we don't want to use it
if (track.kind === 'subtitles' && track.label) {
if (
(track.kind === 'subtitles' || track.kind === 'captions') &&
track.label
) {
tracks.push(textTrackList[i]);
}
}
Expand Down
18 changes: 18 additions & 0 deletions tests/unit/controller/subtitle-track-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,20 @@ describe('SubtitleTrackController', function () {

const textTrack1 = videoElement.addTextTrack('subtitles', 'English', 'en');
const textTrack2 = videoElement.addTextTrack('subtitles', 'Swedish', 'se');
const textTrack3 = videoElement.addTextTrack(
'captions',
'Untitled CC',
'en'
);

textTrack1.groupId = 'default-text-group';
textTrack2.groupId = 'default-text-group';
textTrack3.groupId = 'default-text-group';
subtitleTrackController.groupId = 'default-text-group';

textTrack1.mode = 'disabled';
textTrack2.mode = 'disabled';
textTrack3.mode = 'disabled';
sandbox = sinon.createSandbox();
});

Expand Down Expand Up @@ -89,6 +97,16 @@ describe('SubtitleTrackController', function () {

expect(subtitleTrackController.subtitleTrack).to.equal(0);
});

it('should set subtitleTrack id captions track is showing', function () {
expect(subtitleTrackController.subtitleTrack).to.equal(-1);

videoElement.textTracks[2].mode = 'showing';
subtitleTrackController.onTextTracksChanged();

expect(videoElement.textTracks[2].kind).to.equal('captions');
expect(subtitleTrackController.subtitleTrack).to.equal(2);
});
});

describe('set subtitleTrack', function () {
Expand Down

0 comments on commit 848c5cb

Please sign in to comment.