0
votes

I created a Phonegap application that uses an AUDIO element. It works perfectly on the browser.

If I install it as an app, the audio does not play anymore.

Using the Chrome DevTools I was debugging the app. I inspected the audio element and its source is something like file:///android_asset/www/path/to/my.mp3. If I changed to http://whatever.com/path/to/an.mp3 it works.

If I change it to file:///android_asset/www/path/to/unexisting.mp3 I got the error in the console:

GET file:///android_asset/www/path/to/unexisting.mp3 net::ERR_FILE_NOT_FOUND Uncaught (in promise) DOMException: Failed to load because no supported source was found.

With file:///android_asset/www/path/to/my.mp3 I wasn't getting any error in the console, simply I couldn't hear any sound.

In my config.xml I have

...
<gap:plugin name="org.apache.cordova.media" />
...
<feature name="Media">
    <param name="android-package" value="org.apache.cordova.media.AudioHandler" />
</feature>
<feature name="http://api.phonegap.com/1.0/file"/>
<feature name="http://api.phonegap.com/1.0/media"/>
...

and I did run phonegap plugin add org.apache.cordova.media.

I'm not using the Media class, but rather something like

<audio id="a" src="..."/>
<button onclick="document.getElementById('a').play()">Play</button>

I disconnected the phone from my laptop, but it still doesn't work.

I'm using phonegap 6.0.1.

What am I missing?

Later update:

I checked the Network tab from Chrome DevTools and I can see this

  • Request
    • URL:file:///android_asset/www/path/to/my.mp3
    • Request Method:GET
    • Status Code:200 OK (from cache)
  • Response Headers
    • Client-Via:shouldInterceptRequest
    • Content-Length:2
    • Content-Type:audio/mpeg
  • Request Headers Provisional headers are shown
    • Range:bytes=0-1
    • User-Agent:Mozilla/5.0 ...
1
i know its too late.. Did you find answer? you can check this out stackoverflow.com/questions/37101050/… - Raju Shetty
That's not the same. The files referred in that question/answer are stored in the phone storage or sdcard. Mine are embedded in the application. - Adrian Ber
But I found an answer. - Adrian Ber

1 Answers

0
votes

Instead of

<audio src="/path/to/my.mp3"/>

I used

<audio src="/android_asset/www/path/to/my.mp3"/>

and it worked.