私のサイトでは、Soundmanager Mp3 Button を使用しています。ただし、MP3 をホストする代わりに、Soundcloud Api を使用して、Soundmanager を介してトラックをストリーミングしたいと考えています。基本的に、Soundmanager ボタンから Soundcloud リンクをストリーミングしたいと思います。可能?
jQuery ループ (以下) を作成しようとしましたが、まだうまくいきません。
<ol>
<li><a class="sm2_button" href="http://soundcloud.com/....">Track Title</a>
</li>
</ol>
そして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')});");
});
});