### Complete Mac Catalyst Info.plist Example Source: https://github.com/microsoftdocs/communitytoolkit/blob/main/docs/maui/views/camera-view.md A comprehensive example of an Info.plist file for Mac Catalyst, including camera and microphone usage descriptions. ```xml UIDeviceFamily 1 2 UIRequiredDeviceCapabilities arm64 UISupportedInterfaceOrientations UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight UISupportedInterfaceOrientations~ipad UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight XSAppIconAssets Assets.xcassets/appicon.appiconset NSCameraUsageDescription PROVIDE YOUR REASON HERE NSMicrophoneUsageDescription PROVIDE YOUR REASON HERE ``` -------------------------------- ### Start Camera Preview using C# Method Source: https://github.com/microsoftdocs/communitytoolkit/blob/main/docs/maui/views/camera-view.md This C# code demonstrates how to programmatically start the camera preview using the StartCameraPreview method of the CameraView. It includes basic error handling and a cancellation token with a timeout. ```csharp async void HandleStartCameraPreviewButtonTapped(object? sender, EventArgs e) { try { var startCameraPreviewTCS = new CancellationTokenSource(TimeSpan.FromSeconds(3)); // Use the Camera field defined above in XAML (``) await Camera.StartCameraPreview(startCameraPreviewTCS.Token); } catch(Exception e) { // Handle Exception Trace.WriteLine(e); } } ``` -------------------------------- ### Initialize CameraHelper and Start Capture Source: https://github.com/microsoftdocs/communitytoolkit/blob/main/docs/windows/Helpers/CameraHelper.md Creates a Camera Helper instance and starts capturing video frames from an available frame source. Handles initialization success or failure and subscribes to frame arrival events. ```csharp // Creates a Camera Helper and gets video frames from an available frame source. using CommunityToolkit.WinUI.Helpers.CameraHelper; CameraHelper _cameraHelper = new CameraHelper(); var result = await _cameraHelper.InitializeAndStartCaptureAsync(); // Camera Initialization and Capture failed for some reason if(result != CameraHelperResult.Success) { // get error information var errorMessage = result.ToString(); } else { // Subscribe to get frames as they arrive _cameraHelper.FrameArrived += CameraHelper_FrameArrived; } private void CameraHelper_FrameArrived(object sender, FrameEventArgs e) { // Gets the current video frame VideoFrame currentVideoFrame = e.VideoFrame; // Gets the software bitmap image SoftwareBitmap softwareBitmap = currentVideoFrame.SoftwareBitmap; } ``` -------------------------------- ### CameraHelper with Specific Frame Source Group Source: https://github.com/microsoftdocs/communitytoolkit/blob/main/docs/windows/Helpers/CameraHelper.md This example shows how to get available frame source groups, select one, and then initialize the CameraHelper with that specific group. It also demonstrates setting a different frame source format. ```APIDOC ## CameraHelper with Specific Frame Source Group ### Description Demonstrates how to retrieve all available camera frame source groups, select a preferred one, and initialize the CameraHelper with it. It also includes an optional step to set a specific frame format for the preview stream. ### Method `GetFrameSourceGroupsAsync()`, `InitializeAndStartCaptureAsync()`, `PreviewFrameSource.SetFormatAsync()` ### Parameters `GetFrameSourceGroupsAsync()`: None `InitializeAndStartCaptureAsync()`: None `PreviewFrameSource.SetFormatAsync(MediaFrameFormat format)`: The desired `MediaFrameFormat` to set. ### Request Example ```csharp using CommunityToolkit.WinUI.Helpers.CameraHelper; using System.Linq; var availableFrameSourceGroups = await CameraHelper.GetFrameSourceGroupsAsync(); if(availableFrameSourceGroups != null) { CameraHelper cameraHelper = new CameraHelper() { FrameSourceGroup = availableFrameSourceGroups.FirstOrDefault() }; var result = await cameraHelper.InitializeAndStartCaptureAsync(); if(result == CameraHelperResult.Success) { cameraHelper.FrameArrived += CameraHelper_FrameArrived; var newFormat = cameraHelper.FrameFormatsAvailable.Find((format) => format.VideoFormat.Width == 640); if (newFormat != null) { await cameraHelper.PreviewFrameSource.SetFormatAsync(newFormat); } } } ``` ### Response #### Success Response (CameraHelperResult.Success) Indicates successful initialization and capture start with the selected frame source group and format. #### Error Response (Other CameraHelperResult values) Indicates a failure during initialization or capture. The specific error can be obtained from the `result.ToString()`. ``` -------------------------------- ### Settings Page Example Code-Behind Source: https://github.com/microsoftdocs/communitytoolkit/blob/main/docs/windows/SettingsControls/SettingsExpander.md Provides the C# code-behind for the Settings page example, initializing the page and its data context. ```csharp public sealed partial class SettingsPageExample : Page { public SettingsPageExample() { this.InitializeComponent(); } } ``` -------------------------------- ### Set HorizontalAlignment to Start using Start Extension Source: https://github.com/microsoftdocs/communitytoolkit/blob/main/docs/maui/markup/extensions/view-extensions.md Use the `Start()` extension method to set the `HorizontalOptions` property to `LayoutOptions.Start`. ```csharp new Label().Start() ``` -------------------------------- ### CameraView XAML Setup for Video Recording Source: https://github.com/microsoftdocs/communitytoolkit/blob/main/docs/maui/views/camera-view.md This XAML sets up the CameraView and includes buttons to start and stop video recording using commands. Ensure the `StartVideoRecordingCommand` and `StopVideoRecordingCommand` are bound to the CameraView. ```xaml