-
Notifications
You must be signed in to change notification settings - Fork 7.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Store and restore text tracks from JSON.
When switching techs, we want to clear out the old text tracks and then restore them using the currently appropriate tracks.
- Loading branch information
Showing
4 changed files
with
60 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
let ttToJson = function(track) { | ||
return { | ||
kind: track.kind, | ||
label: track.label, | ||
language: track.language, | ||
id: track.id, | ||
inBandMetadataTrackDispatchType: track.inBandMetadataTrackDispatchType, | ||
mode: track.mode, | ||
cues: track.cues && Array.prototype.map.call(track.cues, function(cue) { | ||
return { | ||
startTime: cue.startTime, | ||
endTime: cue.endTime, | ||
text: cue.text, | ||
id: cue.id | ||
}; | ||
}), | ||
src: track.src | ||
}; | ||
}; | ||
|
||
let textTracksToJson = function(tech) { | ||
let trackEls = tech.el().querySelectorAll('track'); | ||
|
||
let trackObjs = Array.prototype.map.call(trackEls, (t) => t.track); | ||
let tracks = Array.prototype.map.call(trackEls, function(trackEl) { | ||
let json = ttToJson(trackEl.track); | ||
json.src = trackEl.src; | ||
return json; | ||
}); | ||
|
||
return tracks.concat(Array.prototype.filter.call(tech.textTracks(), function(track) { | ||
return trackObjs.indexOf(track) === -1; | ||
}).map(ttToJson)); | ||
}; | ||
|
||
let jsonToTextTracks = function(json, tech) { | ||
json.forEach(function(track) { | ||
let addedTrack = tech.addRemoteTextTrack(track).track; | ||
if (!track.src) { | ||
track.cues.forEach((cue) => addedTrack.addCue(cue)); | ||
} | ||
}); | ||
|
||
return tech.textTracks(); | ||
}; | ||
|
||
export default {textTracksToJson, jsonToTextTracks}; |
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