+ 1

Hack: This is how You could bypass only usergenerated actions can play audio and how to use JavaScript to play audio anytime

Well I Finished My timer app Check it out first!! https://code.sololearn.com/W6P4Qw5RWe0j/?ref=app I had a situation like this that Once timer ends i wanted to play an audio i tried to do it with audio objects(play()) It gave me an alert saying Not allowed only usergenerated events can trigger to play Like only a button click can Actually play an audio Solution:In any button u have just give audioobj.play() and audioob.pause() and now as its initiated by a usercontrol,now u can do audioobj.play() anywhere

13th Nov 2017, 5:00 AM
MohanPierce
MohanPierce - avatar
3 ответов
+ 3
Note, it's a security feature, in the 'availability' (or more accurately 'nuisance') arena. Often features are open until they start to be abused, then they get controls. The same thing happened to navigator.vibrate() -- user intervention required -- and alert() -- prevent this page from creating additional dialogs. The controls generally guide you back into the intended use, which I think you're describing here.
17th Nov 2017, 2:12 PM
Kirk Schafer
Kirk Schafer - avatar
+ 2
In my case i had a button that started my timer,i initiated and paused my audioobj now as its initiated i used it in another function that executes and plays the audio Once timer is finished!!,Now i didnt get the usergenerated error even though no usercontrol was invloved at the end of audio play
13th Nov 2017, 5:03 AM
MohanPierce
MohanPierce - avatar
+ 2
yeah Lol Tat security feature is annoying when u want to make an alarm app or Timer app
17th Nov 2017, 2:15 PM
MohanPierce
MohanPierce - avatar