2013-04-06 36 views
2

有一個HTML播放列表,我想在用戶點擊播放列表中的項目時更改當前視頻和圖像,但它不起作用。我的代碼有什麼問題?使用Javascript API在JWPlayer 5中動態更改文件和圖像

我的HTML:

<div class="item-video"> 
    <script> 
     var playerData = { 
      file: 'dummy-file.flv', 
      image: 'dummy-image.jpg', 
      autostart: false 
     } 
    </script> 
    <div id="item-player"></div> 
    <div class="playlist"> 
     <ul> 
      <li> 
       <a class="thumb-holder" href="#" data-video="new-video.flv" data-image="new-image.jpg" title="test"> 
        <img src="" alt="" /> 
        <span>test</span> 
       </a> 
      </li> 
     </ul> 
    </div> 
</div> 

JavaScript代碼:

if ($(".item-video").length) { 
    if (typeof playerData != 'undefined') { 
     jwplayer('item-player').setup({ 
      file: playerData.file, 
      image: playerData.image, 
      height: '300', 
      width: '420', 
      stretching: 'uniform', 
      smoothing: 'false', 
      modes: [ 
       { 'type': 'html5' }, 
       { 'type': 'flash', src: '/mediaplayer/player.swf' }, 
       { 'type': 'download' } 
      ], 
      autostart: playerData.autostart, 
      backcolor: '#efefef', 
      controlbar: 'bottom', 
      skin: '/mediaplayer/skins/bekle/bekle.zip', 
      allowscriptaccess: 'always', 

     }); 
    } 
    $(".playlist").delegate('a', 'click', function(e) { 
     var $item = $(this); 
     var video = $item.attr('data-video'); 
     var image = $item.attr('data-image'); 
     if (typeof video != 'undefined') { 
      jwplayer().load({ 
       file: video, 
       image: (typeof image != 'undefined') ? image : "" 

      }); 
     } 
     e.preventDefault(); 
    }); 
} 

似乎JWPlayer傢伙已經刪除JWPlayer 5的文件和他們建議升級到JWPlayer 6,但我不能!

+0

你有鏈接到此代碼運行的位置?此外,JW5文檔剛剛移動,並未被刪除。它現在駐留在這裏 - http://www.longtailvideo.com/support/jw5/ – emaxsaun 2013-04-06 22:12:30

+0

不幸的是代碼運行在我的本地,直到我能找到解決這個問題的方案。如果您要求我的網頁,我相信我的網頁上沒有任何其他javascript錯誤。 – 2013-04-08 08:58:16

+0

難道是因爲我的JWPlayer版本?它是5.2。此API是否適用於所有JWPlayer 5版本? – 2013-04-08 09:02:44

回答

1

感謝Ethan LongTail的建議,問題是因爲使用早期版本的JWPlayer(我使用的是5.2,API與5.3+以上版本兼容)。

更新播放器解決了問題。