Skip to content

Commit

Permalink
Fix dispose on MediaElement on Windows (#1304)
Browse files Browse the repository at this point in the history
added handler to dispose the windows view on the right moment

Co-authored-by: Brandon Minnick <[email protected]>
  • Loading branch information
pictos and brminnick authored Jul 27, 2023
1 parent c04539c commit bf69c6f
Showing 1 changed file with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,27 @@ protected override MauiMediaElement CreatePlatformView()
protected override void DisconnectHandler(MauiMediaElement platformView)
{
Dispose();
platformView.Dispose();
UnloadPlatformView(platformView);
base.DisconnectHandler(platformView);
}

static void UnloadPlatformView(MauiMediaElement platformView)
{
if (platformView.IsLoaded)
{
platformView.Unloaded += OnPlatformViewUnloaded;
}
else
{
platformView.Dispose();
}

static void OnPlatformViewUnloaded(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
{
var mediaElement = (MauiMediaElement)sender;

mediaElement.Unloaded -= OnPlatformViewUnloaded;
mediaElement.Dispose();
}
}
}

0 comments on commit bf69c6f

Please sign in to comment.