Repository navigation
Conversation
A media-button PLAY with the app not running (One UI "Play last song", Bluetooth, Waze) makes Media3's MediaButtonReceiver call startForegroundService on PlaybackService. RNQP's onPlaybackResumption always returned an empty queue, so nothing played, startForeground was never called and the system raised an ANR. Patch react-native-queue-player with an onPlaybackResumptionRequest handler that Media3's onPlaybackResumption awaits, using the same cold-start pattern as the Assistant and Android Auto callbacks: the headless JS boot registers the handler, which returns the saved queue, track and position, and the library loads it for Media3 to play. A cold media-button start calls startForeground with a placeholder on the media notification id before waiting, so the service meets the foreground contract however long the JS boot takes. When there is nothing to resume (no saved queue, logged out, a pending Navidrome re-key, nothing playable, no answer within the timeout) the player is paused and the service stops. The answer is never optional and the wait is cancellable: Nitro's Kotlin Promise cannot deliver a null result and its await() ignores cancellation, so either would hang. Substreamer answers from the persisted queue through the same restore code as the boot hydration. Opening the app later in the same process adopts the resumed session instead of loading the queue again.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
On Android, a play press while Substreamer is not running (One UI's "Play last song" card, Bluetooth, a headset, Waze) did nothing, and about 40 s later Android raised an ANR:
Context.startForegroundService() did not then call Service.startForeground(). Now the press resumes the last queue at the saved track and position, and when there is nothing to resume the service stops cleanly. Possibly the same bug as #274 (no logs there).Cause: Media3's
MediaButtonReceiverstartsPlaybackServiceas a foreground service, but react-native-queue-player 3.0.0'sonPlaybackResumptionalways returned an empty queue, so nothing played andstartForegroundwas never called.Changes
patches/react-native-queue-player+3.0.0.patch(the library repo is private, so this follows the existing patch-package convention):onPlaybackResumptionRequestcallback (Nitro spec + regenerated bindings,registerPlaybackServicehandler field). Emptytracksmeans nothing to resume. Android-only; iOS accepts and ignores it.PlaybackService: a cold media-button start callsstartForegroundwith a placeholder on the media notification id at once, awaits the JS answer (cancellable, 20 s), loads it viaapplyResolvedAssistantQueueat the saved index, and hands it to Media3 to play. Nothing to resume: pause,stopForeground,stopSelf.Promise.thenthrows on a null result andawait()ignores cancellation, hence the non-optional result andawaitCancellable.playerService:resolvePlaybackResumptionanswers from the persisted queue through the same restore code as the boot hydration (prepareRestoredQueue); a later UI boot in the same process adopts the resumed session instead of loading it again.headlessMediaService: wires the handler; resumes nothing when logged out or while a Navidrome re-key is pending (narrowing to downloads would prune the saved queue).Testing
npx tsc --noEmitpassesnpx jest --no-coveragepassesPlaybackServiceResumptionTest,PlaybackServiceLifecycleTest; jestplayerService.hydration,headlessMediaService.voice)cmd media_session dispatch play-> playing the same track from 10.66 s about 0.86 s later, no ANR after 65 s; cleared queue -> service stops after 0.7 s, no ANR; unpatchedmasterANRs at +40.7 s). Also on a Galaxy S25 (One UI 9) with the "Play last song" card.Known gap (not new): a cold-start headset double-tap is turned into "skip next" by Media3 and never asks for resumption.
Created with Claude Opus 5.5 in omp (T3 Code). Review by a Claude Opus 5.5 omp subagent.