0

I want to play an mp3 sound, when an event occurs and I am using the following piece of code:

var audio = new Audio('coins.mp3');
audio.play();

It works great under windows in Chrome, however if I open it on my 4.4 Android, it is muted. I tested on another android version (2.3, not Chrome) and it was working. It seems it is also working if I call the code from an onClick event on 4.4 Android.

Can anyone please explain this behaviour for me, as I can not find the answer after some hours of googling. :(

Thanks in advance!

Sandor Farkas
  • 153
  • 2
  • 11

1 Answers1

0

Here is link to Google Android bug, which filed for lack of support of AUDIO tag in Android.

https://code.google.com/p/android/issues/detail?id=10546

Hope this will help and One more thing is

HTML5 Audio support is not consistent across different devices/OSes due to codec licensing issues and OS implementation/support. If you are just playing MP3 files, you can reliably handle those by using PhoneGap's Media class, which will provide consistent and reliable audio programming on all platforms.

  • I created the following element in html: And added the following js: var video = document.getElementById("video"); video.play(); Desktop chrome plays the sound, but the android doesn't. :( – Sandor Farkas Oct 31 '14 at 13:41
  • Works on: Samsung Galaxy Mini 2 - Adndroid 2.3.6 - Factory ROM - Manifacturers browser, no chrome available Not working on: Samsung Galaxy S - Android 4.4.4 - Cyanogenmod 11 - chrome, cyanogen default browser Toshiba Excite at10-a-104 - Android 4.2.1 - Factory ROM - chrome, toshiba default browser I guess that it is android version issue as i get the same result in different browsers – Sandor Farkas Oct 31 '14 at 17:22
  • hey check the edited answer and may be it will help you. – Hardik Sheth Oct 31 '14 at 17:25
  • OK, it seems there are numerous frameworks which promise to provide universal solution (eg: audio.js), but I couldn't get any of these work. The problem is that it plays the sound in case on onclick event, but I cannot call a function from js that can do the same. However it was working with FF for android. Anyway I needed it for another app as an alarm for a short term, and now it is not an issue for me anymore. Thank you Hardik for your assistance! – Sandor Farkas Nov 02 '14 at 18:47