2013-01-23 42 views
3

我在我的網站上使用Soundmanager Mp3按鈕。但是,我想使用Soundcloud Api通過Soundmanager流式傳輸音軌,而不是託管MP3。基本上,我想通過Soundmanager按鈕傳送Soundcloud鏈接。可能?通過Soundmanager2播放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

一些對SoundManager類論壇中的主題可以幫助你:https://getsatisfaction.com/schillmania一堆挖我能得到它,如果我在鏈接中指定的MIME類型MP3的工作後,/searching?query = soundcloud&x = 0&y = 0&style = topics – nickf

+0

試過了。在這裏瘋狂哈哈。當鏈接到一個託管的mp3,但不soundcloud鏈接時完美播放 – Graphicd02

回答

1

您也可以嘗試使用的SoundCloud Javascript SDK,which'll照顧這個最適合你。

SC.initialize({ 
    client_id: "YOUR_CLIENT_ID", 
    redirect_uri: "http://example.com/callback.html", 
}); 


SC.stream("/tracks/293", function(sound){ 
    sound.play(); 
}); 
+0

感謝您的答覆。我已經添加了上面的腳本,但似乎無法讓它工作。有沒有我應該添加到錨點的課程? Graphicd02

0

我試過這個,並認爲我有它...任何人都看到了什麼?

<script src="http://connect.soundcloud.com/sdk.js"></script> 
    <script> 
    SC.initialize({ 
     client_id: "My Consumer Key", 
     redirect_uri: "My Redirect", 
    }); 

    SC.get("https://stackoverflow.com/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> 
5

這也讓我瘋了。

<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

這應該是被接受的答案。謝謝Ben。 –