Skip to content

fix(player): count a play on real listening, not on metadata load - #30

Merged
EnesYilmazcode merged 1 commit into
mainfrom
claude/funny-hawking-930hed
Jul 15, 2026
Merged

EnesYilmazcode merged 1 commit into
mainfrom
claude/funny-hawking-930hed

Conversation

@EnesYilmazcode

Copy link
Copy Markdown
Owner

Fixes #8.

Problem

playCount was bumped in onLoadedMetadata, which fires as soon as 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 (wrong-track attribution).

Fix

  • Count in onTimeUpdate once playback passes a threshold: 5s, or halfway through a shorter track.
  • Credit loadedIdRef — the id the <audio> element is actually loaded with — not the render-closure current.
  • 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.

Verification

Built clean; behavioral test reading real playCount deltas:

Action playCount delta
Play "Last Stop", skip away at 0.5s 0 (not counted) ✅
Play "Express Track" past threshold +1 (counted once) ✅
page errors none ✅

Note: loop-all re-loads the track each wrap so it counts per repeat (each full play = a play, like most players); loop-one uses native audio.loop and counts once — an inherent, acceptable difference.

🤖 Generated with Claude Code


Generated by Claude Code

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
@EnesYilmazcode
EnesYilmazcode merged commit 8d4bb0c into main Jul 15, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[MEDIUM] playCount inflated & loop-mode-dependent — bumped on loadedmetadata

2 participants