2012-02-12 280 views
1

我正嘗試使用mediaelement.js設置播放器。 我正在執行我自己的自定義播放列表 - 我只想要一個播放器,並且點擊播放列表中不同的標題,它必須自動更改播放器的來源。MediaElement.js使用同一個播放器播放音頻和視頻

我用相當簡單的代碼實現了這一點。

這裏的初始化:

var player = new MediaElementPlayer("#audioplayer", 
{ 
//if the <video width> is not specified, this is the default 
defaultVideoWidth: 480, 
// if the <video height> is not specified, this is the default 
defaultVideoHeight: 270, 
// if set, overrides <video width> 
videoWidth: -1, 
// if set, overrides <video height> 
videoHeight: -1, 
// width of audio player 
audioWidth: 960, 
// height of audio player 
audioHeight: 30, 
// initial volume when the player starts 
startVolume: 0.8, 
// useful for <audio> player loops 
loop: false, 
// enables Flash and Silverlight to resize to content size 
enableAutosize: true, 
// the order of controls you want on the control bar (and other plugins below) 
features: ['playpause','progress','current','duration','tracks','volume','fullscreen'], 

// automatically selects a <track> element 
startLanguage: '', 
// a list of languages to auto-translate via Google 
translations: [], 
// a dropdownlist of automatic translations 
translationSelector: false, 
// key for tranlsations 
googleApiKey: '' } 
); 

這是改變SRC,上點擊播放列表中的一個元素的代碼。

document.getElementById('audioplayer').src = url; 
    if(url.search('youtube')!=-1 || url.search('youtu.be')!=-1) 
    { 
    document.getElementById('audioplayer').pluginType="youtube"; 
    $('#audioplayer').attr("type","video/youtube"); 
    } 
    else 
    { 
    document.getElementById('audioplayer').pluginType="native"; 
    $('#audioplayer').attr("type","audio/mp3"); 
    } 
    player.load(); 
    player.play(); 

問題是玩家不能同時播放視頻和音頻源。我試過改變所有參數,包括src,pluginType等。它只播放音頻文件或視頻文件。

任何人都可以幫助我嗎?我猜它與初始化有關 - 如MediaElement,AudioElement或VideoElement等。

在此先感謝。

回答

1

我終於結束了使用兩個播放器 - 初始化爲音頻和其他視頻類型。顯示另一個時隱藏一個玩家,反之亦然。這是我能想到的最簡單的解決方案。