Soundcloud APIのストリーム終了イベントの正しい使い方を教えてください。 URLを解決してストリームを開始し、曲の終了を検出できますが、最初の曲が終了した後、次のストリームが最初のストリームオブジェクトに追加されます。私の例で最初の曲が演奏された後、stopをクリックすると、以前のストリームについてもconsole.log( "Stop Clicked:" Stream.ID)が起動します。Soundcloud API on finishイベントの使用方法
ストリームで新しいストリームを開始するのではなく、新しい曲を開始するようにトラック機能から復帰するにはどうすればよいですか?
Link to a Codepen of the below code
SC.initialize({
client_id: '72e56a72d70b611ec8bcab7b2faf1015'
});
$(document).ready(function() {
var urlid = ["https://soundcloud.com/sheckylovejoy/sad-trombone", "https://soundcloud.com/xcollective/x002"];
$.get(
'https://api.soundcloud.com/resolve.json?url=' + urlid[0] + '&client_id=72e56a72d70b611ec8bcab7b2faf1015',
function (result) {
$(document).trigger('Rotation/currentTrack', result);
return result;
});
$(document).on('Track/finish', function(result){
$.get(
'https://api.soundcloud.com/resolve.json?url=' + urlid[1] + '&client_id=72e56a72d70b611ec8bcab7b2faf1015',
function (result) {
$(document).trigger('Rotation/currentTrack', result);
console.log("Song 2 " + result.id);
return result;
});
});
});
$(document).on('Rotation/currentTrack', function(e, results){
console.log("results " + results.id + " " + results.title);
track(e, results.id);
});
function track(e, trackNum){
SC.stream('/tracks/' + trackNum).then(function(sound) {
sound.play();
$('#start').click(function(e) {
e.preventDefault();
console.log("START Clicked")
sound.play();
sound.on('finish', function(){
console.log("The track finished");
$(document).trigger('Track/finish', sound);
});
});
$('#stop').click(function(e) {
e.preventDefault();
console.log("Stop clicked: " + trackNum)
sound.pause();
});
$('#skip').click(function(e){
e.preventDefault();
sound.seek(170000);
});
})
}