2013-03-18 56 views
4

現在我有一個網站使用jPlayer在mp3上播放。我也希望能夠添加讓SoundCloud直接在播放器上播放的功能。如何將SoundCloud文件添加到jPlayer?

我知道這是可能的,因爲一個我喜歡的音樂博客hillydilly做到這一點。從看他們的代碼,我看到他們的jPlayer的設置有一些額外的參數,即sc和sclink。

$(".play-music").each(function(){ 
     myPlaylist.add({ 
     title: $(this).attr('data-title'), 
     artist: $(this).attr('data-artist'), 
     mp3: $(this).attr('data-mp3'), 
     url: $(this).attr('data-url'), 
     sc: $(this).attr('data-sc'), 
     sclink: $(this).attr('data-sclink')   
     }); 
}); 

我試圖尋找通過其代碼的休息,但無法弄清楚如何或在哪裏,他們實現SC和sclink。任何幫助?

回答

8

如果你看看他們的播放列表所鏈接到的SoundCloud爲軌道的MP3性能:

myPlaylist.setPlaylist([ 

{ 
     title:"Close Enough ft. Noosa", 
    artist:"Ghost Beach", 
    mp3:"http://api.soundcloud.com/tracks/79031167/stream?client_id=db10c5086fe237d1718f7a5184f33b51", 
    url:"http://hillydilly.com/2012/12/top-20-songs/", 
    sc:"true" 
    }, 
    { 
     title:"Always", 
    artist:"Jahan Lennon", 
    mp3:"http://api.soundcloud.com/tracks/80961874/stream?client_id=db10c5086fe237d1718f7a5184f33b51", 
    url:"http://hillydilly.com/2012/12/top-20-songs/", 
    sc:"true" 
    } 

HTML5「流」其實只是你的MP3目前還不能像您可以用保護他們Flash,Silverlight,Quicktime等。如果您直接打開其中一個鏈接(如http://api.soundcloud.com/tracks/79031167/stream?client_id=db10c5086fe237d1718f7a5184f33b51),它會下載MP3。所以我猜測你把它設置成它應該工作的相同方式。

如果你打開瀏覽器和它的網絡檢查(在開發工具:查看>開發者>開發者工具,然後單擊網絡),並點擊下一步丘陵的球員,你可以看到在後臺軌道載荷。

enter image description here

3

其實kreek的答案是隻是故事的一半。

如果要傳輸的SoundCloud歌曲,你是第一個需要developers.soundcloud.com開發者頁面上註冊自己的網站。

然後用他們的super cool API你自己的鍵。您可以將json加載到您的php並在那裏生成鏈接,或者使用jquery $ .getJSON加載信息。

當從SoundCloud聲音流你也想以確保正確的屬性。來自soundcloud的人非常慷慨地讓我們使用他們的數據庫。

//遺憾的不良鏈接(無學分)

How do I use external JSON...?

http://api.jquery.com/jQuery.getJSON/

http://developers.soundcloud.com/docs/api/buttons-logos