我正在尝试为我的用户提供使用外部或内部存储的能力.我正在显示图像和视频(科学性质).将媒体存储在SD卡上时,一切都很好.但是当我在内部存储媒体时,只会显示图像.无论我尝试什么,我在尝试加载和显示存储在applicationcontext.getFilesDir()下的媒体时都会遇到各种错误.
是否有将视频内容设置为此类文件的技巧?
ContentResolver可以帮助我吗?
在相关的说明中,假设存在外部存储是否被视为不良形式?
提前致谢,
希德
下面是一个失败的版本"无法播放视频.抱歉,此视频无法播放".但我有许多其他失败模式.我可以将内部视频复制到临时存储(外部)并播放它,因此这个复制到内部确实创建了一个有效的电影.它只在我尝试直接从内部存储器播放时失败.
videoFile = new File(this.getFilesDir() + File.separator + "test.mp4");
InputStream data = res.openRawResource(R.raw.moviegood);
try {
OutputStream myOutputStream = new FileOutputStream(videoFile);
byte[] buffer = new byte[8192];
int length;
while ( (length = data.read(buffer)) > 0 ) {
myOutputStream.write(buffer);
}
//Close the streams
myOutputStream.flush();
myOutputStream.close();
data.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
vview.setKeepScreenOn(true);
vview.setVideoPath(videoFile.getAbsolutePath());
vview.start();
Run Code Online (Sandbox Code Playgroud)