[Cast] play() right after setMediaItems() is lost when the receiver already has media, so the new item loads paused

Abierto
#3,557 1 comentario 0 reacciones 1 asignado Ver en GitHub

Los mantenedores suelen responder en 4 días

@tanay187 ya está trabajando en esto.

Desde el 16/11/2026.

  • #3558 de @Vashiru — abierto

Evaluación

Este issue todavía no se ha evaluado.

Descripción

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
  1. Start a Cast session to a Default Media Receiver and play any item on the CastPlayer.
  2. Pause it, so playWhenReady == false.
  3. Replace the playlist and start playback right away, on the main thread:
    castPlayer.setMediaItems(listOf(otherItem))
    castPlayer.prepare()
    castPlayer.play()
    
    A small delay between setMediaItems and play() makes no difference, as long as play() comes before the receiver reports the new media. We saw it with play() 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:

  1. The load goes out with autoplay = false. setMediaItems builds the MediaLoadRequestData with setAutoplay(getPlayWhenReady()), which is still false at that point.
  2. play() finds a non-null getMediaStatus(), the previous item's status, so it calls remoteMediaClient.play() right away. That request carries the previous mediaSessionId, and the receiver rejects it:
    W/MediaControlChannel: received unexpected error: Invalid Request.
    
  3. The receiver reports the new media with a new mediaSessionId (for example 16 → 17), playerState PAUSED.
  4. updatePlayerStateAndNotifyIfChanged sets playWhenReady from !remoteMediaClient.isPaused(), so it becomes false.

The relevant code:

  • setPlayWhenReady in 1.11.1, RemoteCastPlayer.java#L630-L661. It only skips the RPC when getMediaStatus() == 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 new CastQueueOrchestrator (from #3272) reads PlayerTransferState when it dispatches the load. A load into an idle queue is dispatched immediately, though, and setPlayWhenReady still calls remoteMediaClient.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 lost play() 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 bugreport to [email protected] after filing this issue.
Lenguaje dominante
Java
Estrellas
3.1k
Forks
1k
Merge medio
6 d 4 h
PR fusionados (30 d)
5

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de androidx/media

Todos los issues de androidx/media

Issues similares

Más issues de Java

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.