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
waveFormatWaveFormatWaveFormat
Properties
AttributeCount
Gets the number of attributes set on this media type.
public int AttributeCount { get; }
Property Value
AverageBytesPerSecond
The average bytes per second (valid for audio media types)
public int AverageBytesPerSecond { get; }
Property Value
BitsPerSample
The number of bits per sample (n.b. not always valid for compressed audio types)
public int BitsPerSample { get; set; }
Property Value
ChannelCount
The number of Channels (valid for audio media types)
public int ChannelCount { get; set; }
Property Value
MajorType
The Major type, e.g. audio or video (from the MediaTypes class)
public Guid MajorType { get; set; }
Property Value
SampleRate
The Sample Rate (valid for audio media types)
public int SampleRate { get; set; }
Property Value
SubType
The Media Subtype. For audio, is a value from the AudioSubtypes class
public Guid SubType { get; set; }
Property Value
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
disposingbool
~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
indexintZero-based index of the attribute
keyGuidReceives the attribute GUID key
valuePtrnintReceives 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
keyGuidvalueReadOnlySpan<byte>
SetUInt32(Guid, int)
Sets a UINT32 attribute on this media type
public void SetUInt32(Guid key, int value)
Parameters
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)