【问题标题】:Play SoundCloud links through Soundmanager2通过 Soundmanager2 播放 SoundCloud 链接
【发布时间】:2013-01-23 04:06:32
【问题描述】:

我在我的网站上使用 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')});");
            });
    }); 

【问题讨论】:

  • SoundManager 论坛上的一些主题可能会对您有所帮助:getsatisfaction.com/schillmania/…
  • 也试过了。在这里疯了哈哈。链接到托管 mp3 但不是 soundcloud 链接时播放完美

标签: soundcloud soundmanager2


【解决方案1】:

这也让我发疯了。经过一堆挖掘,如果我在链接中指定了 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>

【讨论】:

    【解决方案2】:

    您也可以尝试使用 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();
    });
    

    【讨论】:

    • 感谢您的回复。我已经添加了上面的脚本,但似乎仍然无法让它工作。有没有我应该添加到锚点的课程? soundcloud.com...>Track标题
    【解决方案3】:

    我试过了,我以为我有它......有人看到什么了吗?

     <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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多