admin管理员组文章数量:1431927
I need to be able to get the Cues array from TextTracks object in VideoJs.
I have the following code:
videojs("example_video_1", {}, function(){
// Player (this) is initialized and ready.
var aTextTrack = this.textTracks()[0];
aTextTrack.show();
var theArray = this.textTracks()[0]['$'];
console.log(theArray);
console.dir(this.textTracks()[0]['$']);
// EXAMPLE: Start playing the video.
this.play();
});
The var theArray prints as empty but console.dir prints the contents of the Array. How can I get these values? I know its related with javascript asyc variables.
Cheers
I need to be able to get the Cues array from TextTracks object in VideoJs.
I have the following code:
videojs("example_video_1", {}, function(){
// Player (this) is initialized and ready.
var aTextTrack = this.textTracks()[0];
aTextTrack.show();
var theArray = this.textTracks()[0]['$'];
console.log(theArray);
console.dir(this.textTracks()[0]['$']);
// EXAMPLE: Start playing the video.
this.play();
});
The var theArray prints as empty but console.dir prints the contents of the Array. How can I get these values? I know its related with javascript asyc variables.
Cheers
Share Improve this question edited Apr 15, 2014 at 16:43 Adrian Avendano asked Apr 14, 2014 at 18:18 Adrian AvendanoAdrian Avendano 1,1011 gold badge10 silver badges13 bronze badges3 Answers
Reset to default 4This is the right answer. It took me a while to hack it as there is not much documentation on videoJS
videojs("example_video_1", {}, function(){
// Player (this) is initialized and ready.
var aTextTrack = this.textTracks()[0];
aTextTrack.on('loaded', function() {
console.log('here it is');
cues = aTextTrack.cues();
console.log('Ready State', aTextTrack.readyState())
console.log('Cues', cues);
});
aTextTrack.show();//this method call triggers the subtitles to be loaded and loaded trigger
this.play();
});
@Adrian; these are the minified internal objects of VideoJS and if you use them for your code it would render work obsolete with the next version of VideoJS.
It would be better to tap into the API for VideoJS if possible. In this case they don't have an API to read out the subtitles so you have a few options:
Use CSS to restyle the subtitle-display object where you want it.
Use JS to scan the subtitle-display HTML and fire an even when the text changes. Then you could capture the text and use it in your JS application how you'd like.
Scanning a div will be intensive on the browser so I'd remend #1 if possible.
As of 2015 you can listen for the loadeddata
event on the text track (videojs PR), although it's not very clearly documented
// add a text track
player.one('loadedmetadata', () => {
player.addRemoteTextTrack({
kind: 'captions',
language: 'en',
label: 'English',
src: '/path/to/subtitles',
}, true)
})
// listen for text tracks being added
player.textTracks().addEventListener('addtrack', (event) => {
// listen for the track's cues to finish loading
event.track.on('loadeddata', () => {
doSomethingWithCues()
})
})
本文标签: javascriptVideoJs TextTracks Cues emptyStack Overflow
版权声明:本文标题:javascript - VideoJs TextTracks Cues empty - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745588427a2665051.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论