Como posso passar automaticamente para o próximo som após a conclusão da faixa anterior usando o Soundcloud Javascript SDK para streaming?

Sou novo no Javascript e no SDK do Soundcloud, por isso, se a minha solução atual estiver longe, por favor, deixe-me saber como ela pode ser melhorada.

Eu estou construindo um player Soundcloud personalizado e não usando um widget pré-construído. Eu estou olhando paraautomaticamente mova para a próxima faixa depois que a faixa terminar de tocar. Eu quero ser capaz de fazer isso sem usar uma playlist do Soundcloud. Em vez disso, estarei puxando uma lista JSON de faixas para tocar.

Sou capaz de reproduzir, pausar, parar e pular faixas clicando em links, mas não tenho certeza de como saber quando uma faixa foi concluída para ativar onextTrack função. Alguma sugestão?

API do Soundcloud Javascript SDK Streaming:http://developers.soundcloud.com/docs/api/sdks#streaming

Aqui está o meu código:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<script src="http://connect.soundcloud.com/sdk.js"></script>

<div class="music-player">
    <h4 class="trackTitle">Current track</h4>
    <a href="#" id="play">Play</a>
    <a href="#" id="pause" style="display:none;">Pause</a>
    <a href="#" id="stop">Stop</a>
    <a href="#" id="next">Next</a>
</div>

<script>

    Track = function (trackId){
        var currentTrack = "";

        SC.initialize({
            client_id: "CLIENT_ID"
        });

        SC.stream("http://api.soundcloud.com/tracks/" + trackId, function(sound){
            currentTrack = sound;
        });

        this.play = function() {
            currentTrack.play();
        };

        this.pause = function() {
            currentTrack.pause();
        };

        this.stop = function() {
            currentTrack.stop();
        };
    };

    Rotation = function(tracks) {
        var currentTrack = tracks[0];

        this.currentTrack = function () {
            return currentTrack;
        };

        this.nextTrack = function () {
            var currentIndex = tracks.indexOf(currentTrack);
            var nextTrackIndex = currentIndex + 1;
            var nextTrackId = tracks[nextTrackIndex];
            currentTrack = nextTrackId;
            return currentTrack
        };
    };

    $(document).ready (function(){
        var songs = [{"title":"Sad Trombone","song_url":"https://soundcloud.com/sheckylovejoy/sad-    trombone","soundcloud_id":"18321000"},{"title":"AraabMUZIK - \"Beauty\"","song_url":"    https://soundcloud.com/selftitledmag/araabmuzik-beauty","soundcloud_id":"79408289"}]
        var rotation = new Rotation(songs);
        var currentTrack = rotation.currentTrack();
        var currentPlayingTrack = new Track(currentTrack.soundcloud_id);

        $('#play').on('click', function(event){
            currentPlayingTrack.play();
            $('.trackTitle').html(currentTrack.title);
            $('#pause').show();
            $('#play').hide();
        });

        $('#pause').on('click', function(event){
            currentPlayingTrack.pause();
            $('#pause').hide();
            $('#play').show();
        });

        $('#stop').on('click', function(event){
            currentPlayingTrack.stop();
            $('#pause').hide();
            $('#play').show();
        });

        $('#next').on('click', function(event){
            currentPlayingTrack.stop();
            currentTrack = rotation.nextTrack();
            currentPlayingTrack = new Track(currentTrack.soundcloud_id);
            currentPlayingTrack.play();
            $('.trackTitle').html(currentTrack.title);
        });

    });

</script>

questionAnswers(1)

yourAnswerToTheQuestion