DaveR
DaveR

Reputation: 2483

Dynamically embedding soundcloud clips

If you want to embed youtube dynamically then it is totally easy. You just replace the video id in the embed code.

<iframe width="420" height="315" src="http://www.youtube.com/embed/<?=$youtubeid;?>" frameborder="0" allowfullscreen></iframe>

I'm struggling to do the same thing with soundcloud. Is it possible? - the embed code is as follows:

<iframe src="http://w.soundcloud.com/player/?url=http%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F57162664&show_artwork=true"></iframe>

It seems to me like you'd need to know this api code to embed the track, and so you'd have to look this up each time.

Upvotes: 0

Views: 2268

Answers (2)

nickf
nickf

Reputation: 546025

The 'api code' is just tracks/ followed by the track id (or groups/ with a group id, etc), not too different from YouTube, it's just not as easily accessible as YouTube's, since the id isn't in the URL. You can get the id from looking at the share code on a track, but even easier is to use the oembed service to get the full embedding HTML needed (it also calculates the proper height of the iframe to include), and it only requires the 'permalink' url which you see on a track page.

An updated version of the widget coming in the next few weeks should also support the permalink urls out-of-the-box.

Upvotes: 1

DaveR
DaveR

Reputation: 2483

Looks like you have to use the API to dynamically get the embed code:

Here's the documentation:

http://developers.soundcloud.com/docs#playing

Upvotes: 0

Related Questions