Skip to content

[BUG] MediaElement: New "onPositionDiscontinuity" Method not implemented for new Android ExoPlayer refactor, causing crashes on mediaElement.Stop() - stub needs adding to MediaManager #2824

@jonmdev

Description

@jonmdev

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

I updated my app to the new Community Toolkit now using the new refactored MediaElement. This has introduced a new bug in Android, where at one point in my code, calling mediaElement.Stop() crashes the app with the warning:

Java.Lang.AbstractMethodError: 'Loading...'

Java.Lang.AbstractMethodError: 'abstract method "void androidx.media3.common.Player$Listener.onPositionDiscontinuity(androidx.media3.common.Player$PositionInfo, androidx.media3.common.Player$PositionInfo, int)" on receiver java.lang.Class<crc64ceb75e76f4b66147.MediaManager>'

CAUSE & SOLUTION

I asked ChatGPT what this likely represents, and its explanation was quite clear.

Suspected Cause

This appears to stem from incompatibility with newer versions of ExoPlayer, specifically the transition to AndroidX Media3, which refactored the Player.Listener interface to include additional abstract methods like onPositionDiscontinuity(PositionInfo, PositionInfo, int).

The class crc64ceb75e76f4b66147.MediaManager does not implement this newly required method, resulting in the crash.

Expected Behavior

MediaElement.Stop() should function without runtime exceptions and cleanly stop media playback.

Suggested Fix

Update the underlying implementation of MediaElement on Android to align with the latest AndroidX Media3 Player.Listener interface — ensuring all abstract methods (like onPositionDiscontinuity) are implemented.

🔍What is onPositionDiscontinuity?

In ExoPlayer / AndroidX Media3, Player.Listener is an interface that allows a class to receive playback events.

onPositionDiscontinuity(PositionInfo oldPosition, PositionInfo newPosition, int reason) is one of the newer methods in this interface — added as part of a major refactor in Media3 (ExoPlayer 2 → 3).

This method gets called when the player's playback position jumps (e.g., seeking, skipping ads, buffering discontinuities). It's used to notify listeners about timeline or position changes.

⚠️What does the error tell us, and how do we know it’s "not implemented"?

The error:

Java.Lang.AbstractMethodError: 
abstract method "void androidx.media3.common.Player$Listener.onPositionDiscontinuity(...)"
on receiver java.lang.Class<crc64ceb75e76f4b66147.MediaManager>

This error is not a compile-time issue — it only happens at runtime when the JVM (Dalvik/ART) tries to call that method.

What it means:

  • The object (MediaManager) is being used as a Player.Listener.
  • Media3 calls onPositionDiscontinuity(...) on it.
  • But MediaManager does not have that method implemented, so the JVM throws AbstractMethodError.

This is Java’s way of saying:

"You promised to provide this method, but when I went to call it, it wasn't there."

So how do we know this is the cause?

  1. Java.Lang.AbstractMethodError is only thrown when a non-abstract class fails to implement an abstract method from a superclass or interface.

  2. The method name in the error — onPositionDiscontinuity(Player$PositionInfo, Player$PositionInfo, int) — is part of the latest Player.Listener interface in Media3.

  3. The class crc64ceb75e76f4b66147.MediaManager is probably compiled against an older version of the interface (where this method didn't exist yet), and is now running against a newer version of Media3 where the method is mandatory.

📌 TL;DR

  • onPositionDiscontinuity is a required method in the latest Player.Listener interface (Media3).
  • The AbstractMethodError means the class claimed to implement the interface, but does not define this method.

CODE SOLUTION

I then showed ChatGPT the source code for MediaManager in Android and asked it if we then just need to add the stub to fix it, and if any other methods were missing. The reply was as follows

https://github.com/CommunityToolkit/Maui/blob/main/src/CommunityToolkit.Maui.MediaElement/Views/MediaManager.android.cs


The Java.Lang.AbstractMethodError you're seeing confirms that the class MediaManager implements the IPlayerListener interface (which maps to Player.Listener in Java), but does not implement all required methods as defined in the version of androidx.media3.common:common you are using at runtime.

✅ Answer Summary

Yes, you just need to add the missing method to your stub implementation in MediaManager.
The missing method is:

void onPositionDiscontinuity(Player.PositionInfo oldPosition, Player.PositionInfo newPosition, int reason)

🧩 What it Looks Like in C#

In your C# binding for IPlayerListener, the corresponding method is:

public void OnPositionDiscontinuity(Player.PositionInfo oldPosition, Player.PositionInfo newPosition, int reason) { }

This needs to be added to your MediaManager class to satisfy the runtime expectations of the Java interface.

🔍 Are There Any Other Missing Methods?

As of Media3 1.3.0+, these are critical additions not found in older versions:

void onPositionDiscontinuity(
    Player.PositionInfo oldPosition,
    Player.PositionInfo newPosition,
    @Player.DiscontinuityReason int reason);

void onSeekProcessed(); // optional but often invoked

2. Missing in your current stub:

❌ You are missing (at least):

public void OnPositionDiscontinuity(Player.PositionInfo oldPosition, Player.PositionInfo newPosition, int reason) {  }

✅ Summary for Fix

🛠️ Final Implementation Suggestion

Add this method to your MediaManager class:

public void OnPositionDiscontinuity(Player.PositionInfo oldPosition, Player.PositionInfo newPosition, int reason) { }

FIX IMPLEMENTATION

It is not easy for me to push changes or update the Community Toolkit. Can any contributor who has better control over this repository then please just push this update and update the Nuget to fix the omission? It seems pretty straightforward from the above if this all seems logical to you as well.

In other words, it appears we should add (1):

public void OnPositionDiscontinuity(Player.PositionInfo oldPosition, Player.PositionInfo newPosition, int reason) { }

and (2) also one for onSeekProcessed as it suggests that is new also and may avoid crashes to cover for that too.

We just need the single line stubs added as above then.

Thanks

Link to public reproduction project repository

https://github.com/CommunityToolkit/Maui/blob/main/src/CommunityToolkit.Maui.MediaElement/Views/MediaManager.android.cs

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions