WindowsAppSDK icon indicating copy to clipboard operation
WindowsAppSDK copied to clipboard

CameraCaptureUI API Implementation

Open Saharsh979 opened this issue 1 year ago • 9 comments

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

Saharsh979 avatar Oct 03 '24 12:10 Saharsh979

/azp run

Saharsh979 avatar Oct 03 '24 12:10 Saharsh979

Azure Pipelines successfully started running 1 pipeline(s).

azure-pipelines[bot] avatar Oct 03 '24 12:10 azure-pipelines[bot]

/azp run

Saharsh979 avatar Oct 14 '24 11:10 Saharsh979

Azure Pipelines successfully started running 1 pipeline(s).

azure-pipelines[bot] avatar Oct 14 '24 11:10 azure-pipelines[bot]

/azp run

Saharsh979 avatar Oct 15 '24 05:10 Saharsh979

Azure Pipelines successfully started running 1 pipeline(s).

azure-pipelines[bot] avatar Oct 15 '24 05:10 azure-pipelines[bot]

Please add containment in the current PR or in a follow up PR.

AjitSurana avatar Oct 18 '24 08:10 AjitSurana

/azp run

Saharsh979 avatar Oct 20 '24 15:10 Saharsh979

Azure Pipelines successfully started running 1 pipeline(s).

azure-pipelines[bot] avatar Oct 20 '24 15:10 azure-pipelines[bot]

/azp run

Saharsh979 avatar Oct 22 '24 10:10 Saharsh979

Azure Pipelines successfully started running 1 pipeline(s).

azure-pipelines[bot] avatar Oct 22 '24 10:10 azure-pipelines[bot]

/azp run

Saharsh979 avatar Oct 27 '24 17:10 Saharsh979

Azure Pipelines successfully started running 1 pipeline(s).

azure-pipelines[bot] avatar Oct 27 '24 17:10 azure-pipelines[bot]

/azp run

Saharsh979 avatar Oct 29 '24 17:10 Saharsh979

Azure Pipelines successfully started running 1 pipeline(s).

azure-pipelines[bot] avatar Oct 29 '24 17:10 azure-pipelines[bot]