Skip to content

Make CameraView and ICameraView easier to use correctly. #197

@jasells

Description

@jasells

Working with this lib my team has found several issues that could be improved.

  1. the Command creation in example MVVM code should/could be integrated into the CameraView itself to make it easier to use by simply binding to the commands in application code instead of every application having to re-create this. https://github.com/hjam40/Camera.MAUI/blob/master/Camera.MAUI.Test/MVVM/CameraViewModel.cs

  2. ICameraView is virtually useless as it lacks most of the public members.

  3. Several of the open issues relate to the commands for Async-method access/binding not being included, and the way the Cameras collection loads async (or at least after the view is on screen and binding has already run), combined with AutoStartPreviewProperty and AutoStartRecordingProperty not usable until after the .Camera property is set AND they hide the async methods inside of PropertyChanged event handlers. This hiding can cause crashes when navigating away from a page hosting this view since there's no way to really await the stopCamera()...

I'll see if I have time to push up a branch to start at least addressing # 2 above. We are currently wrapping this view in our own view to allow injecting a service to redirect some of these issues, and this interface is a starting point to allow for that.

public interface ICameraViewEx : Camera.MAUI.ICameraView
{
    /// <summary>
    /// The camera view is currently mirroring the image.
    /// </summary>
    bool MirroredImage { get; set; }

    Task<CameraResult> StartRecordingAsync(string file, Size Resolution = default(Size));

    Task<CameraResult> StopCameraAsync();

    int NumCamerasDetected { get; }

    ObservableCollection<CameraInfo> Cameras { get; }

    int NumMicrophonesDetected { get; }

    ObservableCollection<MicrophoneInfo> Microphones { get; }

    bool AutoStartPreview { get; set; } 
    

}

The best options for adding async-commands are covered here:
https://stackoverflow.com/questions/72277317/asynccommand-in-net-maui

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions