cancel
Showing results for 
Search instead for 
Did you mean: 

Android API for video recording plugin in Unity

aguirreduran
Level 3

Hello,

currently I'm working on a project that needs to record what the user is observing in the Oculus Quest 2. The recording should be triggered by an UI button that the user can use whenever it wants.
I didn't find any dedicated asset for this purpose, but I found a solution for Android, in particular a screen recorder: LINK

  • I tested in my smartphone and everything is working fine
  • I tested in the Oculus Quest, the build has no errors and the application doesn't crash during the use with the headset. The problem is that the videos registered are empty!

The code responsible to setup the video and start recording is this:

  1. private void Start()
  2.     {
  3.         DontDestroyOnLoad(gameObject);
  4. #if UNITY_ANDROID && !UNITY_EDITOR
  5.         using (AndroidJavaClass unityClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
  6.         {
  7.             androidRecorder = unityClass.GetStatic<AndroidJavaObject>("currentActivity");
  8.             androidRecorder.Call("setUpSaveFolder","Tee");//custom your save folder to Movies/Tee, by defaut it will use Movies/AndroidUtils
  9.             int width = (int)(Screen.width > SCREEN_WIDTH ? SCREEN_WIDTH : Screen.width);
  10.             int height = Screen.width > SCREEN_WIDTH ? (int)(Screen.height * SCREEN_WIDTH / Screen.width) : Screen.height;
  11.             int bitrate = (int)(1f * width * height / 100 * 240 * 7);
  12.             int fps = 30;
  13.             bool audioEnable=true;
  14.             androidRecorder.Call("setupVideo", width, height,bitrate, fps,audioEnable);//this line manual sets the video record setting. You ca use the defaut setting by comment this code block
  15.         }
  16. #endif
  17.     }

When the user press the record button, the script calls this method:

 
  1.    #region Android Recorder
  2.     public void StartRecording()
  3.     {
  4. #if UNITY_ANDROID && !UNITY_EDITOR
  5.         if (!AndroidUtils.IsPermitted(AndroidPermission.RECORD_AUDIO))//RECORD_AUDIO is declared inside plugin manifest but we need to request it manualy
  6.         {
  7.             AndroidUtils.RequestPermission(AndroidPermission.RECORD_AUDIO);
  8.             onAllowCallback = () =>
  9.             {
  10.                 androidRecorder.Call("startRecording");
  11.             };
  12.             onDenyCallback = () => { ShowToast("Need RECORD_AUDIO permission to record voice");};
  13.             onDenyAndNeverAskAgainCallback = () => { ShowToast("Need RECORD_AUDIO permission to record voice");};
  14.         }
  15.         else
  16.             androidRecorder.Call("startRecording");
  17. #endif
  18.     }

I'm trying to find the issue during these steps and find out the reason why the videos are empty.
Could I modify this script in order to adapt it to the Oculus "screen"?

Thanks

0 REPLIES 0