[英]Javascript & HTML5 - button to play next video not working
Thanks for stopping by. 感谢您的光临。 I'm creating a page to cycle through video clips. 我正在创建一个页面来循环播放视频剪辑。 The cycling through part (run() function) works just fine. 循环遍历部分(run()函数)效果很好。 I also created a few buttons to play the specific video clip and these are not working. 我还创建了一些按钮来播放特定的视频片段,这些按钮不起作用。 I've only written the function for the first button and I'll write the other two when I get the first working. 我只为第一个按钮编写了函数,而当第一个按钮起作用时,我将编写另外两个。
Any help if greatly appreciated. 任何帮助,如果不胜感激。
Thanks, Tommy 谢谢汤米
<video id="tutorials" autoplay onended="run()"
autobuffer="true" width="600px" height="350px" controls>
<source src="video1.mp4" type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"'>
</video>
<br>
<br>
<button id="tut1">Play Tutorial 1</button>
<button id="tut2">Play Tutorial 2</button>
<button id="tut3">Play Tutorial 3</button>
<script type="text/javascript">
video_count =1;
videoPlayer = document.getElementById("tutorials");
function run()
{
video_count++;
if (video_count == 4) return;
var nextVideo = "video"+video_count+".mp4";
videoPlayer.src = nextVideo;
videoPlayer.play();
};
document.getElementByID("tut1").onclick = function()
{
videoPlayer.stop();
videocount = 1;
var video = "video1.mp4";
videoPlayer.src = video;
videoPlayer.play();
}
</script>
I'd prefer to structure the code this way: 我更喜欢这样构造代码:
<script type="text/javascript">
video_count =1;
videoPlayer = document.getElementById("tutorials");
function runNext()
{
runVideo(video_count+1);
}
function runVideo(number)
{
if (number > 3) return;
video_count = number;
videoPlayer.src = "video"+video_count+".mp4";
videoPlayer.play();
}
</script>
HTML: HTML:
<button id="tut1" onclick="runVideo(1);">Play Tutorial 1</button>
<button id="tut2" onclick="runVideo(2);">Play Tutorial 2</button>
<button id="tut3" onclick="runVideo(3);">Play Tutorial 3</button>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.