2016-09-17 108 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視頻變量工作後。在我的情況下,我正在做一個過濾器,所以當你選擇一個選項時,你只會看到在過濾器上選擇的視頻。