viro icon indicating copy to clipboard operation
viro copied to clipboard

cant use startVideoRecording on Android 13

Open saadxprt opened this issue 1 year ago • 12 comments

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

saadxprt avatar Jul 26 '24 14:07 saadxprt

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

Android 13 Permissions

sandeepdoad avatar Jul 30 '24 06:07 sandeepdoad

@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

saadxprt avatar Jul 30 '24 22:07 saadxprt

Someone solved this ?

netanelbi avatar Aug 15 '24 13:08 netanelbi

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

fernandoamz avatar Sep 05 '24 07:09 fernandoamz

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.

naufanituharish avatar Sep 13 '24 04:09 naufanituharish

Any fix for this in the lib please

mouradaouinat avatar Oct 06 '24 15:10 mouradaouinat

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. 😁

naufanituharish avatar Oct 06 '24 15:10 naufanituharish

Thanks, I will check this

mouradaouinat avatar Oct 06 '24 15:10 mouradaouinat

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

mouradaouinat avatar Oct 07 '24 13:10 mouradaouinat

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

Could you share the error message?

naufanituharish avatar Oct 09 '24 06:10 naufanituharish

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 made my changes but when i try to run this script ./prepare_release.sh I get this error

* What went wrong:
Execution failed for task ':viro_bridge:mapReleaseSourceSetPaths'.
> Could not resolve all files for configuration ':viro_bridge:releaseRuntimeClasspath'.
   > Could not find any matches for com.facebook.react:react-native:+ as no versions of com.facebook.react:react-native are available.
     Searched in the following locations:
       - file:/C:/Users/raosa/.m2/repository/com/facebook/react/react-native/
       - file:/C:/Users/raosa/Documents/GitHub/viro/node_modules/react-native/android/com/facebook/react/react-native/maven-metadata.xml
       - file:/C:/Users/raosa/Documents/GitHub/viro/node_modules/jsc-android/dist/com/facebook/react/react-native/maven-metadata.xml
       - https://dl.google.com/dl/android/maven2/com/facebook/react/react-native/maven-metadata.xml
       - https://jcenter.bintray.com/com/facebook/react/react-native/maven-metadata.xml
       - https://jcenter.bintray.com/com/facebook/react/react-native/0.71.0-rc.0/react-native-0.71.0-rc.0.pom
       - https://jitpack.io/com/facebook/react/react-native/maven-metadata.xml
     Required by:
         project :viro_bridge

anyone knows a fix to this?

@fernandoamz

saadxprt avatar Oct 29 '24 21:10 saadxprt

Any one can tell how to install viro for local ( with changing some part of code as @saadxprt is doing ) step by step. Because the guide link in the repo are broken and instruction is not clear too.

pratikgautm avatar Nov 07 '24 14:11 pratikgautm