yasirkula/UnityNativeCamera

Video recording does not work

AlexanderLukashin opened this issue ยท 13 comments

After the user finishes recording the video, null is returned instead of the path.

  • Unity version: 2022.3.29f
  • Platform: Android
  • Device: Redmi 10 (Android 13, MIUI 14.0.2), Xiaomi 14 (Android 14, HyperOS 1.0.6.0)
    image
    Link to the log file

May I see your code?

Here is the method for processing pressing the start recording button

        private void RecordVideo(ClickEvent eventArgs)
        {
            _ = NativeCamera.RecordVideo(Record);

            void Record(string path)
            {
                AddFiles(_data.TaskMedia, path).Forget();
            }
        }

Hmm, it looks good to me. We need to figure out whether this is a device-specific issue or Unity version-specific issue. Do you have older Unity versions (2021 or older) that you can test the example code on?

I tried to build in Unity 2021.3.38f, but the path is still returned null. Link to the log file

This bug is also reproduced on the Galaxy tab 8 tablet (Android 14, OneUI 6.0)

I've created the APK inside this zip archive on 2021.3.29f1 using Mono (faster build) and it works well on my Galaxy S8. Could you give it a try? Source code:

NativeCamera.Permission permission = NativeCamera.RecordVideo( ( path ) =>
{
	if( path != null )
	{
		// Play the recorded video
		Handheld.PlayFullScreenMovie( "file://" + path );
	}
} );

It doesn't work again, here is a link to the archive with videos and logs

Thank you, it's evidently a device-specific issue. I'll investigate it.

There is no such error in the plugin version 1.4.2, maybe it will help somehow

I've been having a busy schedule so I couldn't take a look at it yet.

I've now added a few extra logs to the sections of the code that were added in v1.4.3. Reading those logs could prove useful. Could you replace NativeCamera.aar with the one inside this zip archive and post all logcat logs that have the log tag "Unity"?

PS. The issue doesn't occur on an Android 14 Galaxy S23 device either.

OK I think I figured it out. Thank you for providing the logs. The issue is, the video is saved to path X (that we provide to the camera) but Android wraps that path inside a Uri, let's call it Y. Normally, the native GetPathFromURI function can convert Y to X but for unknown reasons, this failed on your Xiaomi device. The fallback to this scenario is, copying the file from Y to a filepath that we provide (this behaviour was added in v1.4.3). The thing I overlooked is, I was passing back X to that filepath. So, NativeCamera was trying to copy the video from X back to X.

I've resolved this issue in two steps:

  • If conversion from Y to X fails, I also check if there is a non-empty file existing at X (behaviour in v1.4.2). If so, then it means that the video was recorded to X successfully and we can simply return X
  • In the worst case, if the "copy file" fallback is reached, I copy the file to a different path than X to avoid collisions

Could you give this new aar file a shot and verify that the issue is resolved? I'd also appreciate if you could send the Unity-tagged logs one last time to make sure that nothing goes wrong.