Skip to content

Commit

Permalink
Merge branch 'master' into japanese-korean-vtt-captions
Browse files Browse the repository at this point in the history
  • Loading branch information
mangui authored Nov 9, 2017
2 parents decd8f7 + a2d561e commit ebb2fcc
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ env:
- TRAVIS_MODE=funcTests UA=chrome OS="Windows 7"
- TRAVIS_MODE=funcTests UA=firefox OS="Windows 7"
# - TRAVIS_MODE=funcTests UA=MicrosoftEdge OS="Windows 10"
# - TRAVIS_MODE=funcTests UA="internet explorer" OS="Windows 8.1" UA_VERSION="11.0"
- TRAVIS_MODE=funcTests UA="internet explorer" OS="Windows 8.1" UA_VERSION="11.0"
- TRAVIS_MODE=funcTests UA="internet explorer" OS="Windows 10"
- TRAVIS_MODE=funcTests UA=chrome OS="OS X 10.11"
# - TRAVIS_MODE=funcTests UA=firefox OS="OS X 10.11"
Expand Down
17 changes: 14 additions & 3 deletions src/controller/subtitle-track-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ class SubtitleTrackController extends EventHandler {
return;
}

if (this.queuedDefaultTrack !== undefined) {
this.subtitleTrack = this.queuedDefaultTrack;
delete this.queuedDefaultTrack;
}

this.trackChangeListener = this._onTextTracksChanged.bind(this);

this.useTextTrackPolling = !(this.media.textTracks && 'onchange' in this.media.textTracks);
Expand Down Expand Up @@ -94,7 +99,6 @@ class SubtitleTrackController extends EventHandler {
// Fired whenever a new manifest is loaded.
onManifestLoaded(data) {
let tracks = data.subtitles || [];
let defaultFound = false;
this.tracks = tracks;
this.trackId = -1;
this.hls.trigger(Event.SUBTITLE_TRACKS_UPDATED, {subtitleTracks : tracks});
Expand All @@ -103,8 +107,15 @@ class SubtitleTrackController extends EventHandler {
// TODO: improve selection logic to handle forced, etc
tracks.forEach(track => {
if (track.default) {
this.subtitleTrack = track.id;
defaultFound = true;
// setting this.subtitleTrack will trigger internal logic
// if media has not been attached yet, it will fail
// we keep a reference to the default track id
// and we'll set subtitleTrack when onMediaAttached is triggered
if (this.media) {
this.subtitleTrack = track.id;
} else {
this.queuedDefaultTrack = track.id;
}
}
});
}
Expand Down
5 changes: 4 additions & 1 deletion src/utils/webvtt-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ const WebVTTParser = {
parse: function(vttByteArray, syncPTS, vttCCs, cc, callBack, errorCallBack) {
// Convert byteArray into string, replacing any somewhat exotic linefeeds with "\n", then split on that character.
let re = /\r\n|\n\r|\n|\r/g;
let vttLines = utf8ArrayToStr(new Uint8Array(vttByteArray)).trim().replace(re, '\n').split('\n');
// Uint8Array.prototype.reduce is not implemented in IE11
let vttLines = utf8ArrayToStr(Array.prototype.reduce
.call(new Uint8Array(vttByteArray), (raw, vttByte) => raw + String.fromCharCode(vttByte), ''))
.trim().replace(re, '\n').split('\n');

let cueTime = '00:00.000';
let mpegTs = 0;
Expand Down

0 comments on commit ebb2fcc

Please sign in to comment.