StupidBeauty
Read times:976Posted 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

 
Recent comments
2017年4月~2019年4月垃圾短信排行榜Posted at:Thu Sep 26 04:51:48 2024
Qt5.7文档翻译:QWebEngineCookieStore类,QWebEngineCookieStore ClassPosted at:Fri Aug 11 06:50:35 2023盲盒kill -9 18289 Grebe.20230517.211749.552.mp4