Audio
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.
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 plays 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
| Codec | Containers |
|---|---|
| Opus | .ogg, .opus, .webm |
| Vorbis | .ogg, .webm |
| FLAC | .flac |
| MP3 | .mp3 |
| WAV / PCM | .wav |
| AAC | MP4 (Windows only via Media Foundation, not recommended) |
AAC is only available on Windows via system decoders and is not recommended. Use Opus instead.
Referenced API
Canonical API pages mentioned in this guide.
A filesystem that can be accessed by the game.
No summary available.
A filesystem that can be accessed by the game.
Enables music playback. Use this for music, not for playing game sounds.
Paths from tool addons which are mounted.
All mounted content.
Plays a music stream from a URL.
Plays a music file from a relative path.