0
votes

I'm developing app to play soundcloud traks. I'm using ttwmusicplayer and want to bind soundcloud actions on it's play/pause. So, I'm doing it like this:

$("#mainPlayer .jp-play")
        .off("click")
        .on("click", function(){
            $("#mainPlayer .jp-play").css('display','none');
            $("#mainPlayer .jp-pause").css('display','block');
            SC.stream('/tracks/208818225', function(sound){
                sound.play();
            });
        });
$("#mainPlayer .jp-pause")
    .off("click")
    .on("click", function(){
            alert('IT WORKS');
            $("#mainPlayer .jp-play").css('display','block');
            $("#mainPlayer .jp-pause").css('display','none');
            SC.stream('/tracks/208818225', function(sound){
                sound.stop();
            });
        });

It plays track fine,but when I click pause button, I receive alert, so I can understand that this works. Also pause changes itself on play, but music still playing, however I found this methond in docs How can I pause/stop soundcloud tracks then?

2

2 Answers

2
votes

I think there should be one sound object

     var mysound; 
     SC.stream('/tracks/208818225', function(sound){
          mysound = sound;
          mysound.play();
     });

and to stop sound no need to use SC.stream instead just use the sound object. like:

    mysound.stop() //or mysound.pause()
0
votes

To pause:

mysound.pause();

To stop:

mysound.pause();
mysound.seek(0);

I couldn't find any stop() methods in the documentation, so I think you have to pause() first, then seek() to the beginning to "stop" the sound. https://developers.soundcloud.com/docs/api/sdks#javascript