3

私のサイトでは、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')});");
            });
    }); 
4

3 に答える 3

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>
于 2013-06-26T18:56:26.630 に答える
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();
});
于 2013-01-23T12:06:46.127 に答える
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>
于 2013-01-23T22:00:52.670 に答える