hjam40 / Camera.MAUI

A CameraView Control for preview, take photos and control the camera options
MIT License
449 stars 72 forks source link

Feature Request: Option to record Video without Audio #143

Open blago83 opened 6 months ago

blago83 commented 6 months ago

Great work on the plugin!

We need an option to record video only. Asking for Microphone permission is causing additional complications for our design. Also we can't share screen in Teams and record video meantime (The camera is blank). It's important when we do demo presentations.

blago83 commented 6 months ago

I propose the following changes to be included. iOS tested and works great. Android is not tested.

CamaraView.cs

 public static readonly BindableProperty DisableAudioProperty = BindableProperty.Create(nameof(DisableAudio), typeof(bool), typeof(bool), false);

    /// <summary>
    /// Turns the Microphone on and off before recording a video. This is a bindable property.
    /// </summary>
    public bool DisableAudio
    {
        get { return (bool)GetValue(DisableAudioProperty); }
        set { SetValue(DisableAudioProperty, value); }
    }

MauiCameraView(Apple)

  1. Check for DisableAudio before adding micDevices

            if (!cameraView.DisableAudio)
            {
                foreach (var device in micDevices)
                    cameraView.Microphones.Add(new MicrophoneInfo { Name = device.LocalizedName, DeviceId = device.UniqueID });
            }
  2. Check for DisableAudio in StartRecordingAsync(string file, Size Resolution)

               await CameraView.RequestPermissions(!cameraView.DisableAudio, true)
    
                    if (!cameraView.DisableAudio)
                    {
                        micDevice = micDevices.First(d => d.UniqueID == cameraView.Microphone.DeviceId);
                        micInput = new AVCaptureDeviceInput(micDevice, out err);
                        captureSession.AddInput(micInput);
                    }

MauiCameraView(Android)

  1. InitDevices

            if (!cameraView.DisableAudio)
            {
                foreach (var device in audioManager.Microphones)
                {
                    cameraView.Microphones.Add(new MicrophoneInfo { Name = "Microphone " + device.Type.ToString() + " " + device.Address, DeviceId = device.Id.ToString() });
                }
            }
  2. StartRecordingAsync(string file, Microsoft.Maui.Graphics.Size Resolution)

await CameraView.RequestPermissions(!cameraView.DisableAudio, true)

                        if (!cameraView.DisableAudio)
                            mediaRecorder.SetAudioSource(AudioSource.Mic);

Use the control like that:

<cv:CameraView x:Name="cameraView" CamerasLoaded="CamerasLoaded" DisableAudio="True" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" />