-
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
Emulate HTMLTrackElement to enable load event. #2804
Changes from 17 commits
448d2ff
3123de0
86b97cf
6986f4a
660ea2a
4728389
9fe17ac
ceaf4af
452554f
47e6bab
5e5fe16
1c90f74
c7a0033
71828a7
756af99
4ad1d2f
eec4a2c
f054347
4af827d
077a4c3
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 |
---|---|---|
|
@@ -77,21 +77,13 @@ class ChaptersButton extends TextTrackButton { | |
let chaptersTrack; | ||
let items = this.items = []; | ||
|
||
for (let i = 0, l = tracks.length; i < l; i++) { | ||
for (let i = 0, length = tracks.length; i < length; i++) { | ||
let track = tracks[i]; | ||
|
||
if (track['kind'] === this.kind_) { | ||
if (!track.cues) { | ||
track['mode'] = 'hidden'; | ||
/* jshint loopfunc:true */ | ||
// TODO see if we can figure out a better way of doing this https://github.com/videojs/video.js/issues/1864 | ||
window.setTimeout(Fn.bind(this, function() { | ||
this.createMenu(); | ||
}), 100); | ||
/* jshint loopfunc:false */ | ||
} else { | ||
chaptersTrack = track; | ||
break; | ||
} | ||
chaptersTrack = track; | ||
|
||
break; | ||
} | ||
} | ||
|
||
|
@@ -105,7 +97,17 @@ class ChaptersButton extends TextTrackButton { | |
})); | ||
} | ||
|
||
if (chaptersTrack) { | ||
if (chaptersTrack && chaptersTrack.cues == null) { | ||
chaptersTrack['mode'] = 'hidden'; | ||
|
||
let remoteTextTrackEl = this.player_.remoteTextTrackEls().getTrackElementByTrack_(chaptersTrack); | ||
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. looks like there an issue here tracks that were added in the html: <video id="vid1" class="video-js vjs-default-skin" controls preload="auto" width="640" height="264"
poster="http://video-js.zencoder.com/oceans-clip.png">
<source src="oceans-clip.mp4" type='video/mp4'>
<source src="http://video-js.zencoder.com/oceans-clip.mp4?fo23" type='video/mp4'>
<track kind="chapters" src="../docs/examples/shared/example-captions.vtt" srclang="en" label="Subs"></track>
</video> What happens here is that we get the chapters track but when we try to retrieve its associated track el, we get undefined so the chapters button never loads. |
||
|
||
if (remoteTextTrackEl) { | ||
remoteTextTrackEl.addEventListener('load', (event) => this.update()); | ||
} | ||
} | ||
|
||
if (chaptersTrack && chaptersTrack.cues && chaptersTrack.cues.length > 0) { | ||
let cues = chaptersTrack['cues'], cue; | ||
|
||
for (let i = 0, l = cues.length; i < l; i++) { | ||
|
@@ -120,6 +122,7 @@ class ChaptersButton extends TextTrackButton { | |
|
||
menu.addChild(mi); | ||
} | ||
|
||
this.addChild(menu); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,9 @@ | |
*/ | ||
|
||
import Component from '../component'; | ||
import HTMLTrackElement from '../tracks/html-track-element'; | ||
import HTMLTrackElementList from '../tracks/html-track-element-list'; | ||
import mergeOptions from '../utils/merge-options.js'; | ||
import TextTrack from '../tracks/text-track'; | ||
import TextTrackList from '../tracks/text-track-list'; | ||
import * as Fn from '../utils/fn.js'; | ||
|
@@ -377,6 +380,17 @@ class Tech extends Component { | |
return this.remoteTextTracks_; | ||
} | ||
|
||
/** | ||
* Get remote htmltrackelements | ||
* | ||
* @returns {HTMLTrackElementList} | ||
* @method remoteTextTrackEls | ||
*/ | ||
remoteTextTrackEls() { | ||
this.remoteTextTrackEls_ = this.remoteTextTrackEls_ || new HTMLTrackElementList(); | ||
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. We'll also probably want to go through the same shenanigans we've gone through with the text track list to have it work across tech changes. See #2391 |
||
return this.remoteTextTrackEls_; | ||
} | ||
|
||
/** | ||
* Creates and returns a remote text track object | ||
* | ||
|
@@ -396,19 +410,28 @@ class Tech extends Component { | |
} | ||
|
||
/** | ||
* Creates and returns a remote text track object | ||
* Creates a remote text track object and returns a emulated html track element | ||
* | ||
* @param {Object} options The object should contain values for | ||
* kind, language, label and src (location of the WebVTT file) | ||
* @return {TextTrackObject} | ||
* @return {HTMLTrackElement} | ||
* @method addRemoteTextTrack | ||
*/ | ||
addRemoteTextTrack(options) { | ||
let track = createTrackHelper(this, options.kind, options.label, options.language, options); | ||
this.remoteTextTracks().addTrack_(track); | ||
return { | ||
track: track | ||
}; | ||
let track = mergeOptions(options, { | ||
tech: this | ||
}); | ||
|
||
let htmlTrackElement = new HTMLTrackElement(track); | ||
|
||
// store HTMLTrackElement and TextTrack to remote list | ||
this.remoteTextTrackEls().addTrackElement_(htmlTrackElement); | ||
this.remoteTextTracks().addTrack_(htmlTrackElement.track); | ||
|
||
// must come after remoteTextTracks() | ||
this.textTracks().addTrack_(htmlTrackElement.track); | ||
|
||
return htmlTrackElement; | ||
} | ||
|
||
/** | ||
|
@@ -419,6 +442,11 @@ class Tech extends Component { | |
*/ | ||
removeRemoteTextTrack(track) { | ||
this.textTracks().removeTrack_(track); | ||
|
||
let trackElement = this.remoteTextTrackEls().getTrackElementByTrack_(track); | ||
|
||
// remove HTMLTrackElement and TextTrack from remote list | ||
this.remoteTextTrackEls().removeTrackElement_(trackElement); | ||
this.remoteTextTracks().removeTrack_(track); | ||
} | ||
|
||
|
@@ -447,7 +475,7 @@ class Tech extends Component { | |
/* | ||
* Return whether the argument is a Tech or not. | ||
* Can be passed either a Class like `Html5` or a instance like `player.tech_` | ||
* | ||
* | ||
* @param {Object} component An item to check | ||
* @return {Boolean} Whether it is a tech or not | ||
*/ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/** | ||
* @file html-track-element.js | ||
*/ | ||
|
||
import * as browser from '../utils/browser.js'; | ||
import document from 'global/document'; | ||
|
||
class HtmlTrackElementList { | ||
constructor(trackElements = []) { | ||
let list = this; | ||
|
||
if (browser.IS_IE8) { | ||
list = document.createElement('custom'); | ||
|
||
for (let prop in HtmlTrackElementList.prototype) { | ||
if (prop !== 'constructor') { | ||
list[prop] = HtmlTrackElementList.prototype[prop]; | ||
} | ||
} | ||
} | ||
|
||
list.trackElements_ = []; | ||
|
||
Object.defineProperty(list, 'length', { | ||
get() { | ||
return this.trackElements_.length; | ||
} | ||
}); | ||
|
||
for (let i = 0, length = trackElements.length; i < length; i++) { | ||
list.addTrackElement_(trackElements[i]); | ||
} | ||
|
||
if (browser.IS_IE8) { | ||
return list; | ||
} | ||
} | ||
|
||
addTrackElement_(trackElement) { | ||
this.trackElements_.push(trackElement); | ||
} | ||
|
||
getTrackElementByTrack_(track) { | ||
let trackElement_; | ||
|
||
for (let i = 0, length = this.trackElements_.length; i < length; i++) { | ||
if (track === this.trackElements_[i].track) { | ||
trackElement_ = this.trackElements_[i]; | ||
|
||
break; | ||
} | ||
} | ||
|
||
return trackElement_; | ||
} | ||
|
||
removeTrackElement_(trackElement) { | ||
for (let i = 0, length = this.trackElements_.length; i < length; i++) { | ||
if (trackElement === this.trackElements_[i]) { | ||
this.trackElements_.splice(i, 1); | ||
|
||
break; | ||
} | ||
} | ||
} | ||
} | ||
|
||
export default HtmlTrackElementList; |
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.
Followed #1949