Media

Audio

MusicPlayer

MusicPlayer is for music tracks and streaming audio that need programmatic control over playback, positioning, or visualization. For in-game sound effects and Sound components, see Sound.

var music = MusicPlayer.Play( FileSystem.Mounted, "music/theme.ogg" );
music.Volume = 0.8f;
music.Repeat = true;

Streaming from a URL:

var music = MusicPlayer.PlayUrl( "https://example.com/stream.ogg" );

By default, MusicPlayer is positioned at the world origin (set music.ListenLocal = true to play it globally). To place it in world-space:

music.ListenLocal = false;
music.Position = WorldPosition;

Audio visualization:

ReadOnlySpan<float> spectrum = music.Spectrum;   // 512-element FFT magnitudes
float amplitude = music.Amplitude;               // approximate loudness

Supported Formats

CodecContainers
Opus.webm, .mp4
Vorbis.ogg
MP3.mp3
WAV / PCM.wav
AACMP4 (Windows only via Media Foundation, not recommended)

:::warning AAC is only available on Windows via system decoders and is not recommended. Use Opus instead. :::

Source: Facepunch/sbox-docs (CC-BY-4.0) · updated 2026-09-03. Read it rendered on the official docs.

More in Media

Community wiki — not affiliated with Facepunch Studios. For the latest and most authoritative information, see the official developer wiki.