fix(player): count a play on real listening, not on metadata load - #30
Merged
Merged
Conversation
playCount was bumped in onLoadedMetadata, which fires as soon as a track's metadata decodes — before playback and even if play() is rejected. So skipping through tracks counted a play for each, and the count was credited to `current`, which may already have changed after a rapid switch. Count in onTimeUpdate once playback passes a threshold (5s, or halfway through a shorter track), and credit loadedIdRef — the id the <audio> element is actually loaded with. loadedIdRef is blanked at the start of each load and set only when the element switches to the new track, so a timeupdate from the still-playing previous track during the async blob read can't double-count it. Verified in-browser: skipping a track before the threshold records no play; listening past it records exactly one, on the correct track. Fixes #8. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FkDKh1Uo1a4D7n5wCKdcKF
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.
Fixes #8.
Problem
playCountwas bumped inonLoadedMetadata, which fires as soon as metadata decodes — before playback, and even ifplay()is rejected. So skipping through tracks counted a play for each, and the count was credited tocurrent, which may already have changed after a rapid switch (wrong-track attribution).Fix
onTimeUpdateonce playback passes a threshold: 5s, or halfway through a shorter track.loadedIdRef— the id the<audio>element is actually loaded with — not the render-closurecurrent.loadedIdRefis blanked at the start of each load and set only when the element switches to the new track, so atimeupdatefrom the still-playing previous track during the async blob read can't double-count it.Verification
Built clean; behavioral test reading real
playCountdeltas:Note: loop-
allre-loads the track each wrap so it counts per repeat (each full play = a play, like most players); loop-oneuses nativeaudio.loopand counts once — an inherent, acceptable difference.🤖 Generated with Claude Code
Generated by Claude Code