Skip to content
Open
Show file tree
Hide file tree
Changes from 7 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 @@ -24,7 +24,7 @@
<ApplicationVersion>1</ApplicationVersion>

<!-- To develop, package, and publish an app to the Microsoft Store, see: https://aka.ms/MauiTemplateUnpackaged -->
<WindowsPackageType>None</WindowsPackageType>
<WindowsPackageType>MSIX</WindowsPackageType>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>

<NoWarn>IL2026</NoWarn>
Expand Down
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.", "Video capturing will not be available without the Microphone permission.", "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,7 +1,7 @@
{
"profiles": {
"Windows Machine": {
"commandName": "Project",
"commandName": "MsixPackage",
"nativeDebugging": false
}
}
Expand Down
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;

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;

// unpackaged apps always have the capability
var isMicrophoneCapable =
AppInfo.PackagingModel != AppPackagingModel.Packaged ||
Permissions.IsCapabilityDeclared("microphone");

if (isMicrophoneCapable)
{
microphonePermissionStatus = await Permissions.CheckStatusAsync<Permissions.Microphone>();
}

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