Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ protected override async void OnAppearing()
var microphonePermissionsRequest = await Permissions.RequestAsync<Permissions.Microphone>();
if (microphonePermissionsRequest is not PermissionStatus.Granted)
{
await Shell.Current.CurrentPage.DisplayAlertAsync("Microphone permission is not granted.", "Please grant the permission to use this feature.", "OK");
return;
await Shell.Current.CurrentPage.DisplayAlertAsync("Microphone permission is not granted.", "Audio recording will not be available without the Microphone permission, and captured video will be silent.", "OK");
}
}
catch (FileNotFoundException) when (OperatingSystem.IsWindows()) // Unpackaged Windows Apps do not generate the required file AppxManifest.xml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
<Capabilities>
<rescap:Capability Name="runFullTrust" />
<DeviceCapability Name="microphone"/>
<DeviceCapability Name="webcam"/>
</Capabilities>

</Package>
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using CommunityToolkit.Maui.Core;
Comment thread
TheCodeTraveler marked this conversation as resolved.
Comment thread
TheCodeTraveler marked this conversation as resolved.
using Windows.Devices.Enumeration;
using Windows.Media;
using Windows.Media.Capture;
Comment thread
VladislavAntonyuk marked this conversation as resolved.

namespace CommunityToolkit.Maui.Extensions;
Expand All @@ -13,20 +14,40 @@ public static async Task UpdateAvailability(this ICameraView cameraView, Cancell
cameraView.IsAvailable = videoCaptureDevices.Count > 0;
}

public static Task InitializeCameraForCameraView(this MediaCapture mediaCapture, string deviceId, CancellationToken token)
public static async Task InitializeCameraForCameraView(this MediaCapture mediaCapture, string deviceId, CancellationToken token)
{
try
{
return mediaCapture.InitializeAsync(new MediaCaptureInitializationSettings
var settings = new MediaCaptureInitializationSettings
{
VideoDeviceId = deviceId,
PhotoCaptureSource = PhotoCaptureSource.Auto
}).AsTask(token);
};

PermissionStatus microphonePermissionStatus = PermissionStatus.Unknown;

// Permission checks require a packaged app manifest on Windows
var isMicrophoneCapable =
AppInfo.PackagingModel == AppPackagingModel.Packaged &&
Permissions.IsCapabilityDeclared("microphone");

if (isMicrophoneCapable)
{
microphonePermissionStatus = await Permissions.CheckStatusAsync<Permissions.Microphone>();
}
Comment thread
AopBK marked this conversation as resolved.

if (!isMicrophoneCapable || microphonePermissionStatus != PermissionStatus.Granted)
{
settings.StreamingCaptureMode = StreamingCaptureMode.Video;
settings.MediaCategory = MediaCategory.Media;
settings.AudioProcessing = AudioProcessing.Default;
}

await mediaCapture.InitializeAsync(settings).AsTask(token);
}
catch (System.Runtime.InteropServices.COMException)
{
// Camera already initialized
return Task.CompletedTask;
}
}
}
Loading