Description:
Stop sound and play again.
Result:
Stop sound when click the stop 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) {
                    // stop
                    document.getElementById('btn').innerHTML = 'Play';
                    source.sound.stop();
                } else {
                    // play
                    document.getElementById('btn').innerHTML = 'Stop';
                    source.sound.play();
                }
                playing = !playing;
            }