2013-03-18 69 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