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
| 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.