0

I am developing a webpage which plays audio after pressing a button. This works well in Chrome and Firefox. However in Opera mobile, instead of playing the audio it opens up a prompt which asks us to either download, play or cancel the audio. This destroys the flow of my webpage.

How can I prevent that prompt from appearing and just play the audio?

<audio id='snd_c'>
  <source src="cor.ogg" type="audio/ogg">
</audio>
<audio id='snd_w'>
  <source src="wrong.ogg" type="audio/ogg">
</audio>
<audio id='snd_s'>
  <source src="skip.ogg" type="audio/ogg">
</audio>
$("#snd_c")[0].play();
$("#snd_w")[0].play();
$("#snd_s")[0].play();
Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
Abhijith
  • 7
  • 1
  • This sounds like a browser settings issue. I cannot replicate using default settings in Opera 63, the audio here plays on click without asking for permission http://jsfiddle.net/dsuket/jTh3v/. – Rory McCrossan Sep 12 '19 at 08:12
  • I forgot to mention that The problem was in Opera Mobile browser. @RoryMcCrossan: The code you mentioned above work without any problem in Opera. But I cannot solve my issue. I was using JQuery to play the audio. Is that make the problem? – Abhijith Sep 12 '19 at 08:23
  • Opera mobile is an important distinction. This is almost certainly browser behaviour which you can do nothing about. `I was using JQuery to play the audio. Is that make the problem?` No not at all. The problem is how the browser deals with audio content, not how you play the file. – Rory McCrossan Sep 12 '19 at 08:26
  • @RoryMcCrossan But your code runs without any problem. Not prompting to download – Abhijith Sep 12 '19 at 08:29
  • The code in the fiddle works on Opera mobile? – Rory McCrossan Sep 12 '19 at 08:31
  • Yes. The only difference is that you use javascript directly and I used JQuery instead to play audio – Abhijith Sep 12 '19 at 08:34
  • You don't use jQuery to play the audio. You use jQuery to select the element. Then you use JS to make it play. If you'd like to discount jQuery as the problem check this: http://jsfiddle.net/RoryMcCrossan/8okamfwu/ – Rory McCrossan Sep 12 '19 at 08:37
  • @RoryMcCrossan Yes. It plays without any issue.But when I copied your code to my html file and Opened in Opera the issue is there. But running it via jsfiddle doesn't make the issue – Abhijith Sep 12 '19 at 08:45
  • Does the file play if you click 'play' in the popup? – Rory McCrossan Sep 12 '19 at 08:46
  • Yes it plays. But pressing play each time is boring – Abhijith Sep 12 '19 at 08:53
  • In that case the issue could be that you're trying to play the file without user interaction, which is restricted in some browsers – Rory McCrossan Sep 12 '19 at 08:56
  • @RoryMcCrossan: okay – Abhijith Sep 12 '19 at 09:03

0 Answers0