连续播放视频 [英] Continuous Play of video
本文介绍了连续播放视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我目前有这个:
Javascript
Javascript
<script>
$('document').ready(function(){
$('video').get(0).play();
// $('video').bind('ended', function(){
// $(this).next('video');
// });
$('video').each(function(val, index){
$(this).bind('ended', function(){
$(this).get(index + 1).play();
});
});
});
</script>
HTML
<video width="703" height="704" controls preload="auto" src="LOW.mp4">Video format not supported.</video>
<h3>CBS - m4v</h3>
<video width="703" height="704" controls preload="auto" src="1100.m4v">Video format not supported.</video>
<h3>Video #3</h3>
<video width="703" height="704" controls preload="auto" src="yep.mp4">Video format not supported.</video>
现在,javascript无效。如何在第一个视频完成后立即播放下一个视频,然后在第二个视频完成后播放第三个视频。并不总是有3个视频,而且还有更多。
Right now, the javascript isn't working. How do I play the next video as soon as the first video finishes and then play the third one once the second one finishes. There aren't always 3 videos, there coudld be more.
推荐答案
您的脚本中有两个小错误,以下代码为未经测试,但应该有效:
You have two small errors in your script the following code is untested, but should work:
$(function(){
var videos = $('video').each(function(index){
$(this).bind('ended', function(){
var video = videos[index + 1];
video && video.play();
});
});
if(videos.get(0).play){
videos.get(0).play();
}
});
以下是您的一些错误:
- 每个(fn(val,index){})每个的回调都被调用,索引作为第一个参数,元素作为第二个参数(每个(fn(index,video){})
- $(this).get(index + 1)这引用视频元素而不是视频列表(+ index也是上面的视频)
这篇关于连续播放视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文