Skip to content
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

Closed
wants to merge 18 commits into from

Conversation

gkatsev
Copy link
Member

@gkatsev gkatsev commented Jul 21, 2015

Fixes #2367

gkatsev added 2 commits July 21, 2015 15:59
TextTrackList has a couple of event listeners that users rely on. By
emulated the TextTrackList we can hopefully eliminate some of the
friction that can occur during tech changes around the text track event
handlers.
When switching techs, we want to clear out the old text tracks and then
restore them using the currently appropriate tracks.
@pam
Copy link

pam commented Jul 21, 2015

Tests failed. Automated cross-browser testing via Sauce Labs and Travis CI shows that the JavaScript changes in this pull request are: BUSTED

Commit: f198faa
Build details: https://travis-ci.org/pam/video.js/builds/72025560

(Please note that this is a fully automated comment.)

@gkatsev
Copy link
Member Author

gkatsev commented Jul 21, 2015

I'll tackle tests next but it's working for me when switching from html to flash and back.

@@ -86,6 +87,12 @@ class Html5 extends Tech {
* @method dispose
*/
dispose() {
let tt = this.el().textTracks;

tt.removeEventListener('change', Fn.bind(this, this.handleTextTrackChange));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If el().textTracks is a native list then I don't know if the Fn.bind is going to do what you want here. The remove-by-same-id only works with our internal event listeners. The native removeEventListener still looks for the same function.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, you're right. I keep getting more and more output when switching techs.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a fix for this locally but for some odd reason it only wants to work when I'm setting through the code for removing the old text tracks...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, the issue seems that if we remove the event listener in the same event tick as removing the track, we don't actually get the removetrack event. Looking at the spec, it seems like the removetrack events are queued to fire when tracks are removed, so, it makes sense for us to miss them.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the solution in this case really is a setTimeout around the removal of tracks. Either that or create a remove handler that gets added on addtrack and bound to a particular track which then gets removed when that particular track gets removed. But I think that solution might be too clever.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we queue our own removetrack event in that case? Seems like handling that asynchronously could get messy when switching to the new tech.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just realized we could probably just clean out our emulated text track list manually. However, if we remove the event listener asynchronously, it works fine too. Or, we can have the removetrack handler be smart and get added on addtrack and removed on removetrack if there are no longer any text tracks (which is what I tried to describe above).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea of something simple and less async, but whatever you think
works best.

Sent from mobile

@heff
Copy link
Member

heff commented Jul 21, 2015

One question around tech changes but other than that looks really good to me.

gkatsev added 3 commits July 27, 2015 12:01
Add event listeners in the constructor. Remove event listeners in
dispose.
'removetrack' listener needs to be removed asynchronously to make sure
that we get all the events that are to be triggered.
@gkatsev
Copy link
Member Author

gkatsev commented Jul 27, 2015

I updated things. I currently see a weird issue where when you switch back to the html5 tech, to get the non-current-locale text tracks to show, you need to select it twice. Not sure what is going on there.

@pam
Copy link

pam commented Jul 27, 2015

Tests failed. Automated cross-browser testing via Sauce Labs and Travis CI shows that the JavaScript changes in this pull request are: BUSTED

Commit: 6d75a25
Build details: https://travis-ci.org/pam/video.js/builds/72875915

(Please note that this is a fully automated comment.)

@gkatsev
Copy link
Member Author

gkatsev commented Jul 27, 2015

I decided to not try and do anything asynchronous and just clear out our emulated text track list manually in dispose since nothing should be coming along across the tech switch from html5->flash

@pam
Copy link

pam commented Jul 27, 2015

Tests failed. Automated cross-browser testing via Sauce Labs and Travis CI shows that the JavaScript changes in this pull request are: BUSTED

Commit: 486dc45
Build details: https://travis-ci.org/pam/video.js/builds/72882669

(Please note that this is a fully automated comment.)

@@ -178,3 +178,48 @@ test('native source handler canHandleSource', function(){
// Reset test video canPlayType
Html5.TEST_VID.canPlayType = origCPT;
});

if (Html5.supportsNativeTextTracks()) {
Copy link
Member Author

Choose a reason for hiding this comment

The 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.

@gkatsev
Copy link
Member Author

gkatsev commented Jul 27, 2015

I think I may have fixed the issue that text tracks have had with safari in this PR.

@@ -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 = () => ([]);
Copy link
Member Author

Choose a reason for hiding this comment

The 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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please can we fix this? How do we fix this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, you did. Sweet. :)

@gkatsev
Copy link
Member Author

gkatsev commented Jul 28, 2015

Actually, looks like selecting the captions twice is caused by what #2412 fixes.

@@ -0,0 +1,47 @@
let trackToJson = function(track) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function and file could use an explanatory comment.

@dmlap
Copy link
Member

dmlap commented Jul 30, 2015

Other than my documentation comment, LGTM

@heff
Copy link
Member

heff commented Jul 30, 2015

2nd dmlap. Lgtm!

@dmlap dmlap mentioned this pull request Aug 3, 2015
@dmlap
Copy link
Member

dmlap commented Aug 3, 2015

Superseded by #2425

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants