Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML 5 audio tag issues (no sound) with phonegap on android 4.x

Tags:

html

cordova

Platform: Android version 4.x

Issue: HTML 5 Audio Tag

Compiled: Framework Phonegap

I have been trying to play a simple sound with HTML 5, i cant get it to work.

I read that there is a general "not supporting" thing going on with Android, but as i understand it, version 4.x supports HTML 5 Audio tag.

Config.xml I did enable some of the features in it eg. File access, device access and so, i even tried to include all features. Just to let u guys know.

HTML This is what i am working with atm, i figured that maybe i should go back to directly try and get a sound out, then make the costum controls with JQ.

<audio controls="true">
    <source src="media/sound.mp3" type="audio/mpeg">
    <source src="media/sound.ogg"  type="audio/ogg">
    <source src="media/sound.wav"  type="audio/wav">
    Your browser does not support HTML5 audio.
</audio>  

Conclusion So far i havent hear any sounds, i tried to trigger it different ways like:

var Newsound = new Audio("sound.ogg");
Newsound.play();    

Any idea or suggestion is welcome.

Thanks in advance :-)

like image 436
Daniel Avatar asked Nov 12 '22 08:11

Daniel


1 Answers

You generally need a piece of JavaScript to get this working. Try the following:

<audio id="a" controls="true">...

var audio = document.getElementById('a');
audio.addEventListener('touchstart', function() { audio.play(); }, false);

When a user touches the audio element the sound should now play.

like image 170
Ian Devlin Avatar answered Nov 15 '22 00:11

Ian Devlin