从INTERNAL存储读取视频

时间:2016-02-03 22:41:53

标签: android internal-storage

这是将我的视频保存到内部存储的代码(也许我将其保存错误):

private String saveVideo() {
    InputStream inputStream = getResources().openRawResource(R.raw.back_lungs);

    ContextWrapper cw = new ContextWrapper(getApplicationContext());
    // path to /data/data/yourapp/app_data/videoDir
    File directory = cw.getDir("videoDir", Context.MODE_PRIVATE);
    // Create videoDir
    File mypath = new File(directory, "video1.mp4");

    FileOutputStream fos = null;
    try {
        fos = new FileOutputStream(mypath);
        mypath.setReadable(true,false);
        // Use the compress method on the BitMap object to write image to the OutputStream
        int read = -1;
        byte[] buffer = new byte[1024];
        while ((read = inputStream.read(buffer)) == -1) {
            fos.write(buffer, 0, read);
        }
        inputStream.close();
        fos.close();
    } catch (Exception e) {
        e.printStackTrace();
    }

    return directory.getAbsolutePath();
}

现在我从原始文件夹中获取视频,但我稍后会从互联网上下载(这不是问题)。

这是阅读视频的代码,但它失败了:

private void loadVideoFromStorage(String path) {


        File f = new File(path, "video1.mp4");

        videoView.setVideoURI(Uri.fromFile(f));
        videoView.start();


}

0 个答案:

没有答案