Closed yanghun0070 closed 5 months ago
I'll push update for this
thank you
please upgrade to 1.0.7, you can now customize the texts using:
showEditor(url, {
maxDuration: 30,
cancelButtonText: 'hello',
saveButtonText: 'world',
title: 'MyName',
})
@maitrungduc1410 Thanks for the quick fix An error occurs in the code below when saving to Android. Is it possible to add this code as below?
public static void saveVideoToGallery(ReactApplicationContext context, String videoFilePath) throws IOException {
File videoFile = new File(videoFilePath);
// Create the file if it doesn't exist
if (!videoFile.exists()) {
boolean isFileCreated = videoFile.createNewFile();
}
Can I check what error is that?
And how to reproduce as I never face it.
An issue occurs where the video is not saved properly. https://github.com/maitrungduc1410/react-native-video-trim/issues/16
The reason the file is broken in the given code is that you are not actually copying the contents of the file. There is no logic to read the contents of the file in the commented part and write it to outputStream.
private static void saveVideoUsingMediaStore(Context context, File videoFile) {
ContentValues values = new ContentValues();
values.put(MediaStore.Video.Media.TITLE, "My Video Title");
values.put(MediaStore.Video.Media.MIME_TYPE, "video/mp4");
values.put(MediaStore.Video.Media.RELATIVE_PATH, Environment.DIRECTORY_DCIM);
Uri uri = context.getContentResolver().insert(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, values);
if (uri != null) {
try {
OutputStream outputStream = context.getContentResolver().openOutputStream(uri);
if (outputStream != null) {
// Copy the video file to the output stream
FileInputStream inputStream = new FileInputStream(videoFile);
byte[] buffer = new byte[1024];
int length;
while ((length = inputStream.read(buffer)) > 0) {
outputStream.write(buffer, 0, length);
}
inputStream.close();
outputStream.close();
// Notify the media scanner that a new video has been added to the gallery
MediaScannerConnection.scanFile(context, new String[]{videoFile.getAbsolutePath()}, new String[]{"video/*"}, null);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
I'm not really get what you're talking about
Can you please elaborate more?
The reason the file is broken in the given code is that you are not actually copying the contents of the file.
There is no logic to read the contents of the file in the commented part and write it to outputStream.
// Copy the video file to the output stream
FileInputStream inputStream = new FileInputStream(videoFile);
byte[] buffer = new byte[1024];
int length;
while ((length = inputStream.read(buffer)) > 0) {
outputStream.write(buffer, 0, length);
}
inputStream.close();
Your video file will not be broken because you will append the contents of the file below and write it to the outputStream.
Before code change
After code change
It works normally after changing the code.
oh, just recognized that I made this silly issue, forgot to implement the save file for API >= 29 :)).
please upgrade to v1.0.8
and check again.
also can you help me verify if after saving you can see it in your Gallery (make sure Gallery app opened in advance). I want to verify MediaScannerConnection
works, thanks
@maitrungduc1410 It works well with the changed version. Thank you for your support.
@maitrungduc1410 I want to change the names of Edit Video, Cancel, and Save in iOS. What should I do?