Fix ALAC playback in browsers without a native decoder
Summary
- ALAC
.m4afiles were failing silently in the Random-mode player and side-panel preview on browsers without an ALAC decoder (Firefox has none). The error handler refreshed once and skipped to the next track, so the user just saw tracks vanish. - Adds an on-demand transcode path:
/api/audio/<id>?transcode=flacspawnsffmpeg -c:a flac -f flacand pipes stdout to the response (lossless, all browsers support FLAC). - Client-side, a small helper probes
canPlayType('audio/mp4; codecs="alac"')once and rewrites.m4asrcs to use the transcode URL when the browser can't decode ALAC. Direct streaming with HTTP range support is unchanged for everything else. - Installs ffmpeg in the main Docker image to support the transcode path.
Files
-
Dockerfile— addffmpegto apt install -
src/routes/api/audio/[fileId]/+server.ts— handle?transcode=flacvia spawned ffmpeg -
src/lib/audioUrl.ts—audioSrcFor(fileId, fileName)helper with cached browser capability check -
src/routes/random/+page.svelte,src/lib/components/AlbumOrganizePanel.svelte,src/lib/components/FileList.svelte— use the helper everywhere<audio>.srcis set
Test plan
-
pnpm run buildpasses -
Deploy and confirm ffmpeg -versionworks inside the container -
In Firefox, play an ALAC album in Random mode — network tab shows ?transcode=flac, responseContent-Type: audio/flac, audio plays -
In Chrome/Safari, same album plays directly without ?transcode(fast path intact) -
Non-ALAC formats (MP3, FLAC) still stream directly with range/seek support -
Side-panel preview also plays ALAC in Firefox