我正在尝试设置侧边导航以在网页上的不同时间播放主要功能视频。
这是我不工作的代码,显然我使用的是 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/