Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cant use startVideoRecording on Android 13 #303

Open
saadxprt opened this issue Jul 26, 2024 · 12 comments
Open

cant use startVideoRecording on Android 13 #303

saadxprt opened this issue Jul 26, 2024 · 12 comments

Comments

@saadxprt
Copy link

saadxprt commented Jul 26, 2024

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
Copy link

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

Android 13 Permissions

@saadxprt
Copy link
Author

@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
Copy link

Someone solved this ?

@fernandoamz
Copy link

fernandoamz commented Sep 5, 2024

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
Copy link

naufanituharish commented Sep 13, 2024

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
Copy link

Any fix for this in the lib please

@naufanituharish
Copy link

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
Copy link

Thanks, I will check this

@thedentist89
Copy link

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

@naufanituharish
Copy link

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

Could you share the error message?

@saadxprt
Copy link
Author

saadxprt commented Oct 29, 2024

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

@pratikgautm
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants