regression: audio attachment duration is not shown until playback
Merged
AB
3mo ago+143+143+012345678901234567890123456789-1-1-0123456789
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
useMediaDurationhook 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
- Open a room containing one or more audio attachments.
- Observe each attachment's length before playing it.
- Expected: the total duration appears once metadata loads, without requiring playback (previously it showed
00:00until play started).
Further comments
Root cause: #41120
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.