How to get embed code from soundcloud URL

In this article we are going to talk about how to get the soundcloud embed code or how to embed the soundcloud code from url in PHP. You need to copy and paste the soundcloud url and using PHP we are going to create soundcloud embed script.

How to get embed code from soundcloud URL

SoundCloud oEmbed

SoundCloud oEmbed provides you the easy way to embed the widget or playlist from any SoundCloud URL. It accepts any URL pointing to a user, group, set or track and supports JSON (CORS), JSONP and XML (default) as a response format.

Name Default Description
url A Soundcloud URL for a track, set, group, user.
format json (optional) Either xml, json or js (for jsonp).
callback (optional) A function name for the jsonp callback .
maxwidth 100% (optional) The maximum width in px.
maxheight 81 or 305 (optional) The maximum height in px. The default is 81 for tracks and 305 for all other.
color (optional) The primary color of the widget as a hex triplet. (For example: ff0066).
auto_play false (optional) Whether the widget plays on load.
show_comments true (optional) Whether the player displays timed comments.
iframe true (optional) Whether the new HTML5 Iframe-based Widget or the old Adobe Flash Widget will be returned.

You can find more details about soundCloud oEmbed here.

Live Demo Download

Pull SoundCloud Embed Code using SoundCloud oEmbed

//Get the SoundCloud URL
//Get the JSON data of song details with embed code from SoundCloud oEmbed
//Clean the Json to decode
$decodeiFrame=substr($getValues, 1, -2);
//json decode to convert it as an array
$jsonObj = json_decode($decodeiFrame);

//Change the height of the embed player if you want else uncomment below line
// echo $jsonObj->html;
//Print the embed player to the page
echo str_replace('height="400"', 'height="140"', $jsonObj->html);

The above code will get the entered SoundCloud URL and request the track details from soundCloud server using oEmbed. This will return a json response, from that we will get the embed code of given soundCloud track.

Hope you like this article. If so don’t forget to make free email subscription for more updates.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>