-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
7 args TextTrackCue constructor #643
Conversation
I'm sorry, but the Toshiba dTV is not up to spec. If you can detect and fix it with a polyfill, that would be an acceptable solution. But we won't put platform-specific hacks into the main codebase for a user agent that doesn't follow specs. Try checking |
Do you have any recommendation how to polyfill this? As TextTrackCue exist on window object but requires arguments just like these: |
In an earlier draft of the spec, TextTrackCue was all there was. IE11 and Edge only have this 3-argument TextTrackCue. Later, VTTCue was introduced as a concrete implementation, at which point TextTrackCue became an abstract interface. Therefore you will not find a TextTrackCue constructor in the specs now. I recommend you detect the 7-argument TextTrackCue and implement a standard VTTCue constructor instead. Here's the spec: https://w3c.github.io/webvtt/#the-vttcue-interface Your implementation of VTTCue can then reorder the arguments and call your 7-arg TextTrackCue. It may not be obvious, but you can return an object from a constructor in JavaScript. For example: function FakeArray() {
return new Array();
}
var x = new FakeArray();
console.log('x is Array?', x instanceof Array); |
|
*/ | ||
shaka.polyfill.VTTCue.from7ArgsTextTrackCue_ = function(startTime, endTime, | ||
text) { | ||
return new window['TextTrackCue'](text, startTime, endTime, '', '', '', 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.
I assume you're quoting the access here to avoid the compiler complaining about the "wrong" arguments/types. Please add a comment to that effect.
|
||
/** | ||
* Draft spec TextTrackCue with 7 constructor arguments. | ||
* See {@link https://goo.gl/CSPvbz Using the TextTrack API} and examples. |
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.
This link doesn't specify the 7 arguments or their meaning. It gives an example with 4 arguments, and the examples have the text in argument 4, not argument 1 as you have below.
I tracked down the history as best I could.
Here we had the first appearance of TextTrackCue in draft 20110113 (no constructor).
In draft 20120329, we had the first constructor on TextTrackCue (6 arguments, not 7).
In draft 20121025, the constructor was changed to 3 arguments (as implemented by IE11 and Edge today).
In draft 20121217, we have the final appearance of a TextTrackCue constructor. After this, it became abstract.
Are you sure it's 7 on Toshiba and not 6?
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.
righ I used wrong link in the comment, this one is the one with 7 args http://www.w3schools.com/TAGs/av_met_addtexttrack.asp just like on Toshiba
@jozefchutka, let's not give up just yet. You've done all the rest of the work, so I think we can find another way to do the detection. Here are a couple more options:
|
what would you say if I try catch constructing TextTrackCue with 3 and 7 args as a part of polyfill? |
I would prefer detecting either TextTrackCue.length or navigator.userAgent. Catching exceptions can be expensive, so that should never be part of a success path. If we are parsing a VTT file with thousands of cues, running a loop over each cue in which we catch an exception and try again with different args would really hurt performance. |
Surely I do not want exceptions during real playback, but only during initial polyfill install phase. Once correct construction is detected, the polyfill would reference the right one. |
Okay, sounds good. One caught exception at install time is no big deal. |
hi Joey, |
} | ||
|
||
if (!window.TextTrackCue) { | ||
shaka.log.info('VTTCue not available.'); |
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.
This shouldn't happen, since all the browsers we support have either VTTCue or TextTrackCue. So we probably don't need a no-op polyfill for this case.
But if this were to happen, we would throw at new VTTCue in TextEngine, so this message should at least be upgraded to shaka.log.error.
return; | ||
} | ||
|
||
var constructorLength = window.TextTrackCue.length; |
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.
You can drop window here now that TextTrackCue is sure to exist.
I just had a couple small comments on the code. I'll wait for those revisions, and for you to test on the Toshiba. It looks really good, and it looks like it cleans things up for non-Toshiba platforms as well. Thanks for contributing! |
@joeyparrish this is confirmed working on Toshiba, ready to merge from my side |
Great, I'll test it on the build bot and on all the browsers in our test lab. |
Testing in progress... |
Failure:
|
There are some tests that modify |
I have verified that these substitutions in
I'll make these changes and manually merge. Thanks! |
Merged as ca299b2. |
This adds a VTTCue polyfill for IE/Edge (3-arg TextTrackCue) and Toshiba dTV (6-arg TextTrackCue). Closes #635
This adds a VTTCue polyfill for IE/Edge (3-arg TextTrackCue) and Toshiba dTV (6-arg TextTrackCue). Closes #635
Toshiba dTV seems to have a different set of constructor arguments for TextTrackCue, just like the ones used here
http://www.w3schools.com/TAGs/av_met_addtexttrack.asp . Not sure what are the extra arguments but empty strings and true did the job. This also solves #635