1
0
mirror of https://github.com/videojs/video.js.git synced 2024-12-25 02:42:10 +02:00

@gkatsev made the first emulated text track enabled by default. closes #3248

This commit is contained in:
Gary Katsevman 2016-04-19 15:18:21 -04:00
parent 6b5040c04c
commit ff83aa6573
4 changed files with 91 additions and 0 deletions

View File

@ -4,6 +4,7 @@ CHANGELOG
## HEAD (Unreleased) ## HEAD (Unreleased)
* @benjipott updated IS_CHROME to not be true on MS Edge ([view](https://github.com/videojs/video.js/pull/3232)) * @benjipott updated IS_CHROME to not be true on MS Edge ([view](https://github.com/videojs/video.js/pull/3232))
* @mister-ben blacklisted Chrome for Android for playback rate support ([view](https://github.com/videojs/video.js/pull/3246)) * @mister-ben blacklisted Chrome for Android for playback rate support ([view](https://github.com/videojs/video.js/pull/3246))
* @gkatsev made the first emulated text track enabled by default ([view](https://github.com/videojs/video.js/pull/3248))
-------------------- --------------------

View File

@ -58,6 +58,34 @@ class TextTrackDisplay extends Component {
let track = tracks[i]; let track = tracks[i];
this.player_.addRemoteTextTrack(track); this.player_.addRemoteTextTrack(track);
} }
let modes = {'captions': 1, 'subtitles': 1};
let trackList = this.player_.textTracks();
let firstDesc;
let firstCaptions;
if (trackList) {
for (let i = 0; i < trackList.length; i++) {
let track = trackList[i];
if (track.default) {
if (track.kind === 'descriptions' && !firstDesc) {
firstDesc = track;
} else if (track.kind in modes && !firstCaptions) {
firstCaptions = track;
}
}
}
// We want to show the first default track but captions and subtitles
// take precedence over descriptions.
// So, display the first default captions or subtitles track
// and otherwise the first default descriptions track.
if (firstCaptions) {
firstCaptions.mode = 'showing';
} else if (firstDesc) {
firstDesc.mode = 'showing';
}
}
})); }));
} }

View File

@ -136,6 +136,7 @@ class TextTrack extends EventTarget {
let mode = TextTrackEnum.TextTrackMode[options.mode] || 'disabled'; let mode = TextTrackEnum.TextTrackMode[options.mode] || 'disabled';
let kind = TextTrackEnum.TextTrackKind[options.kind] || 'subtitles'; let kind = TextTrackEnum.TextTrackKind[options.kind] || 'subtitles';
let default_ = options.default;
let label = options.label || ''; let label = options.label || '';
let language = options.language || options.srclang || ''; let language = options.language || options.srclang || '';
let id = options.id || 'vjs_text_track_' + Guid.newGUID(); let id = options.id || 'vjs_text_track_' + Guid.newGUID();
@ -190,6 +191,13 @@ class TextTrack extends EventTarget {
set() {} set() {}
}); });
Object.defineProperty(tt, 'default', {
get() {
return default_;
},
set() {}
});
Object.defineProperty(tt, 'mode', { Object.defineProperty(tt, 'mode', {
get() { get() {
return mode; return mode;

View File

@ -475,3 +475,57 @@ test('should uniformly create html track element when adding text track', functi
player.dispose(); player.dispose();
}); });
test('default text tracks should show by default', function() {
let tag = TestHelpers.makeTag();
let capt = document.createElement('track');
capt.kind = 'captions';
capt.setAttribute('default', 'default');
tag.appendChild(capt);
let player = TestHelpers.makePlayer({
html5: {
nativeTextTracks: false
}
}, tag);
// native tracks are initialized after the player is ready
this.clock.tick(1);
let tracks = player.textTracks();
equal(tracks[0].kind, 'captions', 'the captions track is present');
equal(tracks[0].mode, 'showing', 'the captions track is showing');
});
test('default captions take precedence over default descriptions', function() {
let tag = TestHelpers.makeTag();
let desc = document.createElement('track');
let capt = document.createElement('track');
desc.kind = 'descriptions';
desc.setAttribute('default', 'default');
capt.kind = 'captions';
capt.setAttribute('default', 'default');
tag.appendChild(desc);
tag.appendChild(capt);
let player = TestHelpers.makePlayer({
html5: {
nativeTextTracks: false
}
}, tag);
// native tracks are initialized after the player is ready
this.clock.tick(1);
let tracks = player.textTracks();
equal(tracks[0].kind, 'descriptions', 'the descriptions track is first');
equal(tracks[0].mode, 'disabled', 'the descriptions track is disabled');
equal(tracks[1].kind, 'captions', 'the captions track is second');
equal(tracks[1].mode, 'showing', 'the captions track is showing');
});