forked from video-dev/hls.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request video-dev#1527 from SVT/hidden-subtitles
Properly handle hidden subtitles, and use the disabled property where approrpriate
- Loading branch information
Showing
5 changed files
with
141 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
const assert = require('assert'); | ||
|
||
import SubtitleTrackController from '../../../src/controller/subtitle-track-controller'; | ||
import Hls from '../../../src/hls'; | ||
|
||
describe('SubtitleTrackController', () => { | ||
|
||
let subtitleTrackController; | ||
let videoElement; | ||
|
||
beforeEach(() => { | ||
const hls = new Hls(); | ||
|
||
videoElement = document.createElement('video'); | ||
subtitleTrackController = new SubtitleTrackController(hls); | ||
|
||
subtitleTrackController.media = videoElement; | ||
subtitleTrackController.tracks = [{ id: 0 }, { id: 1 }]; | ||
|
||
const textTrack1 = videoElement.addTextTrack('subtitles', 'English', 'en'); | ||
const textTrack2 = videoElement.addTextTrack('subtitles', 'Swedish', 'se'); | ||
|
||
textTrack1.mode = 'disabled'; | ||
textTrack2.mode = 'disabled'; | ||
}); | ||
|
||
describe('onTextTrackChanged', () => { | ||
it('should set subtitleTrack to -1 if disabled', () => { | ||
assert.strictEqual(subtitleTrackController.subtitleTrack, -1); | ||
|
||
videoElement.textTracks[0].mode = 'disabled'; | ||
subtitleTrackController._onTextTracksChanged(); | ||
|
||
assert.strictEqual(subtitleTrackController.subtitleTrack, -1); | ||
}); | ||
|
||
it('should set subtitleTrack to 0 if hidden', () => { | ||
assert.strictEqual(subtitleTrackController.subtitleTrack, -1); | ||
|
||
videoElement.textTracks[0].mode = 'hidden'; | ||
subtitleTrackController._onTextTracksChanged(); | ||
|
||
assert.strictEqual(subtitleTrackController.subtitleTrack, 0); | ||
}); | ||
|
||
it('should set subtitleTrack to 0 if showing', () => { | ||
assert.strictEqual(subtitleTrackController.subtitleTrack, -1); | ||
|
||
videoElement.textTracks[0].mode = 'showing'; | ||
subtitleTrackController._onTextTracksChanged(); | ||
|
||
assert.strictEqual(subtitleTrackController.subtitleTrack, 0); | ||
}); | ||
}); | ||
|
||
describe('setSubtitleTrackInternal', () => { | ||
it('should set active text track mode to showing', () => { | ||
videoElement.textTracks[0].mode = 'disabled'; | ||
|
||
subtitleTrackController.subtitleDisplay = true; | ||
subtitleTrackController.subtitleTrack = 0; | ||
|
||
assert.strictEqual(videoElement.textTracks[0].mode, 'showing'); | ||
}); | ||
|
||
it('should set active text track mode to hidden', () => { | ||
videoElement.textTracks[0].mode = 'disabled'; | ||
|
||
subtitleTrackController.subtitleDisplay = false; | ||
subtitleTrackController.subtitleTrack = 0; | ||
|
||
assert.strictEqual(videoElement.textTracks[0].mode, 'hidden'); | ||
}); | ||
|
||
it('should disable previous track', () => { | ||
// Change active track without triggering setSubtitleTrackInternal | ||
subtitleTrackController.trackId = 0; | ||
|
||
// Change active track and trigger setSubtitleTrackInternal | ||
subtitleTrackController.subtitleTrack = 1; | ||
|
||
assert.strictEqual(videoElement.textTracks[0].mode, 'disabled'); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
const assert = require('assert'); | ||
|
||
import TimelineController from '../../../src/controller/timeline-controller'; | ||
import Hls from '../../../src/hls'; | ||
|
||
describe('TimelineController', () => { | ||
|
||
let timelineController; | ||
let hls; | ||
|
||
beforeEach(() => { | ||
hls = new Hls(); | ||
hls.config.enableWebVTT = true; | ||
timelineController = new TimelineController(hls); | ||
timelineController.media = document.createElement('video'); | ||
|
||
}); | ||
|
||
it('should set default track to showing when displaySubtitles is true', () => { | ||
hls.subtitleTrackController = { subtitleDisplay: true }; | ||
|
||
timelineController.onManifestLoaded({ | ||
subtitles: [{ id: 0 }, { id: 1, default: true }] | ||
}); | ||
|
||
assert.strictEqual(timelineController.textTracks[0].mode, 'disabled'); | ||
assert.strictEqual(timelineController.textTracks[1].mode, 'showing'); | ||
}); | ||
|
||
it('should set default track to hidden when displaySubtitles is false', () => { | ||
hls.subtitleTrackController = { subtitleDisplay: false }; | ||
|
||
timelineController.onManifestLoaded({ | ||
subtitles: [{ id: 0 }, { id: 1, default: true }] | ||
}); | ||
|
||
assert.strictEqual(timelineController.textTracks[0].mode, 'disabled'); | ||
assert.strictEqual(timelineController.textTracks[1].mode, 'hidden'); | ||
}); | ||
}); |