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

[BUG] MediaElement not supported in a DataTemplate on MacCatalyst in an application using multiple windows #2249

Open
2 tasks done
brminnick opened this issue Oct 3, 2024 · 0 comments · May be fixed by #2260
Open
2 tasks done
Labels
bug Something isn't working 📽️ MediaElement Issue/PR that has to do with MediaElement

Comments

@brminnick
Copy link
Collaborator

brminnick commented Oct 3, 2024

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

On MacCatalyst, when using a MediaElement in a DataTemplate on a page that contains multiple ItemsViews, the following exception is thrown:

System.NotSupportedException: MediaElement is not currently supported in multi-window applications
   at CommunityToolkit.Maui.Core.Views.MauiMediaElement.TryGetCurrentPage(Page) in /Users/minnbran/GitHub/CommunityToolkit.Maui/src/CommunityToolkit.Maui.MediaElement/Views/MauiMediaElement.macios.cs:line 132
   at CommunityToolkit.Maui.Core.Views.MauiMediaElement..ctor(AVPlayerViewController playerViewController, MediaElement virtualView) in /Users/minnbran/GitHub/CommunityToolkit.Maui/src/CommunityToolkit.Maui.MediaElement/Views/MauiMediaElement.macios.cs:line 52
   at CommunityToolkit.Maui.Core.Handlers.MediaElementHandler.CreatePlatformView() in /Users/minnbran/GitHub/CommunityToolkit.Maui/src/CommunityToolkit.Maui.MediaElement/Handlers/MediaElementHandler.macios.cs:line 27
   at Microsoft.Maui.Handlers.ViewHandler`2[[CommunityToolkit.Maui.Views.MediaElement, CommunityToolkit.Maui.MediaElement, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[CommunityToolkit.Maui.Core.Views.MauiMediaElement, CommunityToolkit.Maui.MediaElement, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].OnCreatePlatformView()
   at Microsoft.Maui.Handlers.ViewHandler.OnCreatePlatformElement()
   at Microsoft.Maui.Handlers.ElementHandler.CreatePlatformElement()
   at Microsoft.Maui.Handlers.ElementHandler.SetVirtualView(IElement view)
   at Microsoft.Maui.Handlers.ViewHandler`2[[CommunityToolkit.Maui.Views.MediaElement, CommunityToolkit.Maui.MediaElement, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[CommunityToolkit.Maui.Core.Views.MauiMediaElement, CommunityToolkit.Maui.MediaElement, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].SetVirtualView(IView view)
   at Microsoft.Maui.Handlers.ViewHandler`2[[CommunityToolkit.Maui.Views.MediaElement, CommunityToolkit.Maui.MediaElement, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[CommunityToolkit.Maui.Core.Views.MauiMediaElement, CommunityToolkit.Maui.MediaElement, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].SetVirtualView(IElement view)
   at Microsoft.Maui.Controls.Element.SetHandler(IElementHandler newHandler)
   at Microsoft.Maui.Controls.Element.set_Handler(IElementHandler value)
   at Microsoft.Maui.Controls.VisualElement.Microsoft.Maui.IElement.set_Handler(IElementHandler value)
   at Microsoft.Maui.Platform.ElementExtensions.ToHandler(IElement view, IMauiContext context)
   at Microsoft.Maui.Platform.ElementExtensions.ToPlatform(IElement view, IMauiContext context)
   at Microsoft.Maui.Handlers.LayoutHandler.SetVirtualView(IView view)
   at Microsoft.Maui.Handlers.ViewHandler`2[[Microsoft.Maui.ILayout, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Platform.LayoutView, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].SetVirtualView(IElement view)
   at Microsoft.Maui.Controls.Element.SetHandler(IElementHandler newHandler)
   at Microsoft.Maui.Controls.Element.set_Handler(IElementHandler value)
   at Microsoft.Maui.Controls.VisualElement.Microsoft.Maui.IElement.set_Handler(IElementHandler value)
   at Microsoft.Maui.Platform.ElementExtensions.ToHandler(IElement view, IMauiContext context)
   at Microsoft.Maui.Platform.ElementExtensions.ToPlatform(IElement view, IMauiContext context)
   at Microsoft.Maui.Handlers.BorderHandler.UpdateContent(IBorderHandler handler)
   at Microsoft.Maui.Handlers.BorderHandler.MapContent(IBorderHandler handler, IBorderView border)
   at Microsoft.Maui.PropertyMapper`2.<>c__DisplayClass5_0[[Microsoft.Maui.IBorderView, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Handlers.IBorderHandler, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].<Add>b__0(IElementHandler h, IElement v)
   at Microsoft.Maui.PropertyMapper.UpdatePropertyCore(String key, IElementHandler viewHandler, IElement virtualView)
   at Microsoft.Maui.PropertyMapper.UpdateProperties(IElementHandler viewHandler, IElement virtualView)
   at Microsoft.Maui.Handlers.ElementHandler.SetVirtualView(IElement view)
   at Microsoft.Maui.Handlers.ViewHandler`2[[Microsoft.Maui.IBorderView, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Platform.ContentView, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].SetVirtualView(IView view)
   at Microsoft.Maui.Handlers.BorderHandler.SetVirtualView(IView view)
   at Microsoft.Maui.Handlers.ViewHandler`2[[Microsoft.Maui.IBorderView, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Platform.ContentView, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].SetVirtualView(IElement view)
   at Microsoft.Maui.Controls.Element.SetHandler(IElementHandler newHandler)
   at Microsoft.Maui.Controls.Element.set_Handler(IElementHandler value)
   at Microsoft.Maui.Controls.VisualElement.Microsoft.Maui.IElement.set_Handler(IElementHandler value)
   at Microsoft.Maui.Platform.ElementExtensions.ToHandler(IElement view, IMauiContext context)
   at Microsoft.Maui.Platform.ViewExtensions.ToHandler(IView view, IMauiContext context)
   at Microsoft.Maui.Controls.Handlers.Items.TemplateHelpers.GetHandler(View view, IMauiContext context)
   at Microsoft.Maui.Controls.Handlers.Items.TemplatedCell.Bind(DataTemplate template, Object bindingContext, ItemsView itemsView)
   at Microsoft.Maui.Controls.Handlers.Items.ItemsViewController`1[[Microsoft.Maui.Controls.CarouselView, Microsoft.Maui.Controls, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].UpdateTemplatedCell(TemplatedCell cell, NSIndexPath indexPath)
   at Microsoft.Maui.Controls.Handlers.Items.CarouselViewController.GetCell(UICollectionView collectionView, NSIndexPath indexPath)
   at UIKit.UIApplication.UIApplicationMain(Int32 argc, String[] argv, IntPtr principalClassName, IntPtr delegateClassName) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:line 61
   at UIKit.UIApplication.Main(String[] args, Type principalClass, Type delegateClass) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:line 96
   at CommunityToolkit.Maui.Sample.Program.Main(String[] args) in /Users/minnbran/GitHub/CommunityToolkit.Maui/samples/CommunityToolkit.Maui.Sample/Platforms/iOS/Program.cs:line 7

This is a known bug where a NotSupportedException is thrown:

throw new NotSupportedException("MediaElement is not currently supported in multi-window applications");

Expected Behavior

The MediaElement should work on MacCatalyst when using multiple windows.

Steps To Reproduce

  1. On an iOS device, launch CommunityToolkit.Maui.Sample
  2. In CommunityToolkit.Maui.Sample, navigate to Views -> MediaElementMultipleWindowPage
  3. Confirm app crashes

Link to public reproduction project repository

https://github.com/CommunityToolkit/Maui/tree/main/samples

Environment

- .NET MAUI CommunityToolkit MediaElement: v4.1.2
- OS: iOS
- .NET MAUI:
 [maui]
   Installation Source: SDK 8.0.400
   Manifest Version:    8.0.82/8.0.100
   Manifest Path:       /usr/local/share/dotnet/sdk-manifests/8.0.100/microsoft.net.sdk.maui/8.0.82/WorkloadManifest.json
   Install Type:        FileBased

Anything else?

This bug does not currently affect .NET 8, but may affect .NET 9 that deprecates Application.MainPage in favor of Application.CreateWindow(IApplicationState): https://learn.microsoft.com/en-us/dotnet/maui/whats-new/dotnet-9?view=net-maui-8.0#mainpage

@brminnick brminnick added bug Something isn't working unverified 📽️ MediaElement Issue/PR that has to do with MediaElement and removed unverified labels Oct 3, 2024
@ne0rrmatrix ne0rrmatrix linked a pull request Oct 5, 2024 that will close this issue
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working 📽️ MediaElement Issue/PR that has to do with MediaElement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant