StupidBeauty
Read times:1006Posted at:Thu Aug 22 04:45:42 2013
- no title specified

转载:MediaPlayer cant play audio files from program data folder?

由于权限的问题,安卓里的MediaPlayer是无法播放其它应用程序私有的数据目录里的媒体文件的。绕过的办法是,由该应用程序自己打开该媒体文件,然后向 MediaPlayer的setDataSource函数中传递该文件的描述符。

http://stackoverflow.com/questions/3773262/mediaplayer-cant-play-audio-files-from-program-data-folder

亮点

6 down vote

i had the same issues... whenever i used setDataSource with filepaths, it would not work; kept getting IOException.

changing my code to use setDataSource(FileDescriptor) does work... and with this i don't have to copy the files to SDCard or anything like that.

So, with a simple File object, create a new FileInputStream and pass the actual file descriptor as data source as in:

setDataSource((new FileInputStream(myFileInstance)).getFD());

creating an input stream pulls the file data into memory and thereby addresses /data/data access violations.

地球正在数字化

Your opinions
Your name:Email:Website url:Opinion content:
- no title specified

HxLauncher: Launch Android applications by voice commands