+ 3
Promise error audio.play()
6 Réponses
+ 3
You can't just play it automatically ,it needs some user gesture like some click event then you can trigger the audio with play method
+ 2
Abhay i used in onended event to play next song automatically
+ 2
Abhay any method to clear console error
All working perfectly
+ 2
ŚĄŃ use try catch statements ,put the code that is causing err into try and in catch block output nothing like
const a=5;
try{
a=4;
}catch(err){
}
+ 1
ŚĄŃ I also used onended event to play audio and works fine ,
<audio src="audio" controls />
<script>
var audio=document.querySelector("audio");
audio.onended=()=>{
console.log("thks for playing");
audio.play();
}
</script>
Sorry but I can't really go through your code and figure what is causing that error without some more info or maybe you can figure it out yourself and provide more info on the root of problem
+ 1
Your code produces 26 Uncaught(in promise) NotAllowedErrors, with a message that says
"play() can only be initiated by a user gesture." Line 1027
Line 1027 - document.getElementById("audio").play();
This line is part of the method entouchset().
The method entouchset() is invoked (before the user initiates any gesture ) 26 times in total by codeblocks from 3 different for/loops, at lines 1017, 1019, 1021.
Other than causing the Uncaught errors, what purpose do the for/loops serve?