2017-05-05 23 views
0

남자. 내 비디오를 재생하는 위의 스크립트가 있습니다. VideoJS를 사용해 보았는데 작동하지 않습니다. 아래에있는 스크립트는 모든 동영상을 재생하지만 무작위로 재생할 수는 없습니다. 비디오를 무작위로 재생할 수 있도록 도와 줄 수 있습니까?이 재생 목록을 만드는 방법 임의?

<script> 
$(document).ready(function(){ 
    var video = document.getElementById('player'); 
    var vids = ["videos/COMBATE-A-TUBERCULOSE.mp4", 
    "videos/Pilula-01.mp4", 
       "http://jell.yfish.us/media/jellyfish-3-mbps-hd-h264.mkv"]; 
    var current_vid = 0; 
    video.volume = 0.2; 
    video.setAttribute("src", vids['0']); 
    $('video').on('ended',function(){ 
     current_vid = +current_vid + 1; 
     if(typeof vids[current_vid] == 'undefined'){ 
      current_vid = 0; 
     } 
     video.setAttribute("src", vids[current_vid]); 
    }); 
    }); 

답변

0

간단한 대답 :

  $(document).ready(function(){ 
      var video = document.getElementById('player'); 
      var vids = ["videos/COMBATE-A-TUBERCULOSE.mp4", 
      "videos/Pilula-01.mp4", 
         "http://jell.yfish.us/media/jellyfish-3-mbps-hd-h264.mkv"]; 
      var current_vid = 0; 
      video.volume = 0.2; 
      $('video').on('ended',function(){ 
       current_vid = Math.floor(vids.length); 
       video.setAttribute("src", vids[current_vid]); 
      }); 
      }); 
+0

죄송합니다. 그것은 나를 위해 작동하지 않았다. 그것을보십시오 : https://jsfiddle.net/Lb5yva8t/ –