2016-09-17 5 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と動画の変数で作業を開始することができます。私の場合はフィルタを実行しているので、オプションを選択すると、フィルタで選択されたビデオが表示されます。