2012-09-10 50 views
1

我已將MediaElement.js視頻播放器集成到我的MVC 4應用程序中。在該視圖中,我有一個按鈕,並在按鈕單擊中我想更改視頻源和海報圖像。我已經找到屬性來更改mediaelementjs.com中提供的代碼上的按鈕點擊視頻源。但它不包含任何改變海報圖片的屬性。是否有可能像視頻源一樣更換海報圖片?媒體Element.js - 更改視頻海報圖像

這裏是我的代碼:

<div class="videoplayer">  
      <video width="436" height="331" id="player2" poster="../../Images/pix.jpg" controls="controls" preload="none"> 

      <!-- MP4 source must come first for iOS --> 
      <source type="video/mp4" src="http://127.0.0.1:10000/devstoreaccount1/videos/video2.mp4" /> 

      <!-- Fallback flash player for no-HTML5 browsers with JavaScript turned off --> 
       <object width="436" height="331" type="application/x-shockwave-flash" data="../build/flashmediaelement.swf">   
        <param name="movie" value="../build/flashmediaelement.swf" /> 
        <param name="flashvars" value="controls=true&amp;file=http://127.0.0.1:10000/devstoreaccount1/videos/video2.mp4" />   
        <!-- Image fall back for non-HTML5 browser with JavaScript turned off and no Flash player installed --> 
        <img src="../../Images/pix.jpg" width="436" height="331" alt="No video playback capabilities" 
         title="No video playback capabilities" /> 
       </object> 
      </video> 
     </div> 
     <script> 

      $('audio,video').mediaelementplayer({ 
       success: function (player, node) { 
        debugger; 
        $('#' + node.id + '-mode').html('mode: ' + player.pluginType); 
       } 
      }); 

    </script> 

    <input type="button" id="changevideo" value="Change Video" /> 

    <script type="text/javascript"> 
     $('#changevideo').click(function() { 
      $('video, audio').each(function() { 
       $(this)[0].player.setSrc("http://127.0.0.1:10000/devstoreaccount1/videos/video1.mp4"); 
       $(this)[0].player.play(); 
      }); 
     }); 

    </script> 

感謝。

回答

1
$('#changeposter').click(function() { 
    $('video, audio').each(function() { 
     $(this).attr("poster", "../../Images/new_pix.jpg"); 
    }); 
}); 
0

更改海報以便生效後更好地重新加載播放器。

var player = new MediaElementPlayer('#your-player-element-id'); 
player.load(); 
player.play(); 
player.pause(); 
相關問題