-1

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()

  • 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 Answers1

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