如何使这个剧作家随机?

时间:2017-05-05 12:32:12

标签: video random playlist

人。我上面的剧本播放我的视频。我尝试过使用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]);
    });
  });

1 个答案:

答案 0 :(得分: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]);
            });
          });