Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Play SoundCloud links through Soundmanager2

I'm using the Soundmanager Mp3 Button on my site. However, I'd like to use the Soundcloud Api to stream tracks through Soundmanager instead of hosting MP3's. Basically, I'd like to stream a Soundcloud link through the Soundmanager button. Possible?

I've tried creating a jQuery loop (below) but still haven't had any luck.

<ol>
<li><a class="sm2_button" href="http://soundcloud.com/....">Track Title</a>
</li>
</ol>

and the jQuery

$("ol a").each(function()
    { 
        var thisLink = $(this);                         
        var track_url = this.href;                      // save href value of each link to 'track_url' i.e. soundcloud.com/...
        this.href = this.href.replace(track_url, "#");  // replace href value with '#'
        var consumer_key = 'My Consumer Key';
            // now resolve the stream_url through Soundcloud's getJSON method
        $.when($.getJSON('http://api.soundcloud.com/resolve?url=' + track_url + '&format=json&consumer_key=' + consumer_key + '&callback=?', function(track) {
            url = track.stream_url + '?consumer_key=' + consumer_key;   
            })).done(function() {
                // and place an 'onclick' on each link
                $(thisLink).attr('onclick', "if (basicMP3Player.lastSound) { basicMP3Player.lastSound.stop(); } document.getElementById('mp3').type='audio/mpeg'; document.getElementById('mp3').href = '" + url + "'; basicMP3Player.handleClick({target: document.getElementById('mp3')});");
            });
    }); 
like image 609
Graphicd02 Avatar asked Dec 12 '25 14:12

Graphicd02


1 Answers

This was driving me nuts too. After a bunch of digging I was able to get it to work if I specified an mp3 mimetype in the link:

<ol>
    <li><a type="audio/mp3" class="sm2_button" href="https://api.soundcloud.com/tracks/49349198/stream?client_id=YOUR_CLIENT_ID">Track Title</a></li>
</ol>
like image 188
Ben Y Avatar answered Dec 16 '25 04:12

Ben Y



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!