I have a video picker and when the users picks the video, I want to copy it into the internal files folder and modify it. Is it possible? how?
If not, where can I store the video so the user can't access it (as I'm going to modify it and I don't want him to be able to access the modified video)
video picker handled by this code:
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);
Then, its result:
Uri videoUri = data.getData();
I'm trying to copy the file using:
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();
}
it copies the video to internal but without audio.