Skip to content

[BUG] MediaElement Android crashes when OnFullscreenButtonClick #2044

Closed
@vikher

Description

@vikher

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

The Android app crashes when the fullscreen button is clicked.

Expected Behavior

The app should not crash when the fullscreen button is clicked.

Steps To Reproduce

Use MediaElement version 3.1.0.
Click the fullscreen button mainly on a Galaxy S23 Ultra, Galaxy S22 Ultra, or Pixel 8 Pro.

Link to public reproduction project repository

https://github.com/vikher/testmedia

Environment

- .NET MAUI CommunityToolkit Version 9.0.2
- OS: net8.0-android
- .NET MAUI: MauiVersion 8.0.70
- CommunityToolkit.Maui.MediaElement Version 3.1.0

Anything else?

  • Occurs mostly on Galaxy S23 Ultra, Galaxy S22 Ultra, and Pixel 8 Pro.
  • Reported by Visual Studio App Center.
  • I'm using MediaElement version 3.1.0 for Android because:
  1. Version 3.1.1 breaks fullscreen functionality.
  2. Versions 4.0+ causes the app to reopen on the last visited page and continue background audio, behavior that is not desired.
  3. Awaiting approval of CommunityToolkit/Maui PR #2039 to use the latest NuGet package.

Error Details:

Error: System.ObjectDisposedException
Message: ObjectDisposed_Generic ObjectDisposed_ObjectName_Name, CommunityToolkit.Maui.Core.Views.MauiMediaElement

Xamarin Exception Stack:
System.ObjectDisposedException: ObjectDisposed_Generic
ObjectDisposed_ObjectName_Name, CommunityToolkit.Maui.Core.Views.MauiMediaElement
  at Java.Interop.JniPeerMembers.AssertSelf(IJavaPeerable )
  at Java.Interop.JniPeerMembers.JniInstanceMethods.InvokeVirtualVoidMethod(String , IJavaPeerable , JniArgumentValue* )
  at Android.Views.ViewGroup.AddView(View )
  at CommunityToolkit.Maui.Core.Views.MauiMediaElement.OnFullscreenButtonClick(Object sender, FullscreenButtonClickEventArgs e)
  at Com.Google.Android.Exoplayer2.UI.StyledPlayerView.IFullscreenButtonClickListenerImplementor.OnFullscreenButtonClick(Boolean isFullScreen)
  at Com.Google.Android.Exoplayer2.UI.StyledPlayerView.IFullscreenButtonClickListenerInvoker.n_OnFullscreenButtonClick_Z(IntPtr jnienv, IntPtr native__this, Boolean isFullScreen)
  at Android.Runtime.DynamicMethodNameCounter.24(IntPtr , IntPtr , Boolean )

Code Context:

I'm using DisconnectMediaElementHandler method to dispose the media element, based on this discussion:

  public override void Stop()
  {
      base.Stop();
      DisconnectMediaElementHandler();
  }

private void DisconnectMediaElementHandler()
{
    mediaElement.Handler?.DisconnectHandler();
    mediaElement.Dispose();
}

The DisconnectMediaElementHandler method is executed when the page disappears, not when the fullscreen button is clicked, at least on Android.

I'm not using ContentPage_Unloaded because, on iOS, when the fullscreen button is clicked and it enters fullscreen mode, CnkContentPage_Unloaded gets called and disposes of the media element view.

        //DO NOT DO THIS IN IOS
        void ContentPage_Unloaded(System.Object sender, System.EventArgs e)
        {
            DisconnectMediaElementHandler();
        }

Additional Information:
There is no current way to trigger a specialized event in Maui when the fullscreen button is clicked.

The following screenshot from the app center
image

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingunverifiedwaiting for feedbackWaiting for a response from the author or the core team member📽️ MediaElementIssue/PR that has to do with MediaElement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions