2017-05-05 3 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/ –

関連する問題