document.getElementById('s/' + currentRadio + '/' + currentSong).pause();
This is currently not pausing the audio while this works fine playing it
document.getElementById('s/' + currentRadio + '/' + currentSong).play();
If I manually enter on the js console the pause code the audio will stop... so no idea whats goin on.
If I try this
console.log(document.getElementById('s/' + currentRadio + '/' + currentSong));
I will get the div so everything seems okey.
<audio class="playSong" id="s/0/0" src="/music/Playback FM/Big Daddy Kane - Warm It Up, Kane.mp3"></audio>
The audio tag are inside
<div class="radioAudio">
</div>
And the pause button is made like this
$('#tuneRadioPause').click(function(e) {
if(currentSong !== -1 && currentPlay) {
console.log("s/" + currentRadio + "/" + currentSong)
document.getElementById('s/' + currentRadio + '/' + currentSong).pause();
currentPlay = false;
}
if(!currentPlay && currentSong !== -1) {
document.getElementById('s/' + currentRadio + '/' + currentSong).play();
currentPlay = true;
}
});
Updated
The problem is the conditional checks. Both
if
's are run regardless. This means that when the first condition is met (... && currentPlay
)currentPlay
is set tofalse
and audio is paused.Then when the second check is run right after independently (
!currentPlay && ...
),currentPlay
is alreadyfalse
so this condition is also met and thenplay()
is triggered right away making it appear as if pause didn't work.Solve by using an
else
statement like this:I would recommend using the actual status of the audio element to check though rather than unbound flags, for example: