Soundcloud Javascript SDK sound not pausing -


using soundcloud javascript sdk have been able grab tracks , play them. goal allow playing , pausing via clicking on 1 button (like play/pause toggle). however, issue when click on .scbtn element, song plays, , doesn't stop. conditionals seem correct because can see true , false making console. not quite sure why sc.sound.pause(); isn't working.

var is_playing = false; var trackcont = function(tracknum){ sc.stream("/tracks/" + tracknum).then(function(sound){     sc.sound = sound;     if (is_playing === false){         sc.sound.play();         is_playing = true;         console.log(is_playing);     }else if(is_playing === true){         sc.sound.pause();         is_playing = false;         console.log(is_playing);     }     }); } $('body').on("click", ".scbtn", function(){     var thetrack = $(this).attr('id');     trackcont(thetrack); }); 

update

my fiddle

i think you're overcomplicating things. here's simple example:

html:

<script src="https://connect.soundcloud.com/sdk/sdk-3.0.0.js"></script> <button id="play">play</button> 

javascript:

sc.initialize({   client_id: 'xxxx' });  var myplayer; var ispaused = false; sc.stream('tracks/43377447').then(function(player){             player.play()             myplayer = player;         });  document.queryselector('button').addeventlistener('click', function() {     if (ispaused) {         myplayer.play()         ispaused = false;     } else {         myplayer.pause()         ispaused = true;     } }); 

working jsfiddle.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -