CameraCaptureUI API Implementation
Validation Note: A microsoft employee must use /azp run to validate using the pipelines below.
API Spec: https://github.com/microsoft/WindowsAppSDK/pull/4721
Fixes : https://github.com/microsoft/WindowsAppSDK/issues/1034
API Design Overview
The CameraCaptureUI API allows desktop applications to effortlessly integrate native camera capture features across various Windows platforms. This proposal aims to address the limitations of the existing OS CameraCaptureUI, primarily designed for UWP, which poses challenges for desktop environments. Key issues include its reliance on CoreWindow and lack of support for IInitializeWithWindow, necessitating cumbersome workarounds.
This new API streamlines the integration of camera capture capabilities while ensuring feature parity across all Windows platforms supported by WinAppSDK, thus simplifying developers' workflows.
The CameraCaptureUI class provides a comprehensive UI for capturing audio, video, and photos. It allows customization of capture settings, including trimming video and adjusting camera settings.
Constructor:
- CameraCaptureUI(windowId) - Initializes a new CameraCaptureUI object with the specified window ID.
Properties
-
PhotoSettings: Manages photo capture settings.
-
VideoSettings: Manages video capture settings.
Methods
- CaptureFileAsync: Launches the capture UI and returns the resulting file.
This implementation ensures that the CameraCaptureUI API aligns closely with existing UWP functionality, only modifying the constructor to accept a WindowId.
Example C++ Code
This example shows how to use the CameraCaptureUI Class to take a picture.
// Get the WindowId for the window
Microsoft::UI::WindowId windowId = this->AppWindow().Id();
// Initialize CameraCaptureUI with a window handle
winrt::Microsoft::Windows::Media::Capture::CameraCaptureUI cameraUI(windowId);
// Configure Photo Settings
cameraUI.PhotoSettings().Format(CameraCaptureUIPhotoFormat::Jpeg);
cameraUI.PhotoSettings().AllowCropping(false);
// Capture a photo asynchronously
auto photo = co_await cameraUI.CaptureFileAsync(CameraCaptureUIMode::Photo);
// Assert the result
if (photo != nullptr)
{
// Log success if photo capture was successful
Log::Comment(L"Photo capture was successful.");
}
else
{
// Log error if photo capture failed or was canceled
Log::Error(L"Photo capture failed or was canceled.");
}
Testing
- Successful local build
- Produced a experimental NuGet package leveraging the aggregator build pipeline, and tested it using a sample app by calling the CaptureFileAsync API, which functioned as intended.
- Executed unit tests with the mock framework package, and everything performed as expected.
Note: The Interactive Experiences package has been incorporated as a dependency in the Foundation repo to utilize Microsoft.UI API features.
Pending Action Items:
- Ensure that Maestro recognizes the dependency updates being made to the Foundation branch (the Interactive Experiences package has been integrated into the Foundation repo)
- Implement support for C# projections.
- Update unit tests accordingly.
- Publishing Public/Private symbols
/azp run
Azure Pipelines successfully started running 1 pipeline(s).
/azp run
Azure Pipelines successfully started running 1 pipeline(s).
/azp run
Azure Pipelines successfully started running 1 pipeline(s).
Please add containment in the current PR or in a follow up PR.
/azp run
Azure Pipelines successfully started running 1 pipeline(s).
/azp run
Azure Pipelines successfully started running 1 pipeline(s).
/azp run
Azure Pipelines successfully started running 1 pipeline(s).
/azp run
Azure Pipelines successfully started running 1 pipeline(s).