Repository navigation
Conversation
7 of 20 tasks
|
Playback was sent as heartbeats, but the server only merges a heartbeat into the newest event in the bucket. With two players active their heartbeats alternated, never merged, and every 15s poll inserted new zero-duration events. Track each player's playing time as an open segment and write it once with its real duration when the track or state changes, the session ends, or it reaches 5 minutes.
0xbrayo
force-pushed
the
fix/media-watcher-concurrent-players
branch
from
October 8, 2026 19:37
ed6ce41 to
e5691c8
Compare
Key segments by media session token rather than package, so an app's two sessions don't overwrite each other. Close a session's segment when it leaves the active list, when it pauses or stops without metadata, and when it reports an unknown state or empty metadata, so stopped time is never counted as playing. Include album in the segment identity. Run all segment work, including the final writes on disconnect and destroy, on the handler thread so the blocking writes stay off the main thread; the writes are stamped with the disconnect time.
Member
Author
Teardown cleared the maps on the main thread while a session scan could be running on the handler thread, so the scan could register callbacks again after disconnect. Run teardown on the handler thread after any running scan, and guard callbacks, polls and session changes with a connected flag so work queued before the disconnect can't reopen a segment.
Member
Author
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.
Part of #333.
MediaWatchersent playback as zero-duration heartbeats (pulsetime 60s) on every change and every 15s poll. The server only merges a heartbeat into the newest event in the bucket. With two media sessions playing at once (for example music plus a video), their heartbeats alternated, so neither ever merged, and every poll inserted two new zero-duration events instead of extending two events.Change
MediaPlaybackSegmentstracks one open segment per media session (keyed by session token, so an app's two sessions stay separate) with a known start. It writes the segment once, with its real duration viainsertEvent, when:app,package,title,artist,album,state.Behaviour change
Playing time now shows up when the segment closes, at most ~5 minutes plus one poll later, rather than being extended live by heartbeats.
Testing
MediaPlaybackSegmentsTestcovers:./gradlew :mobile:testStandardDebugUnitTestpasses.