Skip to content

mediaPreview: warn when a media file's audio codec can't be played - #346571

Merged
Logan Ramos (lramos15) merged 2 commits into
mainfrom
agents/audio-video-preview-warning-support
Nov 6, 2026
Merged

Logan Ramos (lramos15) merged 2 commits into
mainfrom
agents/audio-video-preview-warning-support

Conversation

@lramos15

@lramos15 Logan Ramos (lramos15) commented Nov 6, 2026 •

Copy link
Copy Markdown
Member

Fixes #343048

The video and audio previews now warn when a file's audio uses a codec that can't be played, and suggest opening the file in an external application, so users don't think the file is broken. For example:

This video's audio uses the AAC codec, which can't be played in the video preview. Open the file in an external application to hear its audio.

For an audio file that fails to load, the warning replaces the generic "An error occurred while loading the audio file." message.

Why the container is parsed

Chromium silently drops audio tracks it can't decode: a video whose AAC audio can't be decoded plays with no error, no tracks and no decoded audio, just like a video without audio. Since #343490, canPlayType and MediaSource.isTypeSupported report codec support correctly, but they need the codec as input, and nothing in the browser or Electron exposes the codecs of a file. So the new readMediaInfo (mediaPreview/common/mediaCodecs.ts) reads the container and the codecs of the tracks of MP4, WebM, Ogg and WAV files, and the webview checks them against the runtime.

Notes for reviewers

  • Reads are bounded. Files are read in cached 64 KiB chunks through readFileStream, up to 2 MiB. readFile reads whole files whenever the provider can, even with position and length. Providers that can only read whole files, such as the Agent Host file system used for remote agent sessions, are read once and only up to 64 MiB. Reads never extend past the end of the file, which avoids a truncation bug in readFileIntoStream that's fixed separately in files: fix truncated ranged reads that reach the end of a file #346572; this PR doesn't depend on it.
  • The webview requests the codecs when its content loads, and the input answers from a read started when rendering. Messages posted to the webview are lost when it's recreated, such as when the editor moves to another window.
  • The WebM fallback that plays WebM files through Media Source Extensions in builds whose FFmpeg lacks WebM (Webms with supported format not previewable in VSCode #195758) now gets the codecs of all tracks from the same parser, instead of searching the first 64 KiB of the file for codec IDs. It asks for them before reading the file, so other formats are no longer read completely. For files that can only be read as a whole, it reads up to 200 MiB, which is the fallback's own limit.
  • Only audio codecs produce a warning; the warning is text only.
  • WAV formats that browsers play although canPlayType only recognizes PCM (IEEE float, A-law, mu-law, MP3) are never reported.

How to test

  1. In a product build, open a video with AAC audio (for example ffmpeg -f lavfi -i testsrc=duration=3 -f lavfi -i sine=duration=3 -c:v libx264 -c:a aac narrated.mp4). The video plays and the warning above it names AAC.
  2. In Code OSS, which can play AAC, use AC-3 audio instead (-c:a ac3) to see the warning, and an IMA ADPCM WAV file (-c:a adpcm_ima_wav) to see the warning replace the audio preview's load error.
  3. Videos with supported audio, such as VP9 and Opus in WebM, show no warning.

Validation:

  • ./scripts/test.sh --run src/vs/workbench/contrib/mediaPreview/test/common/mediaCodecs.test.ts --run src/vs/workbench/contrib/mediaPreview/test/browser/mediaPreviewEditorInputs.test.ts --run src/vs/workbench/contrib/mediaPreview/test/common/mediaPreview.test.ts: passed (11 tests).
  • pnpm run typecheck-client: passed.
  • pnpm run eslint on the changed files: passed.
  • The parser identified the audio codecs of 21 files encoded with ffmpeg (AAC, Opus, MP3, FLAC, AC-3, E-AC-3 and ALAC in MP4, Opus and Vorbis in WebM, Vorbis, Opus and FLAC in Ogg, and PCM, float and ADPCM WAV files). It read 247 KB of a 21.6 MB MP4 whose track descriptions are at the end.
  • In Code OSS, the warning showed for AC-3 video and ADPCM audio, not for Opus WebM, and still showed after moving the editor to a new window. Insiders reports AAC and Opus in MP4 as unsupported to both canPlayType and MediaSource.isTypeSupported.
  • The WebM fallback played a VP9 WebM file with the Insiders FFmpeg library, which can't open WebM.

Chromium silently drops audio tracks it can't decode, so a video whose audio uses an unsupported codec (such as AAC in builds whose FFmpeg doesn't include it) plays without sound and looks like a broken file. The audio and video previews now read the codecs of the file's audio tracks from its container (MP4, WebM, Ogg or WAV) and, if the webview can't play any of them, show a warning that suggests opening the file in an external application.

The WebM fallback that plays files through Media Source Extensions now gets the codecs of all tracks from the same parser instead of searching the first bytes of the file for codec IDs.

Fixes #343048

Co-authored-by: Copilot <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The codec mapping incorrectly labels MPEG-4 ALS streams as AAC, causing unsupported-playback warnings to report the wrong codec.

1 open issue
What changed in this PR

Adds unsupported-audio-codec warnings to VS Code’s media previews, helping explain silent video playback and audio load failures reported in #343048.

Changes:

  • Adds bounded container parsing for MP4, WebM, Ogg, and WAV.
  • Displays localized codec warnings and reuses parsed track information for the WebM playback fallback.
  • Adds parser fixtures and tests for codec detection, read limits, and webview messaging.
File Description
src/​vs/​workbench/​contrib/​mediaPreview/​test/​common/​mediaTestFiles.ts Adds minimal media-file fixture builders.
src/​vs/​workbench/​contrib/​mediaPreview/​test/​common/​mediaCodecs.test.ts Tests codec parsing and file-read behavior.
src/​vs/​workbench/​contrib/​mediaPreview/​test/​browser/​mediaPreviewEditorInputs.test.ts Tests codec-warning and WebM-type messaging.
src/​vs/​workbench/​contrib/​mediaPreview/​common/​mediaCodecs.ts Implements bounded container and track-codec parsing.
src/​vs/​workbench/​contrib/​mediaPreview/​browser/​mediaPlayerEditorInput.ts Integrates warnings and parser-backed WebM fallback detection.

Review effort: Balanced

MPEG-4 Audio also covers codecs that aren't AAC, such as lossless ALS. Any audio object type other than MPEG-1/2 Layer 1 to 3 was named AAC, so the warning for an unsupported ALS track blamed AAC, even in builds that play AAC. AAC object types are now named explicitly, and other object types are left unnamed so that the warning doesn't name a codec.

Co-authored-by: Copilot <[email protected]>
@lramos15
Logan Ramos (lramos15) merged commit 5518e98 into main Nov 6, 2026
52 checks passed
@lramos15
Logan Ramos (lramos15) deleted the agents/audio-video-preview-warning-support branch November 6, 2026 18:37
@vs-code-engineering vs-code-engineering Bot added this to the 1.146.0 milestone Nov 6, 2026
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.

Agents Window: No Audio support in the video preview

4 participants