Description:
Pause sound and play again.
Result:
Pause sound when click the pause button. Play sound when click the play button.
Code:
var source = null; var playing = false; function onload() { var engine = new jWebAudio.SoundEngine(); source = engine.addSoundSource({ 'url': '../../examples/resource/a.ogg', 'preLoad': true, 'callback': function() { source.sound.play(); playing = true; document.getElementById('btn').disabled = false; } }); } function play() { if (playing) { // pause document.getElementById('btn').innerHTML = 'Play'; source.sound.pause(); } else { // play document.getElementById('btn').innerHTML = 'Pause'; source.sound.play(); } playing = !playing; }