ivpusic / react-native-image-crop-picker

iOS/Android image picker with support for camera, video, configurable compression, multiple images and cropping
MIT License
6.12k stars 1.56k forks source link

Video Capture for Android 13 (SDK 33) doesn't work #1859

Open DaneHoward opened 1 year ago

DaneHoward commented 1 year ago

Version

Tell us which versions you are using:

Platform

Expected behaviour

Videos are captured successfully on openCamera with mediaType option 'video'

Actual behaviour

When capturing a video on Android SDK 33 / Android 13 -> The only response is that the user cancelled even if that's not the case

Steps to reproduce

  1. Init project

  2. Install react-native-image-crop-picker

  3. Try to capture video on an Android 13 (SDK 33) device

  4. Only response on RN side is "Error: User cancelled image selection"

  5. Response in Android emulator is attached below

Additional Info

I wanted to add this section because I've already done some research and hope that helps

  1. A similar issue with openPicker was solved by permissions outlined here: https://issuetracker.google.com/issues/237634019?pli=1 and here https://github.com/ivpusic/react-native-image-crop-picker/issues/1849
  2. Google warns of different permissions needed for Android 13 Video Recording: https://developer.android.com/about/versions/13/behavior-changes-13#granular-media-permissions
  3. RN offers PermissionsAndroid but when I tried to request the the READ_MEDIA_VIDEO the app would crash and say the permission is null. Could be my own lack of understanding but those same permissions are in the Manifest file so not sure why I was getting that null.

Attachments

// stacktrace or any other useful debug info I get this bad boy in the Android Emulator:

FATAL EXCEPTION: main
                                                                                                    Process: com.android.camera2, PID: 2576
                                                                                                    java.lang.NullPointerException: Attempt to invoke virtual method 'void android.content.ContentValues.put(java.lang.String, java.lang.Long)' on a null object reference
                                                                                                        at com.android.camera.VideoModule.saveVideo(VideoModule.java:1263)
                                                                                                        at com.android.camera.VideoModule.stopVideoRecording(VideoModule.java:1513)
                                                                                                        at com.android.camera.VideoModule.onStopVideoRecording(VideoModule.java:656)
                                                                                                        at com.android.camera.VideoModule.onShutterButtonClick(VideoModule.java:697)
                                                                                                        at com.android.camera.ShutterButton.performClick(ShutterButton.java:190)
                                                                                                        at android.view.View.performClickInternal(View.java:7483)
                                                                                                        at android.view.View.-$$Nest$mperformClickInternal(Unknown Source:0)
                                                                                                        at android.view.View$PerformClick.run(View.java:29335)
                                                                                                        at android.os.Handler.handleCallback(Handler.java:942)
                                                                                                        at android.os.Handler.dispatchMessage(Handler.java:99)
                                                                                                        at android.os.Looper.loopOnce(Looper.java:201)
                                                                                                        at android.os.Looper.loop(Looper.java:288)
                                                                                                        at android.app.ActivityThread.main(ActivityThread.java:7898)
                                                                                                        at java.lang.reflect.Method.invoke(Native Method)
                                                                                                        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
                                                                                                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)

Love react-native-image-crop-picker? Please consider supporting our collective: 👉 https://opencollective.com/react-native-image-crop-picker/donate

huanguolin commented 1 year ago

I face the same issue. Capture video is work, but the resultCode is RESULT_CANCELED(in onActivityResult). If I ignore the resultCode, the later steps all execute correctly (I can get the video, do the upload, etc.).

It's strange...

huanguolin commented 1 year ago

I found that the reason why it causes the result to be "Error: User cancelled xx" is because the confirmation screen (see the screenshot below) is missing after clicking end recording.

I use a local android project (without react-native, pure native) and test the "same" code to come out with this screen, so there is no problem.

I tried adjusting the react-native version, the android os version and android sdk version and found that only react-native + android 13 devices have this problem (regardless of react-native version and android sdk version).

But I still don't know how to fix this issue ....

image

jon-eubank commented 1 year ago

I encountered the same error when trying to do video capture on an Android emulator that was using Android 13, but when I created a test build and put it on a real device both the image and video capturing worked correctly.

Currently using version 0.37.3 of react-native-image-crop-picker and version 0.68.5 of RN.

Talhafayyaz11 commented 1 year ago

I am stuck at this. Any progress here.

DaneHoward commented 1 year ago

@huanguolin @jde8aa @Talhafayyaz11 Hi friends! I will mark this issue as resolved but first, let me help ya out!

So, I'm going to take a stab that all 3 of you are using Android 13+ which is giving the "didCancel" response.

This is not an issue with the image picker (well, the docs could be clearer)

This is a PERMISSION ISSUE!

The fix should look like this:

import { PermissionsAndroid, Platform, } from 'react-native'; Then in your component:

try { const granted = await PermissionsAndroid.request( PermissionsAndroid.PERMISSIONS.CAMERA, { title: "Cool Photo App Camera Permission", message: "Cool Photo App needs access to your camera " + "so you can take awesome pictures.", buttonNeutral: "Ask Me Later", buttonNegative: "Cancel", buttonPositive: "OK" } ); if (granted === PermissionsAndroid.RESULTS.GRANTED) { return true; } else { return false; } } catch (err) { console.warn(err); return false; }

This should fix up any Android 13 Video capture issues related to didCancel. Since at least the 4 of us have had this issue (and I assume more) They should make more of a stink about it in the docs but the code works.

++ wrap a little magic around this using Platform.OS to account for iOS and you're back in business!

jon-eubank commented 1 year ago

Thanks for the suggestion @DaneHoward but permissions have already been obtained in my case. The video capture simply doesn't work on Android emulators running Android 13 for me. It works fine on a real device though, and image capturing works fine on both emulators and real devices.

ahtokca commented 1 year ago

same here doesn't work in android 13 emulator

08-28 19:25:53.050 10120 10120 D AndroidRuntime: Shutting down VM
08-28 19:25:53.051 10120 10120 E AndroidRuntime: FATAL EXCEPTION: main
08-28 19:25:53.051 10120 10120 E AndroidRuntime: Process: com.android.camera2, PID: 10120
08-28 19:25:53.051 10120 10120 E AndroidRuntime: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.content.ContentValues.put(java.lang.String, java.lang.Long)' on a null object reference
08-28 19:25:53.051 10120 10120 E AndroidRuntime:    at com.android.camera.VideoModule.saveVideo(VideoModule.java:1263)
08-28 19:25:53.051 10120 10120 E AndroidRuntime:    at com.android.camera.VideoModule.stopVideoRecording(VideoModule.java:1513)
08-28 19:25:53.051 10120 10120 E AndroidRuntime:    at com.android.camera.VideoModule.onStopVideoRecording(VideoModule.java:656)
08-28 19:25:53.051 10120 10120 E AndroidRuntime:    at com.android.camera.VideoModule.onShutterButtonClick(VideoModule.java:697)
08-28 19:25:53.051 10120 10120 E AndroidRuntime:    at com.android.camera.ShutterButton.performClick(ShutterButton.java:190)
08-28 19:25:53.051 10120 10120 E AndroidRuntime:    at android.view.View.performClickInternal(View.java:7483)
08-28 19:25:53.051 10120 10120 E AndroidRuntime:    at android.view.View.-$$Nest$mperformClickInternal(Unknown Source:0)
08-28 19:25:53.051 10120 10120 E AndroidRuntime:    at android.view.View$PerformClick.run(View.java:29334)
08-28 19:25:53.051 10120 10120 E AndroidRuntime:    at android.os.Handler.handleCallback(Handler.java:942)
08-28 19:25:53.051 10120 10120 E AndroidRuntime:    at android.os.Handler.dispatchMessage(Handler.java:99)
08-28 19:25:53.051 10120 10120 E AndroidRuntime:    at android.os.Looper.loopOnce(Looper.java:201)
08-28 19:25:53.051 10120 10120 E AndroidRuntime:    at android.os.Looper.loop(Looper.java:288)
08-28 19:25:53.051 10120 10120 E AndroidRuntime:    at android.app.ActivityThread.main(ActivityThread.java:7872)
08-28 19:25:53.051 10120 10120 E AndroidRuntime:    at java.lang.reflect.Method.invoke(Native Method)
08-28 19:25:53.051 10120 10120 E AndroidRuntime:    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
08-28 19:25:53.051 10120 10120 E AndroidRuntime:    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
08-28 19:25:53.054   703 10694 I DropBoxManagerService: add tag=system_app_crash isTagEnabled=true flags=0x2
08-28 19:25:53.055   703  1208 W ActivityTaskManager:   Force finishing activity com.android.camera2/com.android.camera.VideoCamera