Skip to content

[Chromecast] Keep casting when Android stops the phone's media session - #6227

Open
sztomek wants to merge 3 commits into
mainfrom
fix/cast-state-player-ignore-stop
Open

sztomek wants to merge 3 commits into
mainfrom
fix/cast-state-player-ignore-stop

Conversation

@sztomek

@sztomek sztomek commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Description

With the Media3 media session enabled, Cast playback paused by itself about 2 seconds after you started casting an episode that was playing on the phone.

Cause: once casting starts, Android's System UI sees two media sessions from the app (the local Media3 session and the Cast session). It hides the local one and sends it a stop. While casting, the local session wraps CastStatePlayer, whose stop callback called pauseSuspend, so the receiver paused. The same stop also arrives about 0.4 s after every manual pause while casting, which logged a second playback_pause event.

The legacy media session already ignores stop while casting (#3394), and so does the Media3 forwarding player. This makes CastStatePlayer's stop callback do the same: it only writes a debug log line. Stopping a Cast session still goes through the Cast dialog and the Cast notification, and play/pause/media keys are unchanged.

Release builds with the media3_session flag off are not affected.

Testing Instructions

Use a debug build (Media3 session on) and a Cast receiver.

  1. Play an episode on the phone.
  2. Tap the Cast button and choose the receiver.
  3. ✅ The episode keeps playing on the receiver. On main it often pauses after about 2 seconds.
  4. Pause from the mini player. ✅ The receiver pauses, and only one playback_pause event is logged.
  5. Play/pause with the notification and the media keys, then Stop casting from the Cast dialog. ✅ All work as before.

Screenshots or Screencast

No screencap, change is behavioral

Checklist

  • If this is a user-facing change, I have added an entry in CHANGELOG.md
  • Ensure the linter passes (./gradlew spotlessApply to automatically apply formatting/linting)
  • I have considered whether it makes sense to add tests for my changes
  • All strings that need to be localized are in modules/services/localization/src/main/res/values/strings.xml
  • Any jetpack compose components I added or changed are covered by compose previews
  • I have updated (or requested that someone edit) the Event Horizon schema to reflect any new or changed analytics.

I have tested any UI changes...

  • with different themes
  • with a landscape orientation
  • with the device set to have a large display and font size
  • for accessibility with TalkBack

@claude

claude Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @sztomek's task in 33s —— View job


This looks correct. Ignoring stop in CastStatePlayer matches what the PocketCastsForwardingPlayer onStop already does while casting (MediaSessionManager.kt:330) and what the legacy session does. Play, pause and seek still reach PlaybackManager, and stopping a Cast session never went through this callback. SimpleBasePlayer re-reads getState() after handleStop, so the session goes back to READY and doesn't get stuck in IDLE.

Nits

  • modules/services/repositories/src/main/java/au/com/shiftyjelly/pocketcasts/repositories/playback/MediaSessionManager.kt:524: The installCastPlayerInternal KDoc still says CastStatePlayer sends stop to PlaybackManager, which would mislead the next reader. Remove "stop" from that list or note that stop is ignored while casting. These lines aren't in the diff, so I couldn't leave this as an inline comment.

@sztomek
sztomek force-pushed the fix/cast-state-player-ignore-stop branch from 04ba206 to 5e66ff9 Compare October 23, 2026 11:59
@sztomek
sztomek force-pushed the fix/cast-state-player-ignore-stop branch from 5e66ff9 to c6e2131 Compare October 23, 2026 11:59
@sztomek sztomek added this to the 8.24 milestone Oct 23, 2026
@sztomek
sztomek marked this pull request as ready for review October 23, 2026 14:00
@sztomek
sztomek requested a review from a team as a code owner October 23, 2026 14:00
@sztomek
sztomek requested review from geekygecko and removed request for a team October 23, 2026 14:00
@claude

claude Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @sztomek's task in 37s —— View job


No new code since the last review. The one earlier finding is still open: commit 141261c updated the CastStatePlayer KDoc, but the installCastPlayerInternal KDoc still says stop goes to PlaybackManager.

Nits

  • modules/services/repositories/src/main/java/au/com/shiftyjelly/pocketcasts/repositories/playback/MediaSessionManager.kt:524: (nit) The installCastPlayerInternal KDoc still says CastStatePlayer delegates "stop" to PlaybackManager, which will mislead the next person who reads it. Remove "stop" from that list or note that stop is ignored while casting. This line isn't in the diff, so it can't take an inline comment. Fix this →

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant