-
Notifications
You must be signed in to change notification settings - Fork 7.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Always emulated text track list #2391
Changes from all commits
0268fc6
f198faa
b0cb56e
549354c
6d75a25
486dc45
8327051
83f3cb7
314105b
228d79c
28e1844
e54c5cd
c76b3c9
b6de86d
0f64925
ca4743c
79b1b19
6ca59a3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -238,6 +238,14 @@ class Tech extends Component { | |
* @method dispose | ||
*/ | ||
dispose() { | ||
// clear out text tracks because we can't reuse them between techs | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this mean we're not maintaining tracks between tech/source changes? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, we cannot maintain them. If we're switching from Html to Flash, we're moving from track elements to emulated text tracks. And then if if we're going from Flash back to Html, we would want to clear out our emulated text tracks and use the native track elements. If you're just switching sources but staying in the same tech, you should keep the tracks. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok so help me understand what this means for users. What are caveats of using text tracks that we need to tell them? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would mean that users would need to re-add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So the text track list (player.textTracks) will survive. We'll remove the old text tracks (which will trigger change events) and add new text tracks (which will also trigger change events). Users should listen for those events to handle re-adding listeners to the new tracks. Is that right? That doesn't sound too bad. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, sounds right. |
||
let tt = this.textTracks(); | ||
let i = tt.length; | ||
while(i--) { | ||
this.removeRemoteTextTrack(tt[i]); | ||
} | ||
|
||
|
||
// Turn off any manual progress or timeupdate tracking | ||
if (this.manualProgress) { this.manualProgressOff(); } | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
let trackToJson = function(track) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function and file could use an explanatory comment. |
||
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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The naming of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. Also, writing tests for this. |
||
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 = trackToJson(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(trackToJson)); | ||
}; | ||
|
||
let jsonToTextTracks = function(json, tech) { | ||
json.forEach(function(track) { | ||
let addedTrack = tech.addRemoteTextTrack(track).track; | ||
if (!track.src && track.cues) { | ||
track.cues.forEach((cue) => addedTrack.addCue(cue)); | ||
} | ||
}); | ||
|
||
return tech.textTracks(); | ||
}; | ||
|
||
export default {textTracksToJson, jsonToTextTracks, trackToJson}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,6 +70,7 @@ test('dispose removes the object element even before ready fires', function() { | |
mockFlash.off = noop; | ||
mockFlash.trigger = noop; | ||
mockFlash.el_ = {}; | ||
mockFlash.textTracks = () => ([]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is what was causing the issues in safari that we're seeing in master and elsewhere. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please can we fix this? How do we fix this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, you did. Sweet. :) |
||
|
||
dispose.call(mockFlash); | ||
strictEqual(mockFlash.el_, null, 'swf el is nulled'); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -178,3 +178,48 @@ test('native source handler canHandleSource', function(){ | |
// Reset test video canPlayType | ||
Html5.TEST_VID.canPlayType = origCPT; | ||
}); | ||
|
||
if (Html5.supportsNativeTextTracks()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these only run if we are using and support native text tracks, so, I'm only running the tests in those browsers as well because it'll fail otherwise. |
||
test('add native textTrack listeners on startup', function() { | ||
let adds = []; | ||
let rems = []; | ||
let tt = { | ||
length: 0, | ||
addEventListener: (type, fn) => adds.push([type, fn]), | ||
removeEventListener: (type, fn) => rems.push([type, fn]), | ||
}; | ||
let el = document.createElement('div'); | ||
el.textTracks = tt; | ||
|
||
let htmlTech = new Html5({el}); | ||
|
||
equal(adds[0][0], 'change', 'change event handler added'); | ||
equal(adds[1][0], 'addtrack', 'addtrack event handler added'); | ||
equal(adds[2][0], 'removetrack', 'removetrack event handler added'); | ||
}); | ||
|
||
test('remove all tracks from emulated list on dispose', function() { | ||
let adds = []; | ||
let rems = []; | ||
let tt = { | ||
length: 0, | ||
addEventListener: (type, fn) => adds.push([type, fn]), | ||
removeEventListener: (type, fn) => rems.push([type, fn]), | ||
}; | ||
let el = document.createElement('div'); | ||
el.textTracks = tt; | ||
|
||
let htmlTech = new Html5({el}); | ||
htmlTech.dispose(); | ||
|
||
equal(adds[0][0], 'change', 'change event handler added'); | ||
equal(adds[1][0], 'addtrack', 'addtrack event handler added'); | ||
equal(adds[2][0], 'removetrack', 'removetrack event handler added'); | ||
equal(rems[0][0], 'change', 'change event handler removed'); | ||
equal(rems[1][0], 'addtrack', 'addtrack event handler removed'); | ||
equal(rems[2][0], 'removetrack', 'removetrack event handler removed'); | ||
equal(adds[0][0], rems[0][0], 'change event handler removed'); | ||
equal(adds[1][0], rems[1][0], 'addtrack event handler removed'); | ||
equal(adds[2][0], rems[2][0], 'removetrack event handler removed'); | ||
}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I decided to not do any async shenanigans. Even though, those async shenanigans might be more technically correct, this one is good enough and much simpler.