Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Crash on iOS when using MediaElement inside a CarouselView (again) #2245

Merged
merged 3 commits into from
Oct 3, 2024

Conversation

brminnick
Copy link
Collaborator

@brminnick brminnick commented Oct 3, 2024

Description of Change

We initially fixed #1903 in PR #2187. However, it is back in iOS 18 (see screenshot).

The underlying bug is still the same: we need to add the AVPlayerViewController used by MediaElement as a child UIViewController to the MauiMediaElement UIView.

However, testing on iOS 18 shows that iOS has changed how it adds children to the UIViewControllerHierarchy, invalidating our previous work-around which was to wait for the DataTemplate to be initialized on the ItemsView event and then retrieve the ItemsViewController from ItemsView.Handler.

In this PR, we retrieve the ItemsViewController by traversing the Descendants of the current visible page, accomplishing the same goal.

Linked Issues

PR Checklist

  • Has a linked Issue, and the Issue has been approved(bug) or Championed (feature/proposal)
  • Has tests (if omitted, state reason in description)
  • Has samples (if omitted, state reason in description)
  • Rebased on top of main at time of PR
  • Changes adhere to coding standard

Additional information

This new approach has two downsides:

  1. If the page contains multiple ItemsView controls, we are unable to determine which ItemsView contains our MediaElement
  2. If the application contains multiple Windows, we are unable to determine which window contains our MediaElement

I believe both of these can be resolved with a bit more effort + time, and I've added a TODO for both scenarios in the code base.

However, these two scenarios are rare; I estimate that the vast majority of our users will not encounter this scenario. Therefore, I'd like to merge this bug fix now, and we can add the unsupported scenarios in a future PR.

// TODO: Add support for MediaElement in an ItemsView in a multi-window application
// TODO: Add support for MediaElement in an ItemsView on a Page containing multiple ItemsViews

However, since these two scenarios are very rare, I'd like to merge this as a hot fix today and then we can focus on fixing the edge cases.

@brminnick brminnick added the needs discussion Discuss it on the next Monthly standup label Oct 3, 2024
@brminnick brminnick removed the needs discussion Discuss it on the next Monthly standup label Oct 3, 2024
@brminnick brminnick merged commit ed06645 into main Oct 3, 2024
10 checks passed
@brminnick brminnick deleted the Allow-MediaElement-in-DataTemplate-on-iOS branch October 3, 2024 20:26
KeithBoynton added a commit to KeithBoynton/CommunityToolkitMaui that referenced this pull request Oct 31, 2024
* main:
  Update dependabot.yml
  Tell Dependabot to ignore required libraries from auto-updating
  [housekeeping] Automated PR to fix formatting errors (CommunityToolkit#2295)
  [housekeeping] Automated PR to fix formatting errors (CommunityToolkit#2292)
  Fix animation behavior hot reload (CommunityToolkit#2288)
  Update resourceManagement.yml
  [housekeeping] Automated PR to fix formatting errors (CommunityToolkit#2285)
  [Housekeeping] Update NuGet Packages (CommunityToolkit#2254)
  Implement the ability to Close a popup (CommunityToolkit#1688)
  Add `[Obsolete]` tag
  Fix FileSaver Progress (CommunityToolkit#2277)
  Ensure `TouchBehavior.LongPressCompleted` event fires when `LongPressCommand is null` (CommunityToolkit#2239)
  Add Popup Support for MediaElement on iOS + MacCatalyst (CommunityToolkit#2251)
  [Sample app] Add MediaElementMultipleWindowsPage (CommunityToolkit#2250)
  [Sample App] Add Second CarouselView to `MediaElementCarouselViewPage.xaml` (CommunityToolkit#2248)
  Fix Windows Autoplay bug (CommunityToolkit#2238)
  Fix Crash on iOS when using MediaElement inside a CarouselView (again) (CommunityToolkit#2245)
  Refactor URLs and improve logging consistency (CommunityToolkit#2228)
  Bump xunit from 2.9.1 to 2.9.2 in /samples (CommunityToolkit#2234)
  Increase `CommunityToolkitSampleApp_Xcode_Version` to `16`
@github-actions github-actions bot locked and limited conversation to collaborators Nov 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Crash on iOS when using MediaElement inside a CarouselView
2 participants