Skip to content

Streaming

Axwabo edited this page Feb 6, 2026 · 6 revisions

Streaming Audio Files

When playing longer audio files (e.g. music), avoid loading the entire file into memory.

SecretLabNAudio provides methods and classes to make streaming easy. An adequate reader is created which reads samples as requested.

Use the UseFile extension method on an AudioPlayer to have it play a given file. Sample conversion is handled automatically; the file can be of any sample rate, and can even be stereo.

Example
using SecretLabNAudio.Core;
using SecretLabNAudio.Core.Extensions;

AudioPlayer.Create(SpeakerSettings.GloballyAudible)
    .UseFile("/path/to/music.wav")
    .DestroyOnEnd();

Caution

UseFile will throw an exception if the file doesn't exist or if the file type is not supported. This is ideal if you log exceptions. Call UseFileSafe to avoid exceptions; this method will keep the previous provider if the file couldn't be processed.

For granular control over the stream, use the CreateStreamProcessor or the TryCreateStreamProcessor class to create a processor that can be used in other processors even.

Extensions

The extension methods for AudioPlayers automatically downmix and resample the file, no need to convert to 48000 Hz mono Ogg Vorbis

The MixFile and MixFileSafe extensions add the file input to the player's mixer

Most streaming-related extension methods include a volume and a loop, or a ModifyChain parameter.

If you want to play a file after another, use the EnqueueFile or EnqueueFileSafe extension methods to add them to the player's queue

Tip

See also: processor chains

Getting Started

Playing Audio

Advanced

Audio Processors

v1 Guides

Caution

v1 will be out of support soon.

Clone this wiki locally