Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,740,298 Members 42,862 Now Online
XDA Developers Android and Mobile Development Forum

[Q] Playing local audio file in webview app

Tip us?
 
jsterj
Old
#1  
Junior Member - OP
Thanks Meter 0
Posts: 4
Join Date: Feb 2012
Question [Q] Playing local audio file in webview app

When trying to play a local mp3 file included in the APK, nothing happens. However, if I pull an mp3 from the web it works.

e.g.

< a u d i o src="www[dot]example[dot]com/01.mp3" > WORKS

< a u d i o src="01.mp3" > DOES NOT WORK

I tried looking through logs for clues and found this line. I'm not sure if it's relevant or not.

PlayerDriver::isProtectedFile(file:///android_asset/www/01.mp3)

I'm new to Android development, so I can only guess that the file is somehow inaccessible for streaming.

I'd love to get this figured out though. Having to pull the files remotely every time is not a desirable solution.

Some additional info. Either solution works when tested in the browser. The local file problem only arises when I convert it to an app. I'm using PhoneGap build to create the APK.
 
jsterj
Old
#2  
Junior Member - OP
Thanks Meter 0
Posts: 4
Join Date: Feb 2012
Still tryin to figure this one out. I compared the logs between 2 versions of my app. One version that pulls the MP3 from the web at runtime, and the other that has the file stored locally. Just like before, the web version works and the local version does not.

I did find quite a few differences:

They both start off with the ANDROID_DRM_TEST. As far as I can tell, they both pass. It's a file of my own creation and has no protection on it.

That's the only similarity though, it's all different after that.

The local file version (the one that does NOT work) has log entries referring PVPLAYER and PLAYERDRIVER. They're color coded RED and YELLOW which I'm assuming refers to ERROR and WARNING.

The web file version (the one that DOES work) has entries referring to STAGEFRIGHTPLAYER and AWESOMEPLAYER. It then goes on with a few lines about OMXCodec which just appears to be allocating buffers.

So it looks to me like it's using a completely different player depending on where the file is being pulled from. Again, I'm an Android newbie, so I may be completely wrong.

I'm not sure if there's a way I can force it to use a particular player even when playing a local file.

Anyhow, that's where I'm at. Thought I'd post an update and see if that gives anyone else any ideas for a solution. I'll keep plugging away at it myself as well.
 
jsterj
Old
#3  
Junior Member - OP
Thanks Meter 0
Posts: 4
Join Date: Feb 2012
Still no luck, but here's the errors/warnings from my log file if that helps shed any light on the problem(s)

02-07 14:55:04.664 E/PlayerDriver(83): PlayerDriver::it is a not Protected file
02-07 14:55:04.687 E/OsclDirectFileIO(83): [LargeFileSupport] OsclDirectFileIO::eek:penFileOrSharedFd Error = -1
02-07 14:55:04.687 W/MediaPlayer(20628): info/warning (1, 26)
02-07 14:55:04.687 E/PlayerDriver(83): Command PLAYER_SET_DATA_SOURCE completed with an error or info -4
02-07 14:55:04.687 E/MediaPlayer(20628): error (-4, -4)
02-07 14:55:04.687 E/MediaPlayer(20628): Error (-4,-4)
02-07 14:55:04.687 E/PVPlayer(83): isDrmfile playing 0
02-07 14:55:04.687 W/PlayerDriver(83): PVMFInfoErrorHandlingComplete
02-07 14:55:04.691 E/PlayerDriver(83): PlayerDriver::handleTvOut state=[4]
02-07 14:55:04.691 E/PlayerDriver(83): PlayerDriver::it is not a DRM file.So don't resume TVOUT
02-07 14:55:04.703 E/PlayerDriver(83): PlayerDriver::it is a not Protected file
02-07 14:55:04.703 E/PlayerDriver(83): PlayerDriver::handleTvOut state=[4]
02-07 14:55:04.703 E/PlayerDriver(83): PlayerDriver::it is not a DRM file.So don't resume TVOUT
02-07 14:55:04.718 E/OsclDirectFileIO(83): [LargeFileSupport] OsclDirectFileIO::eek:penFileOrSharedFd Error = -1
02-07 14:55:04.718 W/MediaPlayer(20628): info/warning (1, 26)
02-07 14:55:04.718 E/PlayerDriver(83): Command PLAYER_SET_DATA_SOURCE completed with an error or info -4
02-07 14:55:04.718 E/MediaPlayer(20628): error (-4, -4)
02-07 14:55:04.718 E/MediaPlayer(20628): Error (-4,-4)
02-07 14:55:04.718 E/PVPlayer(83): isDrmfile playing 0
02-07 14:55:04.718 W/PlayerDriver(83): PVMFInfoErrorHandlingComplete
02-07 14:55:04.718 E/PlayerDriver(83): PlayerDriver::handleTvOut state=[4]
02-07 14:55:04.718 E/PlayerDriver(83): PlayerDriver::it is not a DRM file.So don't resume TVOUT
02-07 14:55:05.558 E/PlayerDriver(83): PlayerDriver::it is a not Protected file
02-07 14:55:05.558 E/OsclDirectFileIO(83): [LargeFileSupport] OsclDirectFileIO::eek:penFileOrSharedFd Error = -1
02-07 14:55:05.562 W/MediaPlayer(20628): info/warning (1, 26)
02-07 14:55:05.562 E/PlayerDriver(83): Command PLAYER_SET_DATA_SOURCE completed with an error or info -4
02-07 14:55:05.562 E/MediaPlayer(20628): error (-4, -4)
02-07 14:55:05.562 E/MediaPlayer(20628): Error (-4,-4)
02-07 14:55:05.562 E/PVPlayer(83): isDrmfile playing 0
02-07 14:55:05.562 W/PlayerDriver(83): PVMFInfoErrorHandlingComplete
02-07 14:55:05.562 E/PlayerDriver(83): PlayerDriver::handleTvOut state=[4]
02-07 14:55:05.562 E/PlayerDriver(83): PlayerDriver::it is not a DRM file.So don't resume TVOUT
02-07 14:55:05.585 E/PlayerDriver(83): PlayerDriver::it is a not Protected file
02-07 14:55:05.585 E/PlayerDriver(83): PlayerDriver::handleTvOut state=[4]
02-07 14:55:05.585 E/PlayerDriver(83): PlayerDriver::it is not a DRM file.So don't resume TVOUT
02-07 14:55:05.585 E/OsclDirectFileIO(83): [LargeFileSupport] OsclDirectFileIO::eek:penFileOrSharedFd Error = -1
02-07 14:55:05.585 W/MediaPlayer(20628): info/warning (1, 26)
02-07 14:55:05.585 E/PlayerDriver(83): Command PLAYER_SET_DATA_SOURCE completed with an error or info -4
02-07 14:55:05.585 E/MediaPlayer(20628): error (-4, -4)
02-07 14:55:05.585 E/MediaPlayer(20628): Error (-4,-4)
02-07 14:55:05.589 E/PVPlayer(83): isDrmfile playing 0
02-07 14:55:05.589 W/PlayerDriver(83): PVMFInfoErrorHandlingComplete
02-07 14:55:05.589 E/PlayerDriver(83): PlayerDriver::handleTvOut state=[4]
02-07 14:55:05.589 E/PlayerDriver(83): PlayerDriver::it is not a DRM file.So don't resume TVOUT
 
jsterj
Old
#4  
Junior Member - OP
Thanks Meter 0
Posts: 4
Join Date: Feb 2012
I have it working using Phonegap's Media class. The proper way to access it through the media object is like this:
myMedia = new Media("/android_asset/www/test.mp3");

You have to put the full path as the media class defaults to the /SDCARD directory on relative paths.

Simon MacDonald has a great write up about using the media class:
h t tp ://simonmacdonald.blogspot.com/2011/05/using-media-class-in-phonegap.html?m=1

As for the HTML5 method and using the AUDIO tag, I'm still not certain why it fails on local files. Phonegap's media class works just fine though and is probably a more reliable solution anyhow. Phonegap FTW!
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes