我需要使用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?
答案 0 :(得分:0)
我设法解决了,下面是我的解决方案:
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处理视频变量。在我的情况下,我正在做一个过滤器,所以当你选择一个选项时,你只看到在过滤器上选择的视频。