Class AudioFileReader
AudioFileReader simplifies opening an audio file in NAudio Simply pass in the filename, and it will attempt to open the file and set up a conversion path that turns into PCM IEEE float. ACM codecs will be used for conversion. It provides a volume property and implements both WaveStream and ISampleProvider, making it possibly the only stage in your audio pipeline necessary for simple playback scenarios
public class AudioFileReader : WaveStream, IAsyncDisposable, IDisposable, IWaveProvider, ISampleProvider
- Inheritance
-
AudioFileReader
- Implements
- Inherited Members
Constructors
AudioFileReader(Stream)
Initializes a new instance of AudioFileReader from a stream. The audio format is detected from the stream contents, so no file name is required. WAV and AIFF streams are handled by the cross-platform readers; on the Windows build any other format is passed to Media Foundation.
public AudioFileReader(Stream inputStream)
Parameters
inputStreamStreamThe stream to read from. It must be readable and seekable, and the caller retains ownership of it — disposing the AudioFileReader does not dispose the underlying stream.
Exceptions
- ArgumentNullException
inputStreamis null.- ArgumentException
inputStreamis unreadable or unseekable.- NotSupportedException
The stream is in a format the cross-platform build cannot read. Use the Windows build for Media Foundation, or
SoundFileReaderfrom the NAudio.SoundFile package.
AudioFileReader(string)
Initializes a new instance of AudioFileReader
public AudioFileReader(string fileName)
Parameters
fileNamestringThe file to open
Exceptions
- NotSupportedException
The file is in a format the cross-platform build cannot read. Use the Windows build for Media Foundation, or
SoundFileReaderfrom the NAudio.SoundFile package.
Properties
FileName
File Name (null when this reader was created from a stream)
public string FileName { get; }
Property Value
Length
Length of this stream (in bytes)
public override long Length { get; }
Property Value
Position
Position of this stream (in bytes)
public override long Position { get; set; }
Property Value
Volume
Gets or Sets the Volume of this AudioFileReader. 1.0f is full volume
public float Volume { get; set; }
Property Value
WaveFormat
WaveFormat of this stream
public override WaveFormat WaveFormat { get; }
Property Value
Methods
Dispose(bool)
Disposes this AudioFileReader
protected override void Dispose(bool disposing)
Parameters
disposingboolTrue if called from Dispose
Read(byte[], int, int)
Reads from this wave stream
public override int Read(byte[] buffer, int offset, int count)
Parameters
Returns
Read(Span<byte>)
Reads from this wave stream
public override int Read(Span<byte> buffer)
Parameters
Returns
Read(Span<float>)
Reads audio samples from this file reader
public int Read(Span<float> buffer)