dimonovdd / Xamarin.MediaGallery

This plugin is designed to picking and save images and video files from native gallery of Android and iOS devices and capture photos
MIT License
154 stars 19 forks source link

Code hanging at call to CapturePhotoAsync #117

Closed williambuchanan2 closed 1 year ago

williambuchanan2 commented 1 year ago

Description

When I call this line: var file = await MediaGallery.CapturePhotoAsync(cts.Token); The camera shows and I can click the tick, but the following code never gets executed. It is like the await never returns. Reported by another team member and verified same behaviour on my device.

Actual Behavior

Code never executes past this point.

Expected behavior

Code continues to execute.

Steps to reproduce the behavior

  1. Implement example code exactly as is.

Screenshots or Videos

Reproduction Link

Configuration

dimonovdd commented 1 year ago

Hi. Do you have a sample project? It works correctly for me

williambuchanan2 commented 1 year ago

I pretty much copied the code as is (see below). I am on .net 7.0 - not sure if that makes a difference.

[RelayCommand]
public async void СapturePhotoPressed()
{
    CancellationTokenSource cts = null;
    try
    {
        DisposeItems();
        if (!MediaGallery.CheckCapturePhotoSupport())
        {
            OperationInfo = "Capture Photo Not Supported";
            return;
        }

        var status = await PermissionHelper.CheckAndRequest<Permissions.Camera>(
                "The application needs permission to camera");

        if (!status)
        {
            //Toast.ShowToast("The application did not get the necessary permission to camera");
            return;
        }

        cts = new CancellationTokenSource(
                TimeSpan.FromMilliseconds(DelayMilliseconds));

        var file = await MediaGallery.CapturePhotoAsync(cts.Token);

        SelectedItems = file != null ? new IMediaFile[] { file } : null;
        SetInfo(SelectedItems);
      }
    catch (Exception ex)
    {
        OperationInfo = ex.Message;
    }
    finally
    {
        cts?.Dispose();
    }
}
dimonovdd commented 1 year ago

Do you have such a code?

public class MainActivity : MauiAppCompatActivity
{
    protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);
        NativeMedia.Platform.Init(this, savedInstanceState);
    }

    protected override void OnActivityResult(int requestCode, Result resultCode, Intent intent)
    {
        if (NativeMedia.Platform.CheckCanProcessResult(requestCode, resultCode, intent))
            NativeMedia.Platform.OnActivityResult(requestCode, resultCode, intent);

        base.OnActivityResult(requestCode, resultCode, intent);
    }   
}
dimonovdd commented 1 year ago

need more information