I have tried using:
createjs.Sound.pause;
mySound.stop();
Nothing works. Right now it have a stop button but if the stop button is pressed then the sound would not be played again.
This is the soundjs that im using. soundjs
My code is exactly the same with the source code of it. Thanks for any help!
I end up doing it like this Based on Stephen Lightcap answer:
Javascript inside the head tag:
function load() {
// Update the UI
document.getElementById("display").innerText = ".";
// Load the sound
createjs.Sound.alternateExtensions = ["mp3"];
createjs.Sound.addEventListener("fileload", handleFileLoad);
createjs.Sound.registerSound({id:"mySound", src:"../../test.mp3"});
}
function handleFileLoad(event) {
// Update the UI
document.getElementById("display").innerHTML = ".";
document.getElementById("stopBtn").disabled = "";
// Play the loaded sound
createjs.Sound.play(event.src,{loop:2});
}
var instance = createjs.Sound.play(event.src);
</script>
Button inside the body tag:
<input id="pausBtn" type="button" value="Pause" onclick="pause()"/>
Javascript for the button onclick. Placed below the button. :
<script>
function pause(){
instance.pause();
}
</script>
But I got an error saying :
Uncaught TypeError: Cannot read property 'pause' of undefined at pause (phkk.html:560) at HTMLInputElement.onclick (phkk.html:177)