如何让这位玩家随机?
问题描述:
伙计。我有上面的脚本播放我的视频。我试过使用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]);
});
});
答
简单的答案:
$(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]);
});
});
对不起。它不适合我。看到它:https://jsfiddle.net/Lb5yva8t/ –