我创建了一个html5视频播放列表。当页面首次加载时,我希望视频暂停,因此用户可以选择开始自动播放序列。
代码:
<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'>//<![CDATA[
window.onload=function(){
var videoPlayer= document.getElementById('video');
videoPlayer.addEventListener('ended', function(){
this.pause();
this.src = "http://www.mp4point.com/downloads/8feeca1a540b.mp4";
}, false);
}//]]>
</script>
</head>
<body>
<video id="video" src="http://media.w3.org/2010/05/sintel/trailer.mp4" autoplay autobuffer controls />
</body>
</html>
的jsfiddle:http://jsfiddle.net/3uRq6/7/
答案 0 :(得分:0)
从它的外观来看,你需要扭转你的逻辑。从autoplay
移除<video>
属性,在您的事件监听器上,您应该更改src
,然后播放视频。
<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'>//<![CDATA[
window.onload=function(){
var videoPlayer= document.getElementById('video');
videoPlayer.addEventListener('ended', function(){
this.src = "http://www.mp4point.com/downloads/8feeca1a540b.mp4";
this.play();
}, false);
}//]]>
</script>
</head>
<body>
<video id="video" src="http://media.w3.org/2010/05/sintel/trailer.mp4" autobuffer controls />
</body>
</html>