Julian Guy
Julian Guy

Reputation: 11

Soundcloud SC.Stream can't access Soundmanager events

I'm using the Soundcloud Javascript SDK (http://developers.soundcloud.com/docs/api/sdks#javascript) on a project and have happily got my player loading a sound and playing it like so:

SC.get("/resolve/",{
    url: href
},function(response){               
   SC.stream("/tracks/"+response.id,{},function(sound){
        sound.play();

   });
}) 

I can trigger the soundmanager object to play in the callback using sound.play() but I can't work out how to access the events of the object mantioned in the docs (http://www.schillmania.com/projects/soundmanager2/doc/) like whileplaying()

How do I add these in? I've tried this kind of thing:

sound.whileplaying(function(){
   alert("hooray!")
})

But that doesn't work.

Many thanks Julian

Upvotes: 1

Views: 675

Answers (2)

Guilherme Nunes
Guilherme Nunes

Reputation: 11

The correct way is:

SC.stream('/tracks/' + response.id).then(function (player) {
    player.on('finish', function () {
        console.log('finish');
    });
    player.play();
});

You found this answer and consult all events here: https://developers.soundcloud.com/docs/api/sdks#player

Upvotes: 0

hwsw
hwsw

Reputation: 2606

This should work:

SC.stream("/tracks/" + response.id, {
  whileplaying: function () {
    console.log("track is playing");
  }
}, function (sound) {
  sound.play();
});

Upvotes: 3

Related Questions