由于权限的问题,安卓里的MediaPlayer是无法播放其它应用程序私有的数据目录里的媒体文件的。绕过的办法是,由该应用程序自己打开该媒体文件,然后向 MediaPlayer的setDataSource函数中传递该文件的描述符。
亮点 :
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. |
地球正在数字化
HxLauncher: Launch Android applications by voice commands