2011-04-11 104 views
1

我正在使用雅虎媒體播放器播放我的網站上的MP3歌曲。使用雅虎媒體播放器處理動態MP3網址

我在網站上放了一些靜態的mp3鏈接。 例如

鬆1 Song2

而且我已經把YMP JS API代碼也。

現在,我要動態加載的歌曲...

例如,如果一個按鈕用戶點擊我想加載一個完整的新的播放列表到播放器。

//Something like this 
var clickEventHandler = function(){ 
    YMP.removeAllSongs(); 
    YMP.addSongs(mp3_links); 
    YMP.play(); 
} 

請幫幫我。謝謝。

回答

1

這可能會幫助你,用這個:

<script> 
/** On Yahoo Media API Ready **/ 
var yesReady = false; 
YAHOO.MediaPlayer.onAPIReady.subscribe(function(){ 
    yesReady = true; 
}); 

function play(){ 
    //Capture the URL of the song 
    var url = document.getElementById('url').value; 
    //Put it in Href of Song Link 
    document.getElementById('link').href = url; 

    //After that Play the Song using YMP 
    if(yesReady){ 
    YAHOO.MediaPlayer.addTracks(document.getElementById('song-div'), 0, true); 
    YAHOO.MediaPlayer.play(); 
    } 
} 
</script> 

<div id='song-div'> 
    <a href='#' id='link'>Song Name</a> 
</div> 

<input type='text' id='url' /> 
<input type='button' onClick="javascript:play('url')" value='play'/> 

讓我知道如果你需要更多的幫助。