1
votes

Does phonegap support the html5 audio tag to play native mp3 file??

I want to develop an application using phonegap and play mp3 files on it. It works when an online source is given in audio tag, like below

<audio> <!--works this way!!!--> 
<source src="http://www.alexkatz.me/codepen/music/interlude.mp3">
</audio>

but when I tried it with resident mp3 file in music folder, it didnt work. Like the snippet below

<audio><!--does not work this way :(--> 
<source src="music/interlude.mp3">
</audio>

I also tried the following approaches to link the file in different assets directories, but it did not work

<audio><!--does not work this way:(--> 
<source src="android_asset/www/music/interlude.mp3">
</audio>

<audio><!--does not work this way :(-->
<source src="/android_asset/www/music/interlude.mp3">
</audio>

 <audio><!--does not work this way :(-->
<source src="file:///android_asset/www/music/interlude.mp3">
</audio>

Then I tried the "phonegap media API" to make it work, but "phonegap media API" doesn't have progress bar and seek bar, so I would like to ask any idea to play the native audio file in phonegap. THANKS

1

1 Answers

0
votes

Given a FileEntry object, using nativeURL works fine for me. I do something like this:

<audio id='sound'></audio>

And from javascript:

var sound = $$("#sound");
sound.attr('src', myFileEntry.nativeURL);
sound[0].play();

Where myFileEntry is a variable containing a FileEntry object pointing to the audio file.