我有BigVideo.js在一些客户端网站上工作,最近我被问到是否可以加载3或4个视频,并在每次访问时随机加载它们。我是初学者,但是我得到了jist。首先我想写一个视频源阵列,然后是一个随机函数等......
问题是,如果使用firefox,则会显示一个firefox条件来显示.ogg视频源。我真的不知道如何加载具有这种条件的数组,所以我将不胜感激任何建议
这是大视频js> http://dfcb.github.com/BigVideo.js/
以下是显示视频的索引页面的代码:
<script>
$(function() {
var BV = new $.BigVideo({useFlashForFirefox:true});
BV.init();
BV.show('http://clients.kevinhowbrook.com/nw/bigvideo/vids/video1.mp4',{ambient:true}, {altSource:'http://clients.kevinhowbrook.com/nw/bigvideo/vids/video1.ogv'});
});
</script>
答案 0 :(得分:1)
您可以创建可能出现的多个视频的数组,并随机选择数组中的成员:
var videos = ['http://clients.kevinhowbrook.com/nw/bigvideo/vids/video1.mp4',
'some other video',
'some third video'];
var index = Math.floor(Math.random() * videos.length);
BV.show(videos[index], params);
您可能还需要数组中的alt源:
var videos = [
{source: 'http://clients.kevinhowbrook.com/nw/bigvideo/vids/video1.mp4', alt: 'http://clients.kevinhowbrook.com/nw/bigvideo/vids/video1.ogv'},
{source: 'some other video', alt: ''},
{source: 'some third video', alt: ''}
];
var index = Math.floor(Math.random() * videos.length);
BV.show(videos[index].source, params);
答案 1 :(得分:0)
刚刚更新这个... Konstantin的答案是正确的(如标记所示),但这是另一种方法
var aryFiles = ["http://localhost:8888/_websites/davesims/wp-content/themes/david/video/vids/river.mp4", "http://localhost:8888/_websites/davesims/wp-content/themes/david/video/vids/dock.mp4"];
var idx = Math.floor(aryFiles.length * Math.random());
var BV;
$(function() {
// initialize BigVideo
BV = new $.BigVideo();
BV.init();
BV.show(aryFiles[idx], {
ambient: true
});
});