ReactVision / viro

ViroReact: The AR and VR library for React Native 📳💙💛🤍💚
MIT License
1.39k stars 162 forks source link

cant use startVideoRecording on Android 13 #303

Open saadxprt opened 3 months ago

saadxprt commented 3 months ago

environment:

Windows Android 13 actual device @viro-community/react-viro": "^2.41.1", "react-native": "0.72.6", Infinix Zero 30

    const handlePressRecordVideo = async () => {
      if (recording) {
        try {
          const result = await ref.current?._stopVideoRecording();
          setRecording(false);
          console.log("[254]", result);
        } catch (e) {
          console.error("[254]", e);
        }
      } else {
        try {
          setRecording(true);
          const result = await ref.current?._startVideoRecording(
            "test",
            true,
            (e) => {
              // https://viro-community.readme.io/docs/viroconstants#section-video-recording-screenshot-errors
              console.error("[254]", e);
            }
          );
          console.log("[254]", result);
        } catch (e) {
          console.error("[254]", e);
        }
      }
    }

it returns {"errorCode": 1, "success": false, "url": null} This is working fine with android 12 with these permissions

await request('android.permission.WRITE_EXTERNAL_STORAGE'); ` what do I need to do in order to make this _startVideoRecording work with Android 13? or just store the recording anywhere on the phone which I can access

sandeepdoad commented 3 months ago

@saadxprt Pls Check the below Link for Android 13 Permissions Changelogs and Select the Suitable Answer for your Problem

Android 13 Permissions

saadxprt commented 3 months ago

@saadxprt Pls Check the below Link for Android 13 Permissions Changelogs and Select the Suitable Answer for your Problem

Android 13 Permissions

i did try to incorporate the appropriate permissions as per many answers, didnt work for me

netanelbi commented 2 months ago

Someone solved this ?

fernandoamz commented 1 month ago

Hi I think that I have the solution to this bug, basically the viro library internally is reviewing the permissions but on sdk above to 33 we need to ask for other permissions types, so, I fixed recently if you create your own react viro version and make a local installation

After you clone the rect viro repository (https://github.com/viromedia/viro) you will need to add the follow lines inside the:

android -> viro_bridge -> java -> src -> module -> ARSceneNavigatorModule.java

search the line 331:

if (audioAndRecordingPerm){
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
                reactActivity.requestPermissions(new String[]{
                        Manifest.permission.READ_MEDIA_IMAGES,
                        Manifest.permission.READ_MEDIA_AUDIO,
                        Manifest.permission.READ_MEDIA_VIDEO,
                        Manifest.permission.RECORD_AUDIO
                }, PERMISSION_REQ_CODE_AUDIO, listener);
            } else {
                reactActivity.requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE,
                        Manifest.permission.RECORD_AUDIO}, PERMISSION_REQ_CODE_AUDIO, listener);
            }
        } else {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
                reactActivity.requestPermissions(new String[]{
                        Manifest.permission.READ_MEDIA_IMAGES,
                        Manifest.permission.READ_MEDIA_AUDIO,
                        Manifest.permission.READ_MEDIA_VIDEO,
                        Manifest.permission.RECORD_AUDIO
                }, PERMISSION_REQ_CODE_AUDIO, listener);
            } else {
                reactActivity.requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
                        PERMISSION_REQ_CODE_STORAGE, listener);
            }
        }

       private static boolean hasAudioAndRecordingPermissions(Context context) {
              if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
                  boolean hasReadMediaImagesPermissions = ContextCompat.checkSelfPermission(context, "android.permission.READ_MEDIA_IMAGES") == 0;
                  boolean hasReadMediaAudioPermissions = ContextCompat.checkSelfPermission(context, "android.permission.READ_MEDIA_AUDIO") == 0;
                  boolean hasReadMediaVideoPermissions = ContextCompat.checkSelfPermission(context, "android.permission.READ_MEDIA_VIDEO") == 0;

                  return hasReadMediaImagesPermissions && hasReadMediaAudioPermissions && hasReadMediaVideoPermissions;
              } else {
                  boolean hasRecordPermissions = ContextCompat.checkSelfPermission(context, "android.permission.RECORD_AUDIO") == 0;
                  boolean hasExternalStoragePerm = ContextCompat.checkSelfPermission(context, "android.permission.WRITE_EXTERNAL_STORAGE") == 0;
                  return hasRecordPermissions && hasExternalStoragePerm;
              }
          }

Basically that's the issue because it is reviewing internally the permissions before record I tested this and the recording it's working properly, I would help you. Would be great if some contributor could add this changes and thanks to @doranteseduardo he explain me how I can make my local viro version

naufanituharish commented 1 month ago

Hi I think that I have the solution to this bug, basically the viro library internally is reviewing the permissions but on sdk above to 33 we need to ask for other permissions types, so, I fixed recently if you create your own react viro version and make a local installation

After you clone the rect viro repository (https://github.com/viromedia/viro) you will need to add the follow lines inside the:

android -> viro_bridge -> java -> src -> module -> ARSceneNavigatorModule.java

search the line 331:

if (audioAndRecordingPerm){
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
                reactActivity.requestPermissions(new String[]{
                        Manifest.permission.READ_MEDIA_IMAGES,
                        Manifest.permission.READ_MEDIA_AUDIO,
                        Manifest.permission.READ_MEDIA_VIDEO,
                        Manifest.permission.RECORD_AUDIO
                }, PERMISSION_REQ_CODE_AUDIO, listener);
            } else {
                reactActivity.requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE,
                        Manifest.permission.RECORD_AUDIO}, PERMISSION_REQ_CODE_AUDIO, listener);
            }
        } else {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
                reactActivity.requestPermissions(new String[]{
                        Manifest.permission.READ_MEDIA_IMAGES,
                        Manifest.permission.READ_MEDIA_AUDIO,
                        Manifest.permission.READ_MEDIA_VIDEO,
                        Manifest.permission.RECORD_AUDIO
                }, PERMISSION_REQ_CODE_AUDIO, listener);
            } else {
                reactActivity.requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
                        PERMISSION_REQ_CODE_STORAGE, listener);
            }
        }

       private static boolean hasAudioAndRecordingPermissions(Context context) {
              if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
                  boolean hasReadMediaImagesPermissions = ContextCompat.checkSelfPermission(context, "android.permission.READ_MEDIA_IMAGES") == 0;
                  boolean hasReadMediaAudioPermissions = ContextCompat.checkSelfPermission(context, "android.permission.READ_MEDIA_AUDIO") == 0;
                  boolean hasReadMediaVideoPermissions = ContextCompat.checkSelfPermission(context, "android.permission.READ_MEDIA_VIDEO") == 0;

                  return hasReadMediaImagesPermissions && hasReadMediaAudioPermissions && hasReadMediaVideoPermissions;
              } else {
                  boolean hasRecordPermissions = ContextCompat.checkSelfPermission(context, "android.permission.RECORD_AUDIO") == 0;
                  boolean hasExternalStoragePerm = ContextCompat.checkSelfPermission(context, "android.permission.WRITE_EXTERNAL_STORAGE") == 0;
                  return hasRecordPermissions && hasExternalStoragePerm;
              }
          }

Basically that's the issue because it is reviewing internally the permissions before record I tested this and the recording it's working properly, I would help you. Would be great if some contributor could add this changes and thanks to @doranteseduardo he explain me how I can make my local viro version

could you share us the full code file how to replace this,. because I'm not able to make it work, by using your instruction. thanks.

thedentist89 commented 4 weeks ago

Any fix for this in the lib please

naufanituharish commented 4 weeks ago

Any fix for this in the lib please

For android 14 or latter. You can just follow the @fernandoamz for the viro repo. Also, you need to fix the permission in the virocore repository. After you fix the permission issue, you need to rebuild the .aar file. Then you need to rebuild the package. To re build the .aar file you can just follow the readme instruction in virocore repository. To rebuild the react viro package just follow the documentation in react vision documentation site.

If you just build the project for experimental you can just force the permission check to returning true. 😁

thedentist89 commented 4 weeks ago

Thanks, I will check this

thedentist89 commented 3 weeks ago

@naufanituharish I can't build the local version after following the instructions on react vision documentation site

naufanituharish commented 3 weeks ago

@naufanituharish I can't build the local version after following the instructions on react vision documentation site

Could you share the error message?

saadxprt commented 4 days ago

Hi I think that I have the solution to this bug, basically the viro library internally is reviewing the permissions but on sdk above to 33 we need to ask for other permissions types, so, I fixed recently if you create your own react viro version and make a local installation

After you clone the rect viro repository (https://github.com/viromedia/viro) you will need to add the follow lines inside the:

android -> viro_bridge -> java -> src -> module -> ARSceneNavigatorModule.java

search the line 331:

if (audioAndRecordingPerm){
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
                reactActivity.requestPermissions(new String[]{
                        Manifest.permission.READ_MEDIA_IMAGES,
                        Manifest.permission.READ_MEDIA_AUDIO,
                        Manifest.permission.READ_MEDIA_VIDEO,
                        Manifest.permission.RECORD_AUDIO
                }, PERMISSION_REQ_CODE_AUDIO, listener);
            } else {
                reactActivity.requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE,
                        Manifest.permission.RECORD_AUDIO}, PERMISSION_REQ_CODE_AUDIO, listener);
            }
        } else {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
                reactActivity.requestPermissions(new String[]{
                        Manifest.permission.READ_MEDIA_IMAGES,
                        Manifest.permission.READ_MEDIA_AUDIO,
                        Manifest.permission.READ_MEDIA_VIDEO,
                        Manifest.permission.RECORD_AUDIO
                }, PERMISSION_REQ_CODE_AUDIO, listener);
            } else {
                reactActivity.requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
                        PERMISSION_REQ_CODE_STORAGE, listener);
            }
        }

       private static boolean hasAudioAndRecordingPermissions(Context context) {
              if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
                  boolean hasReadMediaImagesPermissions = ContextCompat.checkSelfPermission(context, "android.permission.READ_MEDIA_IMAGES") == 0;
                  boolean hasReadMediaAudioPermissions = ContextCompat.checkSelfPermission(context, "android.permission.READ_MEDIA_AUDIO") == 0;
                  boolean hasReadMediaVideoPermissions = ContextCompat.checkSelfPermission(context, "android.permission.READ_MEDIA_VIDEO") == 0;

                  return hasReadMediaImagesPermissions && hasReadMediaAudioPermissions && hasReadMediaVideoPermissions;
              } else {
                  boolean hasRecordPermissions = ContextCompat.checkSelfPermission(context, "android.permission.RECORD_AUDIO") == 0;
                  boolean hasExternalStoragePerm = ContextCompat.checkSelfPermission(context, "android.permission.WRITE_EXTERNAL_STORAGE") == 0;
                  return hasRecordPermissions && hasExternalStoragePerm;
              }
          }

Basically that's the issue because it is reviewing internally the permissions before record I tested this and the recording it's working properly, I would help you. Would be great if some contributor could add this changes and thanks to @doranteseduardo he explain me how I can make my local viro version

Can you please share intructions here how to build this locally so I can use it with my project?

Edit: I have forked the repo and its in my package.json with that updated code shared above

"@reactvision/react-viro": "github:saadxprt/viro"

but looks like i also have to

 cd android
./gradlew :viroreact:assembleRelease

but this part is not working for me im getting an error

* What went wrong:
Cannot locate tasks that match ':viroreact:assembleRelease' as project 'viroreact' not found in root project 'reactnativestarter'.