關於html5 video的連續播放


<!doctype html>
<html lang="en">
    <head>
    <meta charset="utf-8">
    <title>關於html5 video的連續播放</title>
</head>

<body>
<video id="video" autoplay="" controls="controls">您的瀏覽器不支持HTNL5的video標簽</video> 
</body>
</html>
<script>
var video_list=['videos/demo.mp4','videos/demo2.mp4'];//初始化播放列表
video_length=video_list.length;//播放列表的長度 var curr=0;//當前播放的視頻
var video=document.getElementById('video');
video.addEventListener(
'ended',play); play();
function play(){ video.src=video_list[curr];
video.load();
//若視頻很短,加載完后再播放,監聽canplaythrough事件即可
video.play();
curr
++;
if(curr>=video_length){
curr
=0;//播放完后,重新播放
    }
} </script>

 

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>連續播放</title>
    <style>
        video{
            margin: 0 auto;
            width: 500px;
            height: 500px;
        }
    </style>
</head>
<body>
        <video  id="myvideo" width="100%" height="auto" controls="controls" >
            你的瀏覽器不支持HTML5播放此視頻 
            <source src="videos/demo.mp4" type='video/mp4' />
        </video>
</body>
</html>
<script src="http://files.cnblogs.com/files/heyiming/jquery-2.1.4.min.js"></script>
<script language="javascript">
    $(document).ready(function(){
        video.play();
    });
    var vList = ['videos/demo2.mp4', 'videos/demo3.mp4','videos/demo.mp4']; // 初始化播放列表
    var vLen = vList.length;
    var curr = 0;
    var video = document.getElementById("myvideo");
    video.addEventListener('ended', function(){
        alert("已播放完成,繼續下一個視頻")
        play();
    });
    function play() {
        video.src = vList[curr];
        video.load();
        video.play();
        curr++;
        if(curr >= vLen){
            curr = 0; //重新循環播放
        }

    }
</script>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM