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

Support native captions in html5 tech. #1656

Closed
wants to merge 36 commits into from

Conversation

gkatsev
Copy link
Member

@gkatsev gkatsev commented Nov 11, 2014

Don't auto-add the textTrackDisplay component.
Add a 'featuresNativeTrack'. Currently hardcoded to false for everything
except the html5 tech.
Add textTracks and addTextTrack methods to html5 tech.
Proxy player level methods to tech if we're using native tracks.
Fix up track menu items to work with spec tracks or vjs tracks.

This is the beginning of step 1 for the revamp of text tracks.

  • Native tracks, if available
  • Re-use non-native otherwise
  • Chrome Support
  • Firefox support
  • iPad Support
  • Android support
    • Chrome for Android -- works like desktop chrome
    • Native Android Browser
  • IE Support
    • IE11
    • IE10
    • IE9
    • IE8
  • Tests

Don't auto-add the textTrackDisplay component.
Add a 'featuresNativeTrack'. Currently hardcoded to false for everything
except the html5 tech.
Add textTracks and addTextTrack methods to html5 tech.
Proxy player level methods to tech if we're using native tracks.
Fix up track menu items to work with spec tracks or vjs tracks.
@gkatsev gkatsev mentioned this pull request Nov 11, 2014
17 tasks
@gkatsev
Copy link
Member Author

gkatsev commented Nov 11, 2014

Looks like firefox doesn't like to show captions.

@heff
Copy link
Member

heff commented Nov 12, 2014

It doesn't show captions at all?

@@ -27,6 +27,8 @@ vjs.Html5 = vjs.MediaTechController.extend({
// HTML video supports progress events
this['featuresProgressEvents'] = true;

this['featuresNativeTracks'] = true;
Copy link
Member

Choose a reason for hiding this comment

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

we should probably use textTrack instead of just tracks here, because of videoTracks and audioTracks

@gkatsev
Copy link
Member Author

gkatsev commented Nov 12, 2014

Firefox seems to be complicated but you can force it to show captions natively.

@@ -98,6 +100,20 @@ vjs.Html5.prototype.createEl = function(){
// associate the player with the new tag
el['player'] = player;

if (player.options_.tracks) {
Copy link
Member

Choose a reason for hiding this comment

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

Right now the player strips and disables all the tracks from the video tag at init, and this this would add them back in. It might still be the right way to do since tracks could be overridden by other options, but any thoughts on that?

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've disabled the stripping of tracks. This is to re-add them because we re-create the element here on iOS devices or other devices that have the movingMediaElementInDOM flag.

@gkatsev
Copy link
Member Author

gkatsev commented Nov 12, 2014

Oh, I think firefox is being weird in a way related to iOS. Re-adding the track elements fixes the issues.

@gkatsev
Copy link
Member Author

gkatsev commented Nov 12, 2014

I think the issue is that we're moving the video element and its track elements before firefox has a change to deal with them and it never gets around to fetching the tracks again. I added a fix to kick firefox into gear to re-fetch the tracks but I did it too late in the process so textTracks still returns nothing until the tracks get loaded.

@gkatsev
Copy link
Member Author

gkatsev commented Nov 12, 2014

I'm leaning towards not supporting firefox natively just yet.

@gkatsev
Copy link
Member Author

gkatsev commented Nov 12, 2014

Looks like HTC's native android browsers don't support native text tracks.
Older samsung devices seem to support native text tracks but for some reason vjs's custom implementation is showing up on older versions of android.
It's possible we may want to just always have custom captions on android browsers if they are not Chrome.

@@ -227,6 +227,9 @@ vjs.Player.prototype.createEl = function(){
// Remove width/height attrs from tag so CSS can make it 100% width/height
tag.removeAttribute('width');
tag.removeAttribute('height');

/* Don't clear out tracks
Copy link
Member

Choose a reason for hiding this comment

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

These comments don't make for a very nice diff. :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Nope, I'll clear it out completely during cleanup.

@gkatsev
Copy link
Member Author

gkatsev commented Nov 13, 2014

Some native android browsers are old and use numerical mode values. Trying to mess with the value to switch tracks causes the track to be hidden and you cannot re-display it. Devices with numerical modes for text-tracks should be considered off the table for native text track capabilities.

Also, if text tracks are old and use numerical mode values, use custom
tracks.
If an html tech is using custom tracks, remove track elements so we
don't accidentally show both custom and native captions.
Clean up showTextTrack slightly.
@heff
Copy link
Member

heff commented Nov 13, 2014

Unfortunate but reasonable. Which android versions/browsers are we talking about?

@gkatsev
Copy link
Member Author

gkatsev commented Nov 14, 2014

GS4's Native Android Browser. It's running Android 4.2.2 and I think it's native browser may have been based on Chrome 18.

@gkatsev
Copy link
Member Author

gkatsev commented Nov 14, 2014

IE11 (and maybe 10) will not interpret a mimetype of application/octet-stream as text/vtt if the file is named something like foo.vtt.

@gkatsev
Copy link
Member Author

gkatsev commented Nov 14, 2014

Looks like IE10 also uses numeric modes and has the same issue as the older android devices that do the same. As soon as we try to change the mode, the captions disappear.

This brings me to the following though: if text tracks are supported but have weird issues like the mode, do we want, in those cases, let the browser do it's best to pick the right caption and hide our captions button, or just have a button that disabled captions? @heff @dmlap. Firefox and Chrome will choose the "best" option to display and the display it. Chrome gives the users a button to toggle those captions on or off while Firefox does not.

@gkatsev
Copy link
Member Author

gkatsev commented Nov 14, 2014

IE8 and IE9 don't support native captions, so, the custom implementation is being used.

@gkatsev
Copy link
Member Author

gkatsev commented Nov 14, 2014

I cannot figure out how to get captions working in Firefox... @RickEyre would you be able to provide some direction for that?

@gkatsev
Copy link
Member Author

gkatsev commented Nov 17, 2014

Decided to punt on Firefox for now.

@gkatsev gkatsev mentioned this pull request Nov 17, 2014
* Html5 tech overrides these.
*/
vjs.MediaTechController.prototype.textTracks = function() {
this.player_.textTracks_ = this.player_.textTracks_ || [];
Copy link
Member

Choose a reason for hiding this comment

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

Do we still need to store the tracks on the player or can we move them to tech.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.

Um... I was going to say that it was because I didn't want to lose the tracks if the tech switches. But the tracks are available in the player options anyway, so, may not be necessary. I'll take a look to see whether we need to keep it on the player now as well.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I was wondering about the tech switching case. Techs at least won't switch unless the source is changed, so the question is should tracks persist after a new source is set. I'm not sure how the video element handles that but I would be tempted to say that no matter what the video element does, if you set a new source you have to provide new tracks for the source at the same time. If tracks (including dynamically created ones) need to persist then that would create a much bigger headache for us as far as translating native tracks to non-native tracks in a tech switch.

@heff
Copy link
Member

heff commented Nov 19, 2014

Very nice work, man. Between the native support and what's in video.js today, I know this is a lot to wrap your head around. There's still some outstanding issues around fully shimming things, and it's not always clear whether some of that should be done now or after the vtt.js research.

return;
}

controlBar.getChild('subtitlesButton').update();
Copy link
Member

Choose a reason for hiding this comment

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

After you add the change/add/remove listeners to the buttons these shouldn't be needed anymore.

Copy link
Member Author

Choose a reason for hiding this comment

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

Does our custom textTracks fire those events?

Copy link
Member Author

Choose a reason for hiding this comment

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

Since this piece of code is strictly for the custom controls.

Copy link
Member

Choose a reason for hiding this comment

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

Not now but I think in the end result it should.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, it should. But that would come as part of the next steps.

Copy link
Member

Choose a reason for hiding this comment

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

i.e. I don't think you need to wait for the next steps to update how these buttons work. They should expect native tracks or some that looks exactly like 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.

showTextTrack has been updated to use the correct mode for native text tracks.
I'd prefer to update the buttons in another PR to not make this one any bigger.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, ok. So the goal for this PR is to get the native tracks API working, while maintaining the custom tracks support without getting deeper into shimming. And get this merged in before taking a second pass at shimming.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, exactly.

Copy link
Member

Choose a reason for hiding this comment

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

Which requires the getProp function in the transition, which if that's it I guess that's not terrible. I'm not totally sure if we should release this without the second piece. Technically it breaks the track object API when native is used, so half the time, at least until the second pass when we break it fully. Know any players that have a custom captions button?

@gkatsev
Copy link
Member Author

gkatsev commented Nov 19, 2014

@heff updated based on code review comments

MenuButton's new 'update' method conflicted with volumeMenuButton's
update method which was used to update volume levels.
@gkatsev gkatsev mentioned this pull request Nov 25, 2014
oldTextTracks = videojs.MediaTechController.prototype.textTracks;
videojs.MediaTechController.prototype.textTracks = function() {
return {
addEventListener: Function.prototype
Copy link
Member

Choose a reason for hiding this comment

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

Function.prototype is a cool trick but may not be super obvious for the next person who has to debug this.

vjs.Player.prototype.addTextTrack = function() {
add++;
};
vjs.Player.prototype.getChild = function(child) {
Copy link
Member

Choose a reason for hiding this comment

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

I think this deserves a comment to explain what's happening here.

@gkatsev
Copy link
Member Author

gkatsev commented Dec 3, 2014

This is good to go but we've decided to merge all caption stuff together. closing for now, especially since it now needs to be rebased against master.

@gkatsev gkatsev closed this Dec 3, 2014
@gkatsev gkatsev deleted the native-captions branch March 8, 2016 20:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants