提问人:Maor Cohen 提问时间:5/3/2023 最后编辑:Maor Cohen 更新时间:5/3/2023 访问量:81
如何在SDK版本33中将视频从外部存储复制到内部存储?
How to copy video from external storage to internal storage in SDK version 33?
问:
我有一个视频选取器,当用户选取视频时,我想将其复制到内部文件夹中并对其进行修改。可能吗?如何?
如果没有,我可以在哪里存储视频,以便用户无法访问它(因为我将修改它,我不希望他能够访问修改后的视频)
由以下代码处理的视频选取器:
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("video/*");
String[] mimeTypes = {"video/mp4", "video/3gp", "video/mpeg"};
intent.putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes);
activity.startActivityForResult(intent, REQUEST_CODE_VIDEO_PICKER);
然后,其结果:
Uri videoUri = data.getData();
我正在尝试使用以下方法复制文件:
uriSrc = "content://com.android.providers.media.documents/document/video%3A1000099794"
destPath = getFilesDir() + "/video.mp4";
public static boolean copyFileToInternalStorage(Context context, Uri uriSrc, String destPath) {
try {
//InputStream inputStream = context.getContentResolver().openInputStream(uriSrc);
//File tempFile = File.createTempFile("video", ".mp4", context.getCacheDir());
//FileOutputStream outputStream = new FileOutputStream(tempFile);
//byte[] buffer = new byte[1024];
//int read;
//while ((read = inputStream.read(buffer)) != -1) {
// outputStream.write(buffer, 0, read);
//}
//outputStream.close();
InputStream fileInputStream= context.getContentResolver().openInputStream(uriSrc);
FileOutputStream outputStreamInternal = new FileOutputStream(destPath);
byte[] buffer2 = new byte[1024];
int length;
while ((length = fileInputStream.read(buffer2)) > 0) {
outputStreamInternal.write(buffer2, 0, length);
}
fileInputStream.close();
outputStreamInternal.close();
}
catch (Exception e) {
Log.d("file_log", "exception when copying the src file to the internal storage: " + e.getMessage());
}
return new File(destPath).exists();
}
它将视频复制到内部,但没有音频。
答: 暂无答案
评论
a video picker
什么?请出示验证码。并告诉用户在选择文件时会得到什么。outputStream.close()
FileInputStream fileInputStream = new FileInputStream(tempFile);
这和下面的所有代码都没有意义。复制一个文件,然后复制复制的文件。为什么?