将mp4文件保存到/data/data/mypackage/files/my.mp4,然后调用VideoView的setVideoPath();它不能工作。
对于同一个文件,如果我将文件保存到/mnt/sdcard/my.mp4,然后调用相同的VideoView的setVideoPath,它会正常播放。
有什么方法可以在/ data / data / mypackage / files /下播放mp4文件吗?
答案 0 :(得分:5)
MP 或 VideoView 使用无法访问不可翻译文件的原生播放器。
所以你必须基本上选择:
1)使创建的文件具有世界可读性
2)打开程序中文件的输入流,然后将文件描述符移交给媒体播放器:
FileInputStream fi = new FileInputStream(file);
MediaPlayer pl = new MediaPlayer();
pl.setDataSource(fi.getFD());
pl.prepare();
pl.start();
同时查看此帖子VideoView/MediaPlayer doesn't play video from internal storage并找到here中的自定义视频类代码,同时查看此问题Can a videoview play a video stored on internal storage?