How do I get the audio to stop after x number of time
how do i get the the audio to stop after a 7 sec
12 Replies
you have to keep the
audio
variable in the main scope, and then call audio.stop()
in the timeout callbackI think it's audio.pause() though, not sure audio.stop() exists in the API
Audio. Stop is not working
Tried with pause() ?
Kirin is right, it's
audio.pause()
if that doesn't work, paste your code in a code block (not a screenshot please), and we can take another look 🙂Ok am going to try with pause
//
let audio = new Audio("bell.mp3")
//
if (minutes == 5 && seconds == 0) {
document.querySelector("#hiddenmessage")?.classList.add("show")
playmusic()
setTimeout(
() =>
document.querySelector("#hiddenmessage")?.classList.remove("show"), 7000 )
document.querySelector("#hiddenmessage")?.classList.remove("show"), 7000 )
if you start that with ```js and end it with ```, it'll format properly and add syntax highlighting
where is playmusic defined?
xd giv me a sec did copy that
replace your setTimeout with that
@jochemm is not working but thanks anyways I think I need some rest
@jochemm is working now but I don't understand why is working xd I ended up using || and is working