-
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
Support native captions in html5 tech. #1656
Conversation
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.
Looks like firefox doesn't like to show captions. |
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; |
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.
we should probably use textTrack instead of just tracks here, because of videoTracks and audioTracks
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) { |
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.
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?
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'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.
Oh, I think firefox is being weird in a way related to iOS. Re-adding the track elements fixes the issues. |
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. |
I'm leaning towards not supporting firefox natively just yet. |
Looks like HTC's native android browsers don't support native text tracks. |
@@ -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 |
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.
These comments don't make for a very nice diff. :)
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.
Nope, I'll clear it out completely during cleanup.
Some native android browsers are old and use numerical |
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.
Unfortunate but reasonable. Which android versions/browsers are we talking about? |
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. |
IE11 (and maybe 10) will not interpret a mimetype of |
Looks like IE10 also uses numeric This brings me to the following though: if text tracks are supported but have weird issues like the |
IE8 and IE9 don't support native captions, so, the custom implementation is being used. |
I cannot figure out how to get captions working in Firefox... @RickEyre would you be able to provide some direction for that? |
Decided to punt on Firefox for now. |
* Html5 tech overrides these. | ||
*/ | ||
vjs.MediaTechController.prototype.textTracks = function() { | ||
this.player_.textTracks_ = this.player_.textTracks_ || []; |
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.
Do we still need to store the tracks on the player or can we move them to tech.textTracks_?
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.
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.
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.
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.
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(); |
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.
After you add the change/add/remove listeners to the buttons these shouldn't be needed anymore.
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.
Does our custom textTracks fire those events?
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.
Since this piece of code is strictly for the custom controls.
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.
Not now but I think in the end result it should.
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.
Yes, it should. But that would come as part of the next steps.
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.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.
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.
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.
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.
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.
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.
Yes, exactly.
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.
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?
@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.
oldTextTracks = videojs.MediaTechController.prototype.textTracks; | ||
videojs.MediaTechController.prototype.textTracks = function() { | ||
return { | ||
addEventListener: Function.prototype |
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.
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) { |
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 think this deserves a comment to explain what's happening here.
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. |
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.