Skip to content

Improve cast load reliability with multiple fallback strategies#839

Open
theovilardo wants to merge 26 commits intobckp/refactor-cast-featurefrom
codex/fix-cast-function-connection-issue
Open

Improve cast load reliability with multiple fallback strategies#839
theovilardo wants to merge 26 commits intobckp/refactor-cast-featurefrom
codex/fix-cast-function-connection-issue

Conversation

@theovilardo
Copy link
Owner

Motivation

  • Casting frequently failed for some receivers with a single legacy client.load(MediaInfo) call, causing the app to show "Failed to load media on cast device.".
  • The intent is to make casting robust across a wide range of devices and network conditions by trying multiple compatible loading strategies and improving observability.

Description

  • Add a multi-strategy load flow that attempts queueLoad, a MediaLoadRequestData-based client.load(...), and a legacy client.load(MediaInfo, ...) fallback in sequence until one succeeds.
  • Build a MediaQueueItem list from songs and validate startIndex, with improved media URL/mime handling performed in Song.toMediaQueueItem.
  • Introduce an atomic safeOnComplete wrapper to avoid double invocation and a 20s coroutine-based safety timeout that forces failure if no callback arrives.
  • Add detailed Timber logging for each attempt and result to aid debugging and receiver-specific analysis.

Testing

  • No automated tests were executed for this change.

Codex Task

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3eaa7c12e3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines 139 to 143
val attempts = listOf(::attemptQueueLoad, ::attemptLoadRequest, ::attemptLegacyLoad)

fun runAttempt(index: Int) {
if (index >= attempts.size) {
Timber.tag(CAST_TAG).e("All cast load attempts failed")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reset timeout when chaining multiple load attempts

With the new sequential queueLoad → load(MediaLoadRequestData) → legacy load chain, the existing 20s safety timeout (started before any attempts) can now expire while a later attempt is still in flight. If the first attempt fails slowly and the second/third succeeds after ~20s total, the timeout will fire onComplete(false) first and the eventual success is ignored by safeOnComplete, causing a false “Failed to load media” and disconnect even though the cast device actually loaded. Consider resetting/extending the timeout per-attempt or only starting it once per attempt to avoid premature failure in slower networks/devices.

Useful? React with 👍 / 👎.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments