I have looked all over but nothing so far. I'm stuck.
I have an html audio element and I want to control it with a div. When I click on the div it plays the music, but what I need is when I click on it again to stop playing but don't know how.
This is audio tag.
<audio class="audioplayer" preload="none" style="display: none;" >
<source src="audio/ocean.mp3" type="audio/mpeg">
</audio>
And this is jquery controlling the play with the div (#ocean).
$('#ocean').click(function() {
if ('.audioDemo'.paused == false) {
$(".audioDemo").trigger('pause');
} else {
$(".audioDemo").trigger('play');
}
});
function stopAudio(){
$(".audioDemo").trigger('pause'); //pause playing
$(".audioDemo").prop("currentTime",0); //set play time to 0
}
I have wrote stop function and it works but only if I hock it up on another div. I have tried with that .paused but its not working.
How can I use same div as play and stop?
THX