regression: audio attachment duration is not shown until playback

Merged
AB
3mo ago
+143-1

Proposed changes (including videos or screenshots)

Audio attachments displayed 00:00 as their length until playback started; the duration only appeared once the file began playing.

Root cause: the persistent audio player (#41120) replaced the previous fuselage <AudioPlayer preload="metadata"> (which loaded each attachment's metadata on mount and showed its length) with a single app-wide <audio> element. That shared element only knows the duration of the one track it currently holds, so every non-active attachment was rendered with a hardcoded duration of 0.

Changes:

  • Add a useMediaDuration hook that resolves a file's duration from its metadata off a detached, metadata-only media element, without playing it, restoring the pre-shared-player behavior.
  • Resolve the duration once per source and cache it for the session, so scrolling an attachment out of and back into the virtualized message list does not re-fetch metadata or flash 00:00.
  • Show the resolved duration for non-active attachments and the player's live duration for the active one.

Issue(s)

CORE-2476

Steps to test or reproduce

  1. Open a room containing one or more audio attachments.
  2. Observe each attachment's length before playing it.
  3. Expected: the total duration appears once metadata loads, without requiring playback (previously it showed 00:00 until play started).

Further comments

Root cause: #41120

CORE-2476

CORE-2477

Summary by CodeRabbit

  • New Features
    • Audio attachments can now determine and display their duration before playback begins.
  • Bug Fixes
    • Audio duration displays remain accurate when metadata is initially unavailable or when switching tracks.
    • Invalid or unavailable duration values no longer appear in the player.
  • Tests
    • Added coverage for duration loading, caching, source changes, invalid values, and cleanup.