2016-09-17 104 views
0

我需要使用videojs来显示一些视频。一个通常的视频声明如下所示(关于这个例子2个视频):videojs上的动态视频

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

我设法解决这个问题,以下是我的解决方案:

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视频变量工作后。在我的情况下,我正在做一个过滤器,所以当你选择一个选项时,你只会看到在过滤器上选择的视频。