19th Aug 2020, 9:33 AM
SAN
SAN - avatar
6 Respostas
+ 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
19th Aug 2020, 9:54 AM
Abhay
Abhay - avatar
+ 2
Abhay i used in onended event to play next song automatically
19th Aug 2020, 9:59 AM
SAN
SAN - avatar
+ 2
Abhay any method to clear console error All working perfectly
19th Aug 2020, 2:26 PM
SAN
SAN - avatar
+ 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){ }
19th Aug 2020, 3:26 PM
Abhay
Abhay - avatar
+ 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
19th Aug 2020, 2:16 PM
Abhay
Abhay - avatar
+ 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?
20th Aug 2020, 11:33 PM
ODLNT
ODLNT - avatar