我在我的网站上使用Soundmanager Mp3按钮。但是,我想使用Soundcloud Api通过Soundmanager流式传输音轨,而不是托管MP3。基本上,我想通过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')});");
});
});
答案 0 :(得分:5)
这也让我疯了。经过一堆挖掘后,如果我在链接中指定了mp3 mimetype,我就可以使用它:
<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>
答案 1 :(得分:1)
您也可以尝试使用SoundCloud Javascript SDK,它将为您处理大部分内容。
SC.initialize({
client_id: "YOUR_CLIENT_ID",
redirect_uri: "http://example.com/callback.html",
});
SC.stream("/tracks/293", function(sound){
sound.play();
});
答案 2 :(得分:0)
我试过这个,以为我拥有它......任何人都看到了什么?
<script src="http://connect.soundcloud.com/sdk.js"></script>
<script>
SC.initialize({
client_id: "My Consumer Key",
redirect_uri: "My Redirect",
});
SC.get("/users/MYUSERID/tracks", {limit: 1000}, function(tracks){
alert("Latest track: " + tracks[0].title);
});
$(".sm2_button").live("click", function(sound){
sound.play();
});
</script>
<script>
$(document).ready(function() {
$(".sm2_button").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')});");
});
});
}); </script>