-
Notifications
You must be signed in to change notification settings - Fork 0
Streaming
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.
Tip
See also: format readers file extension methods short clips
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.
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
- π Home
- πΌ Digital Audio Basics
- π Examples
- π¦ Supported Formats
- β¬οΈ Migrating from v1
- π AudioPlayer
- πΎ Short Clips
- πΏ Streaming From Disk
- ποΈ Speaker Groups
- π Sample Providers
- β»οΈ Pooling
- π© SendEngines
- π§ Personalizing Speakers
- π Monitoring Output
- βοΈ AudioQueue
- πΆ Mixer
- ποΈ ProcessorChain
Caution
v1 will be out of support soon.