Search code examples
javascriptsoundcloudsoundmanager2

Soundcloud: preparing multiple tracks for streaming?


After Soundcloud: Cannot set property 'id' of undefined when trying to play the song was resolved (thanks again) I'm going to do the next - I want to prepare multiple SM2 instances for playing multiple tracks on demand.

Here's the code (non-compiled CoffeeScript for readability this time, the whole jsbin can be seen here http://jsbin.com/ejapin/edit#javascript,html)

$ ->
    SOUNDCLOUD_ID = '6d5064768cc29c71e1f66691f435589a'
    PLAYLIST_ID = '1768866'
    SC.initialize client_id: SOUNDCLOUD_ID

    tracks = []
    tracks_total = 0

    tracks_ready = ->
        for track in tracks
          console.log track
          track.play()

    SC.get '/playlists/' + PLAYLIST_ID, (pl) ->
        tracks_total = pl.tracks.length
        for track in pl.tracks
            console.log "Fetching"
            SC.stream "/tracks/#{track.id}", {}, (sound) ->
                tracks.push sound
                console.log "+ Fetched #{tracks.length}"
                if tracks.length == tracks_total
                    tracks_ready()

I see Fetching logged 11 times and I also see SM2's swf to be requested the same number of times.

But the callback is called for the (updated) LAST track only (yet the sound is playing OK for it).

UPD: btw, it also inserts the SM2 js multiple times which looks like an issue


Solution

  • There was a bug in the SC JS SDK causing this. We've deployed a fix today that should fix this. Thanks for reporting this! Please let me know if there are still issues.