How to get proper soundcloud url for embedding from a standard url?

梦想与她 提交于 2019-12-02 19:40:33
Lincoln B

He is trying to get html to create a Soundcloud widget, not get the API url for a track. The oEmbed method "will serve the widget embed code for any SoundCloud URL pointing to a user, group, set or a playlist" and is recommended to make sure Soundclouds changes don't break your app (as opposed making your own Flash object or iframe). You can call it with a PHP web request to

http://soundcloud.com/oembed?format=js&url=[escaped_url]&iframe=true

Or with a JSON-P call (using jQuery for convenience)

$.getJSON('http://soundcloud.com/oembed?callback=?',
    {format: 'js', url: 'http://snd.sc/yp6VMo', iframe: true},
    function(data) {
        // Stick the html content returned in the object into the page
        $('#your_player_div').html(data['html'])
    }
)

I'm adding iframe=true so you get the new HTML5 player, omit to get the old Flash object. It also works with the .sc short urls you are using.

you can try this for song url not for the id of song url

    <iframe width="100%" height="166" scrolling="no" frameborder="no"src="http://w.soundcloud.com/player/?url=http://api.soundcloud.com/elissafranceschi/war&auto_play=false&color=915f33&theme_color=00FF00"></iframe>

I'm not exactly sure what you're asking here, but it sounds like you might need the "resolve" API endpoint. http://developers.soundcloud.com/docs/api/resolve

Example:

$ curl -v 'http://api.soundcloud.com/resolve.json?url=http://soundcloud.com/matas/hobnotropic&client_id=YOUR_CLIENT_ID'

HTTP/1.1 302 Moved Temporarily
Location: http://api.soundcloud.com/tracks/49931.json

This will give you all the track information and that should be enough for whatever you need to do. Also don't forget that there's the HTML5 widget too.

I haven't tried this, modified code from here:

<object height="81" width="100%">
   <param name="movie" value="http://player.soundcloud.com/player.swf?url=<?php echo $url; ?>&amp;g=bb"></param>
   <param name="allowscriptaccess" value="always"></param>
   <embed allowscriptaccess="always" height="81" src="http://player.soundcloud.com/player.swf?url=<?php echo $url; ?>&amp;g=bb" type="application/x-shockwave-flash" width="100%"></embed>
</object>
<a href="<?php echo $url; ?>"><?php echo $url; ?></a>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!