List tracks from Soundcloud and play it with Soundmanager 2 on a Wordpress blog

守給你的承諾、 提交于 2019-12-20 05:25:13

问题


first of all this is not a cry for a perfectly coded solution but it would be perfect if someone could at least give me some tips on how to solve this problem which is: I have this custom Wordpress site for a record label. On this site there is of course a section showing the releases of every of their artist's tracks.

The client needs to upload all their tracks to Soundcloud. In the WP backend they can enter the name of the album, upload a cover image and add as many tracks as they want using MagicFields for Wordpress. After adding the album information and the track names they can enter the URL of the specific track hosted on Soundcloud. WP then lists all of these tracks as following:

(It seems I can not upload images so here is the link) http://postimage.org/image/22ob8ymys/

On the left side you can see Soundmanager2's 360 visualization. Right now the MP3s are uploaded to the label's website (which I need to change) and the link of each list item looks something like this:

<ol>
  <a href="#" onclick="if (threeSixtyPlayer.lastSound) { threeSixtyPlayer.lastSound.stop(); } document.getElementById('mp3').href = 'track1.mp3'; threeSixtyPlayer.handleClick({target: document.getElementById('mp3')});"><li>Track 1</li></a>
  ...
</ol>

As you can see the link leads to specific files, ending with the extension .mp3 to make it playable via SM2. But as you might know you can not easily access an MP3 on Soundcloud. Passing an URL like 'www.soundcloud.com/artist/track1' seems not to work.

I've made some research about Soundcloud's API but guess what, it's too complex for me to understand (that's why I am here). The documentation on http://soundcloud-sm2.heroku.com/docs/application.html came quite close to what I was looking for but unfortunately I can not use it because the tracks should not be included on the site via JS but PHP.

I hope someone of you could give me some tips on how to solve this specific problem. Thanks for reading this far ;)


回答1:


You need to get the stream URI using Soundcloud's API. You can get the stream URI by making a request like:

https://api.soundcloud.com/tracks/5677638.json

where 5677638 is the id of the track you want to get the info of.

But you do need an API key which you can request for free at: Soundcloud Developers

So after that you can make a request like:

https://api.soundcloud.com/tracks/5677638.json?consumer_key={your api key}

That request will get you an json encoded string which contains all the info about the track, e.g.:

{
  "id": 5677638,
  "created_at": "2010/09/29 19:46:01 +0000",
  "user_id": 378405,
  "duration": 183945,
  "commentable": true,
  "state": "finished",
  "sharing": "public",
  "tag_list": "electro electrohouse remix green velvet remixcontest remixcompetition remixcomp foem uptempo",
  "permalink": "green-velvet-feat-santiago-bushido-turn-it-up-sander-van-halem-remix",
  "description": "Now let's turn it up up up up! :D Remix comp at http://foem.info/index.php?option=com_content&task=view&id=383&Itemid=97 . Some feedback would be appreciated. ",
  "streamable": true,
  "downloadable": true,
  "genre": "",
  "release": "",
  "purchase_url": null,
  "label_id": null,
  "label_name": "",
  "isrc": "",
  "video_url": null,
  "track_type": "remix",
  "key_signature": "",
  "bpm": 128,
  "title": "Green Velvet feat. Santiago and Bushido - Turn It Up (Sander van Halem Remix)",
  "release_year": null,
  "release_month": null,
  "release_day": null,
  "original_format": "mp3",
  "license": "all-rights-reserved",
  "uri": "https://api.soundcloud.com/tracks/5677638",
  "permalink_url": "http://soundcloud.com/sander-van-halem/green-velvet-feat-santiago-bushido-turn-it-up-sander-van-halem-remix",
  "artwork_url": "http://i1.sndcdn.com/artworks-000002478404-sy6zd5-large.jpg?6cbf23e",
  "waveform_url": "http://w1.sndcdn.com/1Iydbj7KnvOi_m.png",
  "user":  {
    "id": 378405,
    "permalink": "sander-van-halem",
    "username": "Sander van Halem",
    "uri": "https://api.soundcloud.com/users/378405",
    "permalink_url": "http://soundcloud.com/sander-van-halem",
    "avatar_url": "http://i1.sndcdn.com/avatars-000000760311-hwm8iz-large.jpg?6cbf23e"
  },
  "stream_url": "https://api.soundcloud.com/tracks/5677638/stream",
  "download_url": "https://api.soundcloud.com/tracks/5677638/download",
  "playback_count": 1386,
  "download_count": 67,
  "favoritings_count": 17,
  "comment_count": 34,
  "attachments_uri": "https://api.soundcloud.com/tracks/5677638/attachments"
}

As you can see there is an stream_url item which contains the URL you can use to 'embed' the track using SoundManager just like you would with a local mp3.



来源:https://stackoverflow.com/questions/7464400/list-tracks-from-soundcloud-and-play-it-with-soundmanager-2-on-a-wordpress-blog

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!