javascript - VideoJs TextTracks 提示为空

标签 javascript google-chrome video.js

我需要能够从 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();

}); 

enter image description here

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/

相关文章:

javascript - 在 Firebug/Chrome 中获取从一个断点到另一个断点的 Javascript 或 jQuery 堆栈跟踪?

video.js - 浏览器自动播放策略。 Netflix 中的自动播放是如何工作的?

jquery - 是否有可用于在我的网站中进行视频修剪/剪切的 flash/JavaScript 库?

css - 如何在不在视频上方创建相同大小的条的情况下将 video.js 控件放置在视频下方

javascript - Extjs 平均存储所有字段

javascript - 使用 Javascript Yammer API 访问外部网络数据

javascript - Chrome : navigator. mediaDevices.getUserMedia 不是函数

javascript - 我们如何使用 InternJS 对 Chrome 打包应用程序(例如 Chromebook 应用程序)执行自动化测试

Javascript:setTimeout 和引用中的函数

javascript - 此代码是否有可能丢失一些匹配项?