I am deploying on Android 4.4 with v19 of the Android SDK on phonegap. I have an mp3 file in the same folder as my index.html file that I want to play using html5 audio tags.
<html>
<body>
<audio controls>
<source src='sound.mp3' type='audio/mpeg'>
</audio>
</body>
<script type="text/javascript" src="cordova.js"></script>
</html>
It doesn't work and fails with the following:
I/AwesomePlayer( 124): setDataSource_l(URL suppressed)
E/ ( 124): Failed to open file '/android_asset/www/sound.mp3'. (No such file or directory)
It looks like a path issue, but I've tried all permutations I can think of. I think it is more fundamental, like AwesomePlayer can't access mp3s that are stored in the android_asset directory.
Using the Media plugin for phonegap works fine as other answers have suggested, but since audio tags work for external media, and the Media plugin works for internal media, it seems like this should be easily fixable. I also have a huge working app that uses audio tags everywhere and I really don't want to rewrite it to use the Media plugin. Is there an easy obvious fix, or should I submit a bug report?
The HTML <audio> element is used to play an audio file on a web page.
Currently, there are 3 supported “audio formats” for the HTML5 “audio” tag: . mp3, . ogg, and . wav.
Let me summarize what I found from various questions/answers on the similar topic:
playing local files from SD cards works on Android:
<audio controls="controls">
<source src="file:///sdcard/test.mp3" type="audio/mpeg"/>
</audio>
your current implementation using Media object is the only option if your would like to play files from Android device at the moment.
Links to explore:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With