fix(player): use the real preview length, not the full track duration#47
Merged
aykhan019 merged 1 commit intoMay 31, 2026
Merged
Conversation
The <audio> element plays a ~30s iTunes preview, but the player used the full Spotify track duration (durationMs) for the seek bar, progress, and the recorded play length. That left most of the seek bar dead, capped the progress bar near ~17%, and inflated recorded listening minutes roughly 6x. - Measure the preview length from the audio element's loadedmetadata event and store it as previewDurationMs in the player store. - Drive the seek bar max, progress, time labels, position clamping, and onEnded from that effective duration, falling back to the track duration until metadata loads. - Record durationPlayedMs as min(previewDurationMs, trackDurationMs) with a 30s fallback, so listening-minute analytics reflect previews, not full tracks.
|
@fateh-mammadli is attempting to deploy a commit to the Aykhan's projects Team on Vercel. A member of the Team first needs to authorize it. |
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.
Why
The audio player plays a ~30-second iTunes preview, but it used the full Spotify track duration (
durationMs, ~3 min) for the seek bar, progress bar, and the recorded play length. Symptoms:durationPlayedMs = full track length, soSUM(duration_played_ms)/60000over-reported listening minutes by roughly 6× — which feeds the analytics screens.What changed
previewDurationMs, measured from the<audio>element'sloadedmetadataevent.max, progress, time labels, position clamping, andonEndedall use this effective duration, falling back to the track duration until metadata loads.PlayHistoryReporterrecordsdurationPlayedMs = min(previewDurationMs, trackDurationMs)(30 s fallback when not yet measured), so listening-minute analytics reflect previews rather than full tracks.Verification
pnpm --filter @statify/web typecheck,eslint, andpnpm --filter @statify/web test(61 tests, incl. the player-store suite) all pass.