'Play() can only be initiated by a user gesture' workaround | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 6

'Play() can only be initiated by a user gesture' workaround

I get this exception on Android devices when I try to play audio via JavaScript - 'play() can only be initiated by a user gesture' Do you guys know any workaround or alternative? Thanks.

14th Sep 2018, 6:28 AM
Moses Odhiambo
Moses Odhiambo - avatar
6 Answers
+ 5
Janningā­ That happened when I tried to use play() without any event handlers. I wanted the music to play automatically, but now, it only plays when the user clicks the "up/down/--->/<---" labels. I guess it's no longer a big deal.
15th Sep 2018, 8:12 AM
Moses Odhiambo
Moses Odhiambo - avatar
+ 5
Janningā­ works on PC but not on Android. I've learned that Google only allows play() on Android when it's used along with DOM events.
15th Sep 2018, 8:31 AM
Moses Odhiambo
Moses Odhiambo - avatar
+ 3
If you're talking about the background music in this code: https://code.sololearn.com/Wis4OmrSYmM9/?ref=app I can only tell you that I can't reproduce the error you're referring to. It works fine on my device.
15th Sep 2018, 8:03 AM
Janningā­
Janningā­ - avatar
24th Jul 2020, 11:11 AM
Raj Srivastava
Raj Srivastava - avatar
+ 2
15th Sep 2018, 8:20 AM
Janningā­
Janningā­ - avatar
+ 2
šŸ¤” Fascinating...
15th Sep 2018, 8:37 AM
Janningā­
Janningā­ - avatar