Repository navigation
Description
Version
Media3 1.11.1
More version details
Reproduced on a device with media3-cast 1.9.0 and 1.11.1, and play-services-cast-framework:22.1.0. By reading the source, the same code path is still present on main (@ 31bb0d1), which I haven't run.
Devices that reproduce the issue
Pixel 10, Android 17, casting to a Google Nest Mini on the Default Media Receiver (CC1AD845).
Devices that do not reproduce the issue
n/a. It doesn't depend on the device, only on the receiver already having media when the new load is sent.
Reproducible in the demo app?
Not tested
Reproduction steps
- Start a Cast session to a Default Media Receiver and play any item on the
CastPlayer. - Pause it, so
playWhenReady == false. - Replace the playlist and start playback right away, on the main thread:
A small delay between
castPlayer.setMediaItems(listOf(otherItem)) castPlayer.prepare() castPlayer.play()setMediaItemsandplay()makes no difference, as long asplay()comes before the receiver reports the new media. We saw it withplay()about 5 ms later.
Expected result
The new item starts playing, as it would on ExoPlayer.
Actual result
The new item loads on the receiver but stays paused, and getPlayWhenReady() goes back to false. Calling play() again afterwards works.
With receiver-side logging (MediaStatus.toJson()), every time:
- The load goes out with
autoplay = false.setMediaItemsbuilds theMediaLoadRequestDatawithsetAutoplay(getPlayWhenReady()), which is stillfalseat that point. play()finds a non-nullgetMediaStatus(), the previous item's status, so it callsremoteMediaClient.play()right away. That request carries the previousmediaSessionId, and the receiver rejects it:W/MediaControlChannel: received unexpected error: Invalid Request.- The receiver reports the new media with a new
mediaSessionId(for example 16 → 17),playerStatePAUSED. updatePlayerStateAndNotifyIfChangedsetsplayWhenReadyfrom!remoteMediaClient.isPaused(), so it becomesfalse.
The relevant code:
setPlayWhenReadyin 1.11.1,RemoteCastPlayer.java#L630-L661. It only skips the RPC whengetMediaStatus() == null. The comment there says that in that case the value "is used to populate autoplay when the client loads media". So the case where nothing is loaded yet is handled, but not the case where a previous item is still loaded and a new load is in flight.- The autoplay flag is read once, when the load is built:
setAutoplay(getPlayWhenReady()). - On
main, the newCastQueueOrchestrator(from [Cast] Adding media items too soon after setting media items drops added items #3272) readsPlayerTransferStatewhen it dispatches the load. A load into an idle queue is dispatched immediately, though, andsetPlayWhenReadystill callsremoteMediaClient.play()directly instead of going through the orchestrator. So the order above looks unchanged.
When it does not happen:
- If the player was already playing, the load goes out with
autoplay = true, and the lostplay()doesn't matter. - On a fresh session with no media,
getMediaStatus()is null, so the flag goes into the load's autoplay as intended.
Workaround we use: we note the receiver's mediaSessionId before the load, remember the last user play()/pause() made while the load is in flight, and set playWhenReady again once a status with a new mediaSessionId arrives. It works, but it depends on MediaStatus.toJson() for the session id.
Possible fix: while a load or queue replacement is pending, let setPlayWhenReady update the pending load's autoplay (if it hasn't been sent yet), or defer the play/pause until the receiver reports the new media, for example by queuing it behind the load in CastQueueOrchestrator.
Related, but different: #3373 (failures of these RPCs weren't logged; they are now in 1.12.0-alpha01) and #3272 (queue mutations racing a load).
Media
Not content-dependent. We saw it with live MP3 streams and with regular MP3 files.
Bug Report
- You will email the zip file produced by
adb bugreportto android-media-github@google.com after filing this issue.
Activity
Defer RemoteCastPlayer play/pause until an in-flight load completes
tanay187 commentedon Nov 16, 2026
@Vashiru Thanks for reporting! I shall have an update soon.
Internal tracker: b/573176376