how can we play audio on mobile broswer is playing on desktop browser but not playing on mobile what is the solution for the particular problem.. code is var audio=new Audio('sound.mp4') audio.play()
Asked
Active
Viewed 459 times
-1
-
You need to review the accepted codec in your device and according to this call the respective file. Look at [here](https://developer.android.com/guide/topics/media/media-formats.html) to see the accepted codecs in android and [here](https://stackoverflow.com/questions/3069124/playing-html5-audio-in-android-browser) there are some possible workarounds. – Arnold Gandarillas Mar 31 '18 at 11:25
1 Answers
1
Mobile Safari, and probably others, only allow audio to play in response to a user action. So element.addEventListener( 'click', () => audio.play() )
will work, but the autoplay
attribute or document.addEventListener('DOMContentLoaded', () => audio.play() )
won't.

Ben West
- 4,398
- 1
- 16
- 16
-
jQuery(function(){ /// audio.play(); jQuery('#playFancy').click(); }); document.getElementById('playFancy').addEventListener( 'click', () => audio.play() ) that is my code but its still not working on mobile browser – waleed babar Mar 31 '18 at 11:59
-
-
i cant have a real action i am generating a click event of a button through jquery and want audio to play through that event – waleed babar Mar 31 '18 at 12:14
-