Skip to content

Fix ALAC playback in browsers without a native decoder

jedmund requested to merge jedmund/fix-alac-playback into main

Summary

  • ALAC .m4a files 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=flac spawns ffmpeg -c:a flac -f flac and pipes stdout to the response (lossless, all browsers support FLAC).
  • Client-side, a small helper probes canPlayType('audio/mp4; codecs="alac"') once and rewrites .m4a srcs 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 — add ffmpeg to apt install
  • src/routes/api/audio/[fileId]/+server.ts — handle ?transcode=flac via spawned ffmpeg
  • src/lib/audioUrl.tsaudioSrcFor(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>.src is set

Test plan

  • pnpm run build passes
  • Deploy and confirm ffmpeg -version works inside the container
  • In Firefox, play an ALAC album in Random mode — network tab shows ?transcode=flac, response Content-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

Merge request reports

Loading