Play sound in the WebView provided by vscode

Viewed 1346

I want to develop a plug-in to play local sound.So I make a demo for test with audio :

<audio src="vscode-resource:/Users/asure/Documents/Projects/test/EffectMove.mp3" controls>

/Users/asure/Documents/Projects/test it's the directory where I tested it.I also tested after adding it to localResourceRoots.Below was what I get.

player
It seems that sound didn't load correctly while no errors can be found in console window.I was confused whether vscode disable audio related content in webview or something was wrong in my code.
Does anyone know how to play sound in the webview provided by vsocde

3 Answers

VSCode does not support playing sound with audio tag in WebView. you can use web audio API instead.

and there is already an extension that plays local sound files with web audio API.

Because vscode does not support audio playback.

Actually, I just learned that we strip out ffmpeg and other media support from our release builds. This is by-design and something we will not change, but it does mean that many types of media playback will never be supported in webviews inside vscode

source: https://github.com/microsoft/vscode/issues/32540

Vscode v1.71 will support various audio codecs within a webView.

See release notes: ffmpeg support.

It includes mp3 suuport and

Vorbis
Flac
H.264
VP8
WAV
MP3
Ogg
Related