S
S
Stanislav_Bykov2017-09-19 11:23:57
JavaScript
Stanislav_Bykov, 2017-09-19 11:23:57

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

3 answer(s)
S
Stanislav_Bykov, 2017-09-25
@Stanislav_Bykov

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.

A
Alexander, 2017-09-19
@kentuck1213

85a4f22529eb4d10b9da9f6b523644bd.png

M
monochromer, 2017-09-19
@monochromer

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 question

Ask a Question

731 491 924 answers to any question