Table of Contents

Class MediaType

Namespace
NAudio.MediaFoundation
Assembly
NAudio.Wasapi.dll

Media Type helper class, simplifying working with IMFMediaType. Implements IDisposable for proper COM lifetime management.

public class MediaType : IDisposable
Inheritance
MediaType
Implements
Inherited Members

Constructors

MediaType()

Creates and wraps a new IMFMediaType object

public MediaType()

MediaType(WaveFormat)

Creates and wraps a new IMFMediaType object based on a WaveFormat

public MediaType(WaveFormat waveFormat)

Parameters

waveFormat WaveFormat

WaveFormat

Properties

AttributeCount

Gets the number of attributes set on this media type.

public int AttributeCount { get; }

Property Value

int

AverageBytesPerSecond

The average bytes per second (valid for audio media types)

public int AverageBytesPerSecond { get; }

Property Value

int

BitsPerSample

The number of bits per sample (n.b. not always valid for compressed audio types)

public int BitsPerSample { get; set; }

Property Value

int

ChannelCount

The number of Channels (valid for audio media types)

public int ChannelCount { get; set; }

Property Value

int

MajorType

The Major type, e.g. audio or video (from the MediaTypes class)

public Guid MajorType { get; set; }

Property Value

Guid

SampleRate

The Sample Rate (valid for audio media types)

public int SampleRate { get; set; }

Property Value

int

SubType

The Media Subtype. For audio, is a value from the AudioSubtypes class

public Guid SubType { get; set; }

Property Value

Guid

Methods

Dispose()

Releases the underlying COM object.

public void Dispose()

Dispose(bool)

Releases the native IntPtr ref unconditionally. When called from Dispose() (disposing=true) also calls FinalRelease on the RCW; the finalizer path leaves the RCW alone because ComObject has its own finalizer with no defined ordering relative to ours.

protected virtual void Dispose(bool disposing)

Parameters

disposing bool

~MediaType()

Finalizer — runs only if Dispose was not called. Releases the native IntPtr ref; the source-generated RCW has its own ComObject finalizer that releases its ref independently.

protected ~MediaType()

GetAttributeByIndex(int, out Guid, nint)

Retrieves an attribute at the specified index.

public void GetAttributeByIndex(int index, out Guid key, nint valuePtr)

Parameters

index int

Zero-based index of the attribute

key Guid

Receives the attribute GUID key

valuePtr nint

Receives the attribute value as a PropVariant. Caller must free with PropVariant.Clear.

SetBlob(Guid, ReadOnlySpan<byte>)

Sets a byte-blob attribute on this media type. Used for codec-private configuration data (e.g. MF_MT_USER_DATA carrying the ALAC magic cookie or AAC HEAACWAVEINFO).

public void SetBlob(Guid key, ReadOnlySpan<byte> value)

Parameters

key Guid
value ReadOnlySpan<byte>

SetUInt32(Guid, int)

Sets a UINT32 attribute on this media type

public void SetUInt32(Guid key, int value)

Parameters

key Guid
value int

TryGetUInt32(Guid, int)

Tries to get a UINT32 value, returning a default value if it doesn't exist

public int TryGetUInt32(Guid key, int defaultValue = -1)

Parameters

key Guid
defaultValue int

Returns

int