Skip to content

Commit

Permalink
Fix camera still being used after closing camera preview page (#1638)
Browse files Browse the repository at this point in the history
<!--- Provide a general summary of your changes in the Title above -->

## Description
<!--- Describe your changes in detail -->
When leaving the camera capture page, the camera now no longer is in
use.

## Motivation and Context
<!--- Why is this change required? What problem does it solve? -->
<!--- If it fixes an open issue, please link to the issue here. -->
Closes #1610
## How Has This Been Tested?
<!--- Please describe in detail how you tested your changes. -->
<!--- Include details of your testing environment, and the tests you ran
to -->
<!--- see how your change affects other areas of the code, etc. -->

## Screenshots (if appropriate):

## Types of changes
<!--- What types of changes does your code introduce? Put an `x` in all
the boxes that apply: -->
- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
  • Loading branch information
marcelwgn authored Dec 6, 2024
1 parent b5b6d88 commit d24c449
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions WinUIGallery/ControlPages/CaptureElementPreviewPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using Windows.Storage.Streams;
using System.ComponentModel;
using WinUIGallery.Helper;
using System.Threading.Tasks;

namespace WinUIGallery.ControlPages
{
Expand All @@ -38,6 +39,17 @@ public CaptureElementPreviewPage()
captureContainer.Children.Remove(sv);
captureContainer.Children.Add(expandToFillContainer);
expandToFillContainer.Children.Add(sv);

this.Unloaded += this.CaptureElementPreviewPage_Unloaded;
}

private void CaptureElementPreviewPage_Unloaded(object sender, RoutedEventArgs e)
{
// Needs to run as task to unblock UI thread
if (mediaCapture != null)
{
new Task(mediaCapture.Dispose).Start();
}
}

private MediaFrameSourceGroup mediaFrameSourceGroup;
Expand Down

0 comments on commit d24c449

Please sign in to comment.