Table of Contents

Class MediaFoundationReader

Namespace
NAudio.Wave
Assembly
NAudio.Wasapi.dll

Class for reading any file that Media Foundation can play Automatically converts to PCM If it is a video file with multiple audio streams, it will pick out the first audio stream

public class MediaFoundationReader : WaveStream, IAsyncDisposable, IDisposable, IWaveProvider
Inheritance
MediaFoundationReader
Implements
Derived
Inherited Members
Extension Methods

Constructors

MediaFoundationReader()

Default constructor

protected MediaFoundationReader()

MediaFoundationReader(string)

Creates a new MediaFoundationReader based on the supplied file

public MediaFoundationReader(string file)

Parameters

file string

Filename (can also be a URL e.g. http:// mms:// file://)

MediaFoundationReader(string, MediaFoundationReaderSettings)

Creates a new MediaFoundationReader based on the supplied file

public MediaFoundationReader(string file, MediaFoundationReader.MediaFoundationReaderSettings settings)

Parameters

file string

Filename

settings MediaFoundationReader.MediaFoundationReaderSettings

Advanced settings

Properties

Length

The bytesRequired of this stream in bytes (n.b may not be accurate)

public override long Length { get; }

Property Value

long

Position

Current position within this stream

public override long Position { get; set; }

Property Value

long

WaveFormat

WaveFormat of this stream (n.b. this is after converting to PCM)

public override WaveFormat WaveFormat { get; }

Property Value

WaveFormat

Methods

Dispose(bool)

Cleans up after finishing with this reader

protected override void Dispose(bool disposing)

Parameters

disposing bool

true if called from Dispose

Init(MediaFoundationReaderSettings)

Initializes

protected void Init(MediaFoundationReader.MediaFoundationReaderSettings initialSettings)

Parameters

initialSettings MediaFoundationReader.MediaFoundationReaderSettings

Read(byte[], int, int)

Reads from this wave stream

public override int Read(byte[] buffer, int offset, int count)

Parameters

buffer byte[]

Buffer to read into

offset int

Offset in buffer

count int

Bytes required

Returns

int

Number of bytes read; 0 indicates end of stream

Read(Span<byte>)

Reads from this wave stream into a span (zero-copy path for WASAPI playback)

public override int Read(Span<byte> buffer)

Parameters

buffer Span<byte>

Returns

int

Events

WaveFormatChanged

WaveFormat has changed

public event EventHandler WaveFormatChanged

Event Type

EventHandler