2015-02-07 32 views
0

你們能幫我解決嗎? : 我想從我的SoundCloud軌道做個列表和播放任何曲目,當我使用JavaScript點擊它,但它不與我工作:(使用JavaScript進行stream soundcloud跟蹤不起作用

HTML文件

<script src="//connect.soundcloud.com/sdk.js"></script> 
<body> 
    <ol id="track-list"></ol> 
</body> 

js文件:

function PlayIt(ID){ 
    SC.stream("/tracks"+ID, function(sound){ 
    soundManager.stopAll(); 
    sound.play(); 
    }); 

} 



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

/** 
Once that's done you are all set and ready to call the SoundCloud API. 
**/ 



/** 
Call to the SoundCloud API. 
Retrieves list of tracks, and displays a list with links to the tracks showing 'tracktitle' and 'track duration' 
**/ 

    var userId = 39090345; // user_id of Prutsonic 

    SC.get("/tracks", { 
     user_id: userId, 
     limit: 100 
    }, function (tracks) { 

     var tmp = ''; 

     for (var i = 0; i < tracks.length; i++) { 
     var TrackId=tracks[i].id; 
      tmp = '<a href="#" onclick="PlayIt('+TrackId +')">' + tracks[i].title + ' - ' + tracks[i].duration + '</a>'; 

      $("<li/>").html(tmp).appendTo("#track-list"); 
     } 

    }); 

您也可以點擊此處查看: http://jsfiddle.net/26pHX/96/

*這不是我的代碼,但我儘量做到更好

回答

0

那麼它看起來像你需要在你的代碼中的客戶端ID。您還需要重定向網址。我不確定那會有什麼期望,但現在我會嘗試給它一個隨機頁面,因爲它們的示例頁面似乎沒有任何特殊之處。

0

我發現這個部分是問題:

的onclick =「PlayIt( '+的TrackID +')

相反,我使用使用document.createElement製成標籤( 'a')的然後我使用(元素).setAttribute('the_attribute','the_value')設置其屬性;並且一切正常。