[Cast] Adding media items too soon after setting media items drops added items
@tanay187 is already working on this.
Since Jun 23, 2026.
- 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);
}
- Run
demo-cast - Tap the top app bar cast button to start casting
- 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 bugreportto android-media-github@google.com after filing this issue.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.