maitrungduc1410 / react-native-video-trim

Video trimmer for React Native App
MIT License
60 stars 24 forks source link

java.lang.ArithmeticException #79

Open LianVyv opened 4 days ago

LianVyv commented 4 days ago

Hi @maitrungduc1410

I was preparing my app on the PlayStore and then they reported this issue

Exception java.lang.ArithmeticException: divide by zero
  at com.videotrim.widgets.VideoTrimmerView.mediaPrepared (VideoTrimmerView.java:94)
  at com.videotrim.widgets.VideoTrimmerView.lambda$initByURI$0 (VideoTrimmerView.java:5)
  at android.widget.VideoView$2.onPrepared (VideoView.java:499)
  at android.media.MediaPlayer$EventHandler.handleMessage (MediaPlayer.java:3348)
  at android.os.Handler.dispatchMessage (Handler.java:106)
  at android.os.Looper.loop (Looper.java:223)
  at android.app.ActivityThread.main (ActivityThread.java:7664)
  at java.lang.reflect.Method.invoke
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:592)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:947)

Device Google Pixel 5 1080x2340 Android 11 (SDK 30) 8,192 MB arm64-v8a en_ZA

I had a quick look at the code and I can see on two places where you doing division in mediaPrepared() method

1.VideoTrimmerUtil.mThumbWidth = VideoTrimmerUtil.THUMB_HEIGHT * bitmap.getWidth() / bitmap.getHeight(); AND

  1. VideoTrimmerUtil.MAX_COUNT_RANGE = Math.max((VIDEO_FRAMES_WIDTH / VideoTrimmerUtil.mThumbWidth), VideoTrimmerUtil.MAX_COUNT_RANGE);

I doubt that it will be number 2. I'm assuming it is number 1. Do you think there is a chance that bitmap.getHeight() might be 0?

This is how I call the code

  showEditor(data.uri, {
          maxDuration: 60,
          enableCancelDialog: false,
          enableSaveDialog: false,
          saveButtonText: 'Upload',
        });

I have not personally seen this crash happen. I have only noticed that on old Huawei device I can't open the trimming but still need to investiage this one wondering if it might be related.

Let me know if you need anything else.

maitrungduc1410 commented 4 days ago

hi, thanks for reporting the issue. Lemme check and get back to you

maitrungduc1410 commented 4 days ago

is it possible for you to ask them for a screen recording/screenshot, and their testing video as well

LianVyv commented 4 days ago

@maitrungduc1410 for this particular crash it unfortunately did not have a screenshot. Here is what I see on the PlayStore.

This crash have been recorded on two different release now and both times that screenshot is not getting read.

Screenshot 2024-11-10 at 17 07 36

maitrungduc1410 commented 4 days ago

hi @LianVyv please upgrade to 2.2.11, I added a fallback for this. Check here