androidx / androidx/media

androidx.media3.session.PlayerWrapper.getCurrentTimelineWithCommandCheck() doesn't respect the absence of COMMAND_GET_TIMELINE correctly

Open
#2,665 2 comments 0 reactions 1 assignee View on GitHub

@marcbaechinger is already working on this.

Since Jul 28, 2025.

bug needs triage
Dominant language
Java
Stars
3k
Forks
955
Avg merge
12d 14h
Merged PRs (30d)
2

Description

Version

Media3 1.7.1 (same as 1.6.1)

More version details

No response

Devices that reproduce the issue

any

Devices that do not reproduce the issue

none

Reproducible in the demo app?

No

Reproduction steps

The issue seems to stem from androidx/media3/session/PlayerWrapper.java:713:

  public Timeline getCurrentTimelineWithCommandCheck() {
    if (isCommandAvailable(COMMAND_GET_TIMELINE)) {
      return getCurrentTimeline();
    } else if (isCommandAvailable(COMMAND_GET_CURRENT_MEDIA_ITEM)) {
      return getCurrentTimeline().isEmpty() // illegal access
          ? Timeline.EMPTY
          : new CurrentMediaItemOnlyTimeline(this);
    }
    return Timeline.EMPTY;
  }
  1. Create your own implementation of the androidx.media3.common.Player interface.
  2. Specify COMMAND_GET_CURRENT_MEDIA_ITEM as available and implement related interface functions
  3. Specifically do not specify COMMAND_GET_TIMELINE as available and do not implement related methods, specifically getCurrentTimeline(). For example throw UnsupportedOperationException
  4. Wrap your Player using PlayerWrapper, for example by using it in a MediaSession.Builder
Expected result

getCurrentTimeline() is not being called, as COMMAND_GET_TIMELINE is unavailable -> no crash is occuring

This would respect the documentation:

This method must only be called if COMMAND_GET_TIMELINE is available.

Actual result

getCurrentTimeline() is being called, even though COMMAND_GET_TIMELINE is unavailable -> the application crashes.

This does not respect the documentation:

This method must only be called if COMMAND_GET_TIMELINE is available.

stacktrace:

FATAL EXCEPTION: main
Process: com.example.myapp, PID: 19150
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myapp/com.example.myapp.MainActivity}: java.lang.UnsupportedOperationException: getCurrentTimeline() is not supported since COMMAND_GET_TIMELINE is not advertised
	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4280)
	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4467)
	at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:222)
	at android.app.servertransaction.TransactionExecutor.executeNonLifecycleItem(TransactionExecutor.java:133)
	at android.app.servertransaction.TransactionExecutor.executeTransactionItems(TransactionExecutor.java:103)
	at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:80)
	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2823)
	at android.os.Handler.dispatchMessage(Handler.java:110)
	at android.os.Looper.loopOnce(Looper.java:248)
	at android.os.Looper.loop(Looper.java:338)
	at android.app.ActivityThread.main(ActivityThread.java:9067)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:593)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:932)
Caused by: java.lang.UnsupportedOperationException: getCurrentTimeline() is not supported since COMMAND_GET_TIMELINE is not advertised
	at com.example.myapp.MyPlayer.getCurrentTimeline(MyPlayer.kt:45)
	at androidx.media3.common.ForwardingPlayer.getCurrentTimeline(ForwardingPlayer.java:527)
	at androidx.media3.session.PlayerWrapper.getCurrentTimeline(PlayerWrapper.java:706)
	at androidx.media3.session.PlayerWrapper.getCurrentTimelineWithCommandCheck(PlayerWrapper.java:713)
	at androidx.media3.session.MediaSessionLegacyStub$ControllerLegacyCbForBroadcast.onPlayerChanged(MediaSessionLegacyStub.java:1067)
	at androidx.media3.session.MediaSessionImpl.lambda$setPlayerInternal$1(MediaSessionImpl.java:295)
	at androidx.media3.session.MediaSessionImpl$$ExternalSyntheticLambda2.run(D8$$SyntheticClass:0)
	at androidx.media3.session.MediaSessionImpl.dispatchRemoteControllerTaskToLegacyStub(MediaSessionImpl.java:1070)
	at androidx.media3.session.MediaSessionImpl.setPlayerInternal(MediaSessionImpl.java:294)
	at androidx.media3.session.MediaSessionImpl.lambda$new$0(MediaSessionImpl.java:259)
	at androidx.media3.session.MediaSessionImpl$$ExternalSyntheticLambda31.run(D8$$SyntheticClass:0)
	at androidx.media3.common.util.Util.postOrRun(Util.java:800)
	at androidx.media3.session.MediaSessionImpl.<init>(MediaSessionImpl.java:256)
	at androidx.media3.session.MediaSession.createImpl(MediaSession.java:744)
	at androidx.media3.session.MediaSession.<init>(MediaSession.java:712)
	at androidx.media3.session.MediaSession$Builder.build(MediaSession.java:496)
	at com.example.myapp.MainActivity.onCreate(MainActivity.kt:23)
	at android.app.Activity.performCreate(Activity.java:9155)
	at android.app.Activity.performCreate(Activity.java:9133)
	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1521)
	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4262)
	... 13 more
Media

Not applicable

Bug Report
  • You will email the zip file produced by adb bugreport to android-media-github@google.com after filing this issue.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.