Forum Discussion
aguirreduran
5 years agoExplorer
Android API for video recording plugin in Unity
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:
- private void Start()
- {
- DontDestroyOnLoad(gameObject);
- #if UNITY_ANDROID && !UNITY_EDITOR
- {
- androidRecorder = unityClass.GetStatic<AndroidJavaObject>("currentActivity");
- androidRecorder.Call("setUpSaveFolder","Tee");//custom your save folder to Movies/Tee, by defaut it will use Movies/AndroidUtils
- int width = (int)(Screen.width > SCREEN_WIDTH ? SCREEN_WIDTH : Screen.width);
- int height = Screen.width > SCREEN_WIDTH ? (int)(Screen.height * SCREEN_WIDTH / Screen.width) : Screen.height;
- int bitrate = (int)(1f * width * height / 100 * 240 * 7);
- int fps = 30;
- bool audioEnable=true;
- 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
- }
- #endif
- }
When the user press the record button, the script calls this method:
- #region Android Recorder
- public void StartRecording()
- {
- #if UNITY_ANDROID && !UNITY_EDITOR
- if (!AndroidUtils.IsPermitted(AndroidPermission.RECORD_AUDIO))//RECORD_AUDIO is declared inside plugin manifest but we need to request it manualy
- {
- AndroidUtils.RequestPermission(AndroidPermission.RECORD_AUDIO);
- onAllowCallback = () =>
- {
- androidRecorder.Call("startRecording");
- };
- onDenyCallback = () => { ShowToast("Need RECORD_AUDIO permission to record voice");};
- onDenyAndNeverAskAgainCallback = () => { ShowToast("Need RECORD_AUDIO permission to record voice");};
- }
- else
- androidRecorder.Call("startRecording");
- #endif
- }
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
Quick Links
- Horizon Developer Support
- Quest User Forums
- Troubleshooting Forum for problems with a game or app
- Quest Support for problems with your device
Other Meta Support
Related Content
- 10 months ago