我需要能够从 VideoJs 中的 TextTracks 对象获取 Cues 数组。
我有以下代码:
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();
});
var theArray 打印为空,但 console.dir 打印数组的内容。我怎样才能得到这些值?我知道它与 javascript asyc 变量有关。
干杯
最佳答案
这是正确的答案。我花了一些时间来破解它,因为关于 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();
});
关于javascript - VideoJs TextTracks 提示为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23067294/