Maui: [BUG] Crash when cleaning up MediaElement on Windows
Is there an existing issue for this?
- I have searched the existing issues
Did you read the “Reporting a bug” section on Contributing file?
- I have read the “Reporting a bug” section on Contributing file: https://github.com/CommunityToolkit/Maui/blob/main/CONTRIBUTING.md#reporting-a-bug
Current Behavior
- Follow the guide at MediaElement announcement blog post to create a very simple page to play a movie from an internet uri.
- Start app on net7.0-windows10.0.19041.0
- Navigate to the movie page
- Browse back
Expected Behavior
App navigates back and resources are cleaned up
Steps To Reproduce
App navigates back and a crash occurs
System.Runtime.InteropServices.COMException (0x80004004): Operation aborted (0x80004004 (E_ABORT))
at WinRT.ExceptionHelpers.<ThrowExceptionForHR>g__Throw|20_0(Int32 hr)
at ABI.Windows.Media.Playback.IMediaPlayerMethods.get_Position(IObjectReference _obj)
at Windows.Media.Playback.MediaPlayer.get_Position()
at CommunityToolkit.Maui.Core.Views.MediaManager.PlatformUpdatePosition()
at CommunityToolkit.Maui.Core.Views.MediaManager.UpdateStatus()
at CommunityToolkit.Maui.Core.Handlers.MediaElementHandler.MapStatusUpdated(MediaElementHandler handler, MediaElement MediaElement, Object args)
at Microsoft.Maui.Handlers.ElementHandler.Invoke(String command, Object args)
at CommunityToolkit.Maui.Views.MediaElement.OnTimerTick(Object sender, EventArgs e)
at Microsoft.Maui.Dispatching.DispatcherTimer.OnTimerTick(DispatcherQueueTimer sender, Object args)
at WinRT._EventSource_global__Windows_Foundation_TypedEventHandler_global__Microsoft_UI_Dispatching_Dispatcher
QueueTimer__object_.EventState.<GetEventInvoke>b__1_0(DispatcherQueueTimer sender, Object args)
at ABI.Windows.Foundation.TypedEventHandler`2.Do_Abi_Invoke[TSenderAbi,TResultAbi](Void* thisPtr, TSenderAbi sender, TResultAbi args)
Link to public reproduction project repository
https://github.com/wldevries/MauiMediaElementCrash
Environment
- .NET MAUI CommunityToolkit: 4.0.0
- OS: Windows 10 Build 10.0.19045.2546
- .NET MAUI: no idea.. part of VS 2022 17.4.4
- .NET MAUI MediaElement: 1.0.1
Anything else?
No response
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 15 (8 by maintainers)
Tested with version 1.0.0-build-1002.87588 and DiconnectHander doesn’t throw exception anymore.
I tried it. It appears to properly dispose of MediaElement. I get no errors. Does not solve my issue of after playing two video going and trying to play a third still fails to open. It tries and platform shows video controls but stream never opens. I have example in my bug report of how to show bug and sample is provided. I have tested the fix and can verify no errors on disconnecting handler. But I still cant play three video’s in a row.
My issue only affects Windows. It is still unresolved. But the bug with media element handler disconnect is fixed from this PR.
I had same issue till I did a null check for sender like this.
inside xaml:
inside xaml.page.cs
Event args goes off fairly often and you don’t want it to trigger accidently. Try adding above null check and see if that helps. I had exact same issue and this fixed it for me. This is example and the relavent code in xaml is: