目前,我正在使用这个jquery,它获取youtube视频并在元素的背景中播放它们。
我得到了这个代码,它将播放youtube上的单个视频。但我想做一个视频列表然后随机播放..。我现在对Javascript不太在行,所以我很想在这方面提供一些帮助.
现在我有这个..。
我想制作一张视频列表,像一张杂乱的播放列表一样随机播放。
$(function()
{
var videos = ['xJvt2SDV7ck', 'x6DD1k4BAUg', 'xJvt2SDV7ck'];
var index = Math.floor(Math.random() * videos.length);
var Video_back = new video_background($("#bgvideo"),
{
"position": "absolute", //Stick within the div
"z-index": "-1", //Behind everything
"loop": true, //Loop when it reaches the end
"autoplay": true, //Autoplay at start
"muted": true, //Muted at start
"youtube": "videos[index]", //Youtube video id
"start": 0, //Start with 6 seconds offset (to pass the introduction in this case for example)
"video_ratio": 1.333, // width/height -> If none provided sizing of the video is set to adjust
"fallback_image": "videos/main.jpg", //Fallback image path
});
});目前它只播放从列表中随机选择的1段视频(单圈)。我想制作它,这样当第一个视频结束时,它就会转到另一个视频。
我们会非常感谢你的帮助!谢谢您抽时间见我!
发布于 2014-10-11 22:41:00
以下的答案是基于这样的事实,即没有办法确定什么时候视频已经完成。长度以毫秒为单位:
$(function()
{
var videos =
[
{ id : 'xJvt2SDV7ck', length : 60000 },
{ id : 'x6DD1k4BAUg', length : 125000 },
{ id : 'xJvt2SDV7ck', length : 166000 }
];
function playNext()
{
var index = Math.floor(Math.random() * videos.length);
alert( "Playing next movie => " + videos[index].id );
var Video_back = new video_background($("#bgvideo"),
{
"position": "absolute", //Stick within the div
"z-index": "-1", //Behind everything
"loop": true, //Loop when it reaches the end
"autoplay": true, //Autoplay at start
"muted": true, //Muted at start
"youtube": videos[index].id, //Youtube video id
"start": 0, //Start with 6 seconds offset (to pass the introduction in this case for example)
"video_ratio": 1.333, // width/height -> If none provided sizing of the video is set to adjust
"fallback_image": "videos/main.jpg", //Fallback image path
});
setTimeout(function()
{
playNext();
}, videos[index].length);
}
playNext();
});https://stackoverflow.com/questions/26314661
复制相似问题