Skip to content

[BUG] MediaElement crashing on iOS within CarouselView (again) #2890

@RomanTelexy

Description

@RomanTelexy

Is there an existing issue for this?

  • I have searched the existing issues

Did you read the "Reporting a bug" section on Contributing file?

Current Behavior

MediaElement crashes when created inside ItemTemplate of CarouselView with the following error:

System.InvalidOperationException: Cannot find current page   
at CommunityToolkit.Maui.Core.Views.MauiMediaElement..ctor(AVPlayerViewController playerViewController, MediaElement virtualView) 
in /_/src/CommunityToolkit.Maui.MediaElement/Views/MauiMediaElement.macios.cs:line 57   
at CommunityToolkit.Maui.Core.Handlers.MediaElementHandler.CreatePlatformView() 

Expected Behavior

MediaElement runs without issues on iOS

Steps To Reproduce

Open and build this demo:
https://github.com/RomanTelexy/MediaElement.Crash.Demo.iOS

NOTE: Because this is iOS only bug, you'll need to provide your own certificate in order to run it on iOS.

I tested it on iPad A16 (iPad OS 18.4 & 18.5), as well as on iPad A16 Emulator (same OS versions)

Link to public reproduction project repository

https://github.com/RomanTelexy/MediaElement.Crash.Demo.iOS

Environment

- .NET MAUI CommunityToolkit:6.1.2
- OS:iPad OS 18.4 & 18.5, running from Visual Studio 2022 on Win 11 (v 24H2)
- .NET MAUI:9.0.110

Anything else?

This seems like a regression of this issue. It also came back here.

I think the culprit is inside TryGetCurrentPage which runs inside constructor, more specifically this line doesn't have a desired effect, when not using Shell navigation. window.Navigation.NavigationStack only displays correct data after the page was constructed. For instance, if you check the same NavigationStack inside OnAppearing - you will be able to find a page.
I have a detailed demo of this behavior over here:
https://github.com/RomanTelexy/Maui.NavigationDemo

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions