2017-08-28 85 views
0

我需要一個視頻播放和無縫循環定義的次數,然後跳到下一個視頻並無縫循環定義次數,依此類推,直到播放列表結束。視頻播放循環播放另一個ja

在一個頁面中,用戶定義要播放的視頻以及「循環」(或迭代)的次數。這些是使用會話變量作爲存儲:

$_SESSION["Exer[" .$x. "]"]

$_SESSION["Reps[" . $x. "]"]

我忽略了這方面(的PHP的東西)目前

我有一些代碼獨立工作,一個循環和一個播放的播放列表,但我似乎不能管理他們的合併一起實現功能。該代碼如下:

HTML

<video width="320" height="240" id="myVideo" autoplay="autoplay"> 
</video> 

的JavaScript 對於循環:

<script> 
var iterations = 1; 

document.getElementById('iteration').innerText = iterations; 
document.getElementById('myVideo').src = "Video/01.mp4"; 
myVideo.addEventListener('ended', function() {  

    if (iterations < 3) {  

     this.currentTime = 0; 
     this.play(); 
     iterations ++; 

     document.getElementById('iteration').innerText = iterations; 

    } 

}, true); 
</script> 

播放列表:

<script> 
var videoSource = new Array(); 
videoSource[0] = "Video/01.mp4"; 
videoSource[1] = "Video/02.mp4"; 
videoSource[2] = "Video/03.mp4"; 
videoSource[3] = "Video/04.mp4"; 
var i = 0; // define i 
var videoCount = videoSource.length; 

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); 
videoPlay(0); // play the video 


function myHandler() { 
    i++; 
    if (i == (videoCount - 1)) { 
     i = 0; 
     videoPlay(i); 
    } else { 
     videoPlay(i); 
    } 
} 
</script> 

任何幫助表示讚賞。

+0

有你合併後嘗試?如果沒有,然後嘗試它,併發布代碼,如果您遇到問題 – Amogh

+0

我試圖合併兩個倍數(許多和許多)時間...我可以 – terry25110

+0

然後顯示該代碼 – Amogh

回答

1

請檢查此,Java腳本代碼,將重播了多次提及數量的視頻,然後播放下一個視頻,如果存在播放列表:

var eachVdoLoop = 2; 
var currentVdoLoop=0; 
var videoSource = new Array(); 
videoSource[0] = "http://www.sample-videos.com/video/mp4/240/big_buck_bunny_240p_1mb.mp4"; 
videoSource[1] = "https://www.w3schools.com/html/mov_bbb.mp4"; 
var videoCount = videoSource.length; 
var vdoIndex=0; 
document.getElementById('myVideo').addEventListener('ended', myHandler, false); 

nextVideo(); 


function myHandler() { 
    currentVdoLoop++; 
    if(currentVdoLoop < eachVdoLoop) 
    { 
      document.getElementById("myVideo").play();  
    } 
    else 
    { 
      vdoIndex++; 
      currentVdoLoop=0; 
      nextVideo(); 
    } 
} 

function nextVideo() { 
    if(vdoIndex == videoSource.length) 
    { 
     alert("Playlist ended!!!") 
     return; 
    } 
    document.getElementById("myVideo").setAttribute("src", videoSource[vdoIndex]);  
    document.getElementById("myVideo").play(); 
} 

的工作jsfiddle(小提琴更新)