androidx / androidx/media

[Cast] Adding media items too soon after setting media items drops added items

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

@tanay187 is already working on this.

Since Jun 23, 2026.

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

Description

Version

Media3 1.10.1

More version details

No response

Devices that reproduce the issue

Pixel 8 Pro running Android 15

Devices that do not reproduce the issue

No response

Reproducible in the demo app?

Yes

Reproduction steps

While adding Casting to our app I noticed that adding media items seems to not work most of the time despite running the same code as our ExoPlayer. In our architecture, when the user taps on a media item, setMediaItem is called, then some async code is run to fetch the queue to build over the network and calls addMediaItems. This way, we play the selected item asap without the queue delaying it. However, despite the addMediaItems call definitely happening, the items are not added and the queue is just the single media item added via setMediaItem.

After some experimenting, I noticed that the addMediaItems works if I add a delay, so my guess that something wrong happens when you set and add media items too quickly when casting specifically. I've been able to replicate this in demo-cast as well. In PlayerManager.kt, change

public void addItem(MediaItem item) {
  mediaQueue.add(item);
  currentPlayer.addMediaItem(item);
}

To

public void addItem(MediaItem item) {
  MediaItem newItem = new MediaItem.Builder().setUri(item.localConfiguration.uri).setMediaMetadata(new MediaMetadata.Builder().setTitle("Test").build()).build();

  mediaQueue.add(item);
  mediaQueue.add(newItem);

  currentPlayer.setMediaItem(item);
  currentPlayer.addMediaItem(newItem);
}
  1. Run demo-cast
  2. Tap the top app bar cast button to start casting
  3. Tap the FAB and add any item

If you add a delay before calling addMediaItem e.g.

public void addItem(MediaItem item) {
  MediaItem newItem = new MediaItem.Builder().setUri(item.localConfiguration.uri).setMediaMetadata(new MediaMetadata.Builder().setTitle("Test").build()).build();

  mediaQueue.add(item);
  mediaQueue.add(newItem);

  currentPlayer.setMediaItem(item);
  handler.postDelayed(() -> currentPlayer.addMediaItem(newItem), 5000);
}

It is added as expected. It seems like maybe it's specifically setMediaItem + addMediaItem i.e. addMediaItem + addMediaItem seems okay.

Expected result

In the player, the skip button is tappable and tapping it skips to the next item

Actual result

In the player, the skip button is greyed out implying the added Test item was not added

Media

Any item via the FAB is okay in cast-demo

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.