Answer the question
In order to leave comments, you need to log in
Why is audio not playing in mobile browsers?
Good afternoon!
I'm making a website that plays audio when a button is clicked. I create a new audio (let audio = new Audio(src)), then when I click on the button, I launch it (audio.play()). On the computer, everything works fine (including on the mobile device emulator), but in the mobile browser (Chrome) there is no sound (although the button is definitely pressed, because when pressed, it changes color). I thought that a possible problem is that there are not enough codecs, but if placed with controls, then when you click on the play, the sound goes. Do not tell me how to solve this problem?
Answer the question
In order to leave comments, you need to log in
It turns out that <audio> is poorly supported by mobile browsers, but the Web Audio API is supported with a bang. With his help everything was done.
Try saving the audio in multiple formats and placing the audio element itself in the DOM:
<audio>
<source src="file.mp3" type="audio/mpeg">
<source src="file.ogg" type="audio/ogg">
</audio>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question