Skip to content

fix(player): use the real preview length, not the full track duration#47

Merged
aykhan019 merged 1 commit into
aykhan019:mainfrom
endorphin13:fix/preview-player-duration
May 31, 2026
Merged

fix(player): use the real preview length, not the full track duration#47
aykhan019 merged 1 commit into
aykhan019:mainfrom
endorphin13:fix/preview-player-duration

Conversation

@endorphin13

Copy link
Copy Markdown
Contributor

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:

  • most of the seek slider was dead (it spanned 3 min for ~30 s of audio);
  • the progress bar capped around ~17%;
  • every preview recorded durationPlayedMs = full track length, so SUM(duration_played_ms)/60000 over-reported listening minutes by roughly — which feeds the analytics screens.

What changed

  • The player store now tracks previewDurationMs, measured from the <audio> element's loadedmetadata event.
  • The seek bar max, progress, time labels, position clamping, and onEnded all use this effective duration, falling back to the track duration until metadata loads.
  • PlayHistoryReporter records durationPlayedMs = 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, and pnpm --filter @statify/web test (61 tests, incl. the player-store suite) all pass.

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.
@endorphin13 endorphin13 requested a review from aykhan019 as a code owner May 31, 2026 18:04
@vercel

vercel Bot commented May 31, 2026

Copy link
Copy Markdown

@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.

@aykhan019 aykhan019 merged commit 7638f89 into aykhan019:main May 31, 2026
1 of 2 checks 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.

3 participants