javascript - 使用 video-js 设置链接以在不同时间播放视频

标签 javascript video video.js

我正在尝试设置侧边导航以在网页上的不同时间播放主要功能视频。

这是我不工作的代码,显然我使用的是 video.js 插件,它在没有这个侧边导航的情况下运行良好。

HTML

<video id="myVideo" class="video-js vjs-default-skin box" controls preload="none" width="720" height="540" poster="images/myPoster.jpg" data-setup="{}">
  <source src="myVideo.mp4" type='video/mp4'>
  <source src="myVideo.oggtheora.ogv" type='video/ogg'> 
</video>



<a onClick="introduction()">Introduction</a>
<a onClick="chapertOne()">Chapter One</a>

JS

<script type="text/javascript">
 var myPlayer = _V_("myVideo");
   function(introduction){
 // Do something when the event is fired
    myPlayer.currentTime(120); // 2 minutes into the video
    myPlayer.play();
};
</script>

 <script type="text/javascript">
 var myPlayer = _V_("myVideo");
   function(chapterOne){
 // Do something when the event is fired
    myPlayer.currentTime(440); // 4 minutes into the video
    myPlayer.play();
};
</script>
...

代码无效。当我按下链接时没有任何反应。你认为这是因为它是一部长电影(大约10m)。我也在考虑将电影分成几章,然后在每个链接上加载一章。您认为正确的方法是什么?

最佳答案

function(chapterOne){ ... } 此代码创建未分配给任何变量的匿名函数。所以也许你应该试试这个:

<script type="text/javascript">
    var myPlayer = _V_("myVideo");

    function introduction() {
        // Do something when the event is fired
        myPlayer.currentTime(120); // 2 minutes into the video
        myPlayer.play();
    };

    function chapterOne() {
        // Do something when the event is fired
        myPlayer.currentTime(440); // 4 minutes into the video
        myPlayer.play();
    };
</script>

同时将 onClick 属性更改为 onclick

关于javascript - 使用 video-js 设置链接以在不同时间播放视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15811470/

相关文章:

javascript - 在 Vuejs 组件中使用 videojs-vr

javascript - 将 video.js 库与 Webpack 的 ProvidePlugin 结合使用

javascript - 为段落动态分配类

javascript - 复制按钮功能

android - 是否可以在没有音频源的情况下使用 CamcorderProfile?

闪光灯:提高相机的数据速率/质量

javascript - 在 Javascript 中制作函数式 OO 函数

javascript - Angular Elements Web 组件中的 NgFor 使用 JSON 文件 : How to get the values

iphone - 在 Linux 网络服务器上重新编码 iPhone/iPad Quicktime mov 文件以旋转视频