+ 3

audio.play() using JS

audio.play() using JS is not working on Sololearn Mobile APP but working on browser , how can I fix it😬? https://code.sololearn.com/WUW0CEKydXzI/?ref=app

17th Jul 2021, 6:58 PM
Amit Maindola
Amit Maindola - avatar
2 odpowiedzi
+ 2
You can't , most browsers don't allow audio to play on it's own you need some user gesture to play the audio . Like have a onclick event handler function on window and play the audio inside it. When user click anywhere on window , it will play it. Also there is a howler js library that i have heard can help in playing it without user interaction.
17th Jul 2021, 8:29 PM
Abhay
Abhay - avatar
+ 1
You have to use user event like click, dblclick, .... to initiate audio.play() action.
18th Jul 2021, 2:39 AM
Divya Mohan
Divya Mohan - avatar