我需要使用videojs来显示一些视频。通常的视频声明如下所示(本示例中为2个视频):
var videos = [
{
src : [
'http://demo.dealerpro.net/Images/Sites/577/videos/HondaHands.mp4'
],
poster : 'http://i145.photobucket.com/albums/r217/Carnifreekshow/Asus%20Orion%20Repair/before_zps12ce48a2.jpg',
title : 'Honda. The Power of Dreams.'
},
{
src : [
'http://1eb9cddbb30a65a675d4-91fe7d858d3e9c59dcdfd3e789416fbc.r56.cf1.rackcdn.com/Sites/577/commercial.mp4'
],
poster : 'http://i145.photobucket.com/albums/r217/Carnifreekshow/Asus%20Orion%20Repair/before_zps12ce48a2.jpg',
title : 'Thanks for Making Us #1'
}
];
我在另一个阵列上有一些视频的src,海报和标题信息,我需要根据一些过滤器动态地声明它。我需要做这样的事情:
for (var index = 0;index<totalVideos;index++)
{
var videos = [
{
src : [
sourceArray[index]
],
poster : posterArray[index],
title : titleArray[index]
}
];
}
但这是行不通的,有人知道我该如何动态声明要在videojs上使用的视频?
我设法解决了,以下是我的解决方案:
var totalVideos = 3;//put the ammount of videos you want to dynamically add
/*You need to fill this arrays with the information of your videos*/
var arrayTitles = new Array(totalVideos);
var arraySources = new Array(totalVideos);
var arrayPosters = new Array(totalVideos);
var videos = new Array(totalVideos);
for (var index = 0;index<totalVideos;index++)
{
var theVideo = {
src: [
arraySources[index]
],
poster: arrayPosters[index],
title: arrayTitles[index]
};
videos[index] = theVideo;
}
之后,您可以开始使用videojs的videos变量。就我而言,我正在做一个过滤器,因此当您选择一个选项时,您只会看到在过滤器上选择的视频。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句