maitrungduc1410 / react-native-video-trim

Video trimmer for React Native App
MIT License
37 stars 14 forks source link

I want to change the names of Edit Video, Cancel, and Save in iOS. What should I do? #18

Closed yanghun0070 closed 5 months ago

yanghun0070 commented 5 months ago

@maitrungduc1410 I want to change the names of Edit Video, Cancel, and Save in iOS. What should I do?

IMG_5928

maitrungduc1410 commented 5 months ago

I'll push update for this

yanghun0070 commented 5 months ago

thank you

maitrungduc1410 commented 5 months ago

please upgrade to 1.0.7, you can now customize the texts using:

showEditor(url, {
  maxDuration: 30,
  cancelButtonText: 'hello',
  saveButtonText: 'world',
  title: 'MyName',
})
yanghun0070 commented 5 months ago

@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();
     }
maitrungduc1410 commented 5 months ago

Can I check what error is that?

And how to reproduce as I never face it.

yanghun0070 commented 5 months ago

An issue occurs where the video is not saved properly. https://github.com/maitrungduc1410/react-native-video-trim/issues/16

yanghun0070 commented 5 months ago

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();
      }
    }
  }
maitrungduc1410 commented 5 months ago

I'm not really get what you're talking about

Can you please elaborate more?

yanghun0070 commented 5 months ago

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

https://github.com/maitrungduc1410/react-native-video-trim/assets/22450400/3ffcd4a4-cd84-4412-ad7f-e44c0bf1865e

After code change

https://github.com/maitrungduc1410/react-native-video-trim/assets/22450400/b8188f52-bf58-4f9b-9ac0-e8c547f34ab2

It works normally after changing the code.

maitrungduc1410 commented 5 months ago

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

yanghun0070 commented 5 months ago

@maitrungduc1410 It works well with the changed version. Thank you for your support.