Skip to content

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

Closed

Description

@jqi26

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

Activity

  1. AquilesCanta commented on Jun 12, 2026

    @AquilesCanta
    Contributor

    Thanks for reporting!

    Internal tracker: b/523188752

  2. AquilesCanta commented on Jun 23, 2026

    @AquilesCanta
    Contributor

    We are working on this

  3. tanay187 commented on Oct 9, 2026

    @tanay187
    Contributor

    @jqi26 thanks for reporting the issue! The fix for this has been submitted and would be available with the next media3 release or you could clone the repo to try it out locally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions