通过javascript播放视频循环

时间:2014-05-13 17:49:32

标签: javascript arrays html5

我正在尝试编写代码来播放两个视频的连续循环。我已尝试通过此代码执行此操作,但尚未完成。不熟悉html5和javascript需要帮助才能进行必要的更正。

<!doctype html>
<html><head>

<script>

var videoSource = new Array();
videoSource[0]="videfirst.mp4";
videoSource[1]="videosecond.mp4";
var videoCount = videoSource.length;

document.getElementById("myVideo").setAttribute("src",videoSource[0]); 


 function videoPlay(videoNum)
    {
document.getElementById("myVideo").setAttribute("src",videoSource   [videoNum]);
document.getElementById("myVideo").load();
document.getElementById("myVideo").play();
    }



    document.getElementById('myVideo').addEventListener     ('ended',myHandler,false);
 function myHandler() {
 i++;
 if(i == (videoCount-1)){
 i = 0;
    videoPlay(i);
    }
    else{
    videoPlay(i);
    }

   }
</script>
</head>

<body>

<video controls  height="180" width="300" id="video" > 

</video>

</body>
</html>

0 个答案:

没有答案