Skip to content

Defer RemoteCastPlayer play/pause until an in-flight load completes - #3558

Open
Vashiru wants to merge 1 commit into
androidx:mainfrom
Vashiru:cast-defer-play-during-load
Open

Vashiru wants to merge 1 commit into
androidx:mainfrom
Vashiru:cast-defer-play-during-load

Conversation

@Vashiru

@Vashiru Vashiru commented Nov 16, 2026

Copy link
Copy Markdown

Fixes #3557.

Problem: With media already loaded on the receiver and the player paused, setMediaItems(...) followed by play() loads the new item paused.

Cause: setMediaItems dispatches the load right away, with autoplay = false. play() then sees the previous item's MediaStatus and calls remoteMediaClient.play() while the load is still in flight. That request targets the media session the load is replacing, so the receiver rejects it. The next status update reports the new item as paused and resets playWhenReady to false.

Fix: CastQueueOrchestrator now tracks whether the active operation is a load (setMediaItems, addMediaItems into an empty receiver queue, or a reload from the ended state). While one is in flight, setPlayWhenReady keeps playWhenReady masked and asks the orchestrator to run the play/pause once the load completes. Only the last call is sent, and if the load is replaced by another load, the call waits for the newer one. Without a load in flight, nothing changes.

Tests: New RemoteCastPlayerTest cases:

  • play() during a pending load is sent after the load and the player ends up playing.
  • play() then pause() during a load only sends pause().
  • A load replaced by another load (REPLACED result) sends play() only after the latest load completes.
  • play() with no load in flight is still sent right away.

The first three fail without the fix. All lib-cast unit tests pass.

🤖 Generated with Claude Code

@google-cla

google-cla Bot commented Nov 16, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Calling play() or pause() right after setMediaItems() sent the request
while the load was still in flight. The request targets the receiver's
current media session, which the load replaces, so the receiver
rejected it. The new media then loaded with the autoplay value from
before the call, and the next status update reset playWhenReady.

While a load is in flight, keep playWhenReady masked and send the
play/pause request once the load completes. If several calls are made,
only the last one is sent.

Issue: androidx#3557
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants