yasirkula / UnityNativeCamera

A native Unity plugin to take pictures/record videos with device camera on Android & iOS
MIT License
615 stars 71 forks source link

Video recording does not work #120

Closed AlexanderLukashin closed 5 months ago

AlexanderLukashin commented 6 months ago

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

yasirkula commented 6 months ago

May I see your code?

AlexanderLukashin commented 6 months ago

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();
            }
        }
yasirkula commented 6 months ago

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?

AlexanderLukashin commented 6 months ago

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

AlexanderLukashin commented 6 months ago

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

yasirkula commented 6 months ago

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 );
    }
} );
AlexanderLukashin commented 6 months ago

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

yasirkula commented 6 months ago

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

AlexanderLukashin commented 6 months ago

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

yasirkula commented 6 months ago

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

yasirkula commented 5 months ago

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.

AlexanderLukashin commented 5 months ago

Xiaomi-22011119UY-Android-13_2024-06-21_110356.zip

yasirkula commented 5 months ago

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:

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.

AlexanderLukashin commented 5 months ago

These changes have fixed the bug. Xiaomi-23127PN0CG-Android-14_2024-06-24_110638.zip