AudioEncoder Class

Encodes audio (https://w3c.github.io/webcodecs/#audioencoder-interface): the AudioData objects given to AudioEncoder.Encode are encoded by the codecs of BrowsingContextOptions.MediaCodecs, and the EncodedAudioChunk objects are given to the output callback with the configuration of their decoder.

public sealed class AudioEncoder : EventTarget
Inheritance
EventTarget AudioEncoder

Constructors

NameDescription
AudioEncoder(AudioEncoderInit)Creates an encoder (https://w3c.github.io/webcodecs/#dom-audioencoder-audioencoder).

AudioEncoder(AudioEncoderInit)

Codecs.cs

Creates an encoder (https://w3c.github.io/webcodecs/#dom-audioencoder-audioencoder).

public AudioEncoder(AudioEncoderInit init)

Parameters

init AudioEncoderInit
The output and error callbacks.

See also

Properties

NameDescription
EncodeQueueSizeGets the number of pending encode requests.
OnDequeueGets or sets the event handler of the dequeue event (the queue size decreased).
StateGets the state of the encoder.

EncodeQueueSize

Codecs.cs

Gets the number of pending encode requests.

public uint EncodeQueueSize { get; }

OnDequeue

Codecs.cs

Gets or sets the event handler of the dequeue event (the queue size decreased).

public Action<Event>? OnDequeue { get; set; }

Gets the state of the encoder.

public CodecState State { get; }

Methods

NameDescription
Close()Closes the encoder (https://w3c.github.io/webcodecs/#dom-audioencoder-close).
Configure(AudioEncoderConfig)Configures the encoder (https://w3c.github.io/webcodecs/#dom-audioencoder-configure): a configuration that the codecs do not support closes it with a NotSupportedError.
Encode(AudioData)Encodes audio (https://w3c.github.io/webcodecs/#dom-audioencoder-encode): a clone of the data is encoded.
Flush()Encodes the pending audio (https://w3c.github.io/webcodecs/#dom-audioencoder-flush): the promise resolves once the chunks are delivered.
IsConfigSupported(AudioEncoderConfig)Returns whether the codecs support a configuration (https://w3c.github.io/webcodecs/#dom-audioencoder-isconfigsupported).
Reset()Discards the pending audio and the configuration (https://w3c.github.io/webcodecs/#dom-audioencoder-reset).

Close()

Codecs.cs

Closes the encoder (https://w3c.github.io/webcodecs/#dom-audioencoder-close).

public void Close()

Exceptions

DomException
An InvalidStateError when the encoder is closed.

See also

Configure(AudioEncoderConfig)

Codecs.cs

Configures the encoder (https://w3c.github.io/webcodecs/#dom-audioencoder-configure): a configuration that the codecs do not support closes it with a NotSupportedError.

public void Configure(AudioEncoderConfig config)

Parameters

config AudioEncoderConfig
The configuration.

Exceptions

TypeErrorException
The configuration is invalid.
DomException
An InvalidStateError when the encoder is closed.

See also

Encode(AudioData)

Codecs.cs

Encodes audio (https://w3c.github.io/webcodecs/#dom-audioencoder-encode): a clone of the data is encoded.

public void Encode(AudioData data)

Parameters

data AudioData
The audio.

Exceptions

TypeErrorException
The data is closed.
DomException
An InvalidStateError when the encoder is not configured.

See also

Flush()

Codecs.cs

Encodes the pending audio (https://w3c.github.io/webcodecs/#dom-audioencoder-flush): the promise resolves once the chunks are delivered.

public Task Flush()

IsConfigSupported(AudioEncoderConfig)

Codecs.cs

Returns whether the codecs support a configuration (https://w3c.github.io/webcodecs/#dom-audioencoder-isconfigsupported).

public static Task<AudioEncoderSupport> IsConfigSupported(AudioEncoderConfig config)

Parameters

config AudioEncoderConfig
The configuration.

Returns

Task<AudioEncoderSupport> A task that completes with the support and the configuration with the recognized members, or fails with a TypeErrorException for an invalid configuration.

See also

Reset()

Codecs.cs

Discards the pending audio and the configuration (https://w3c.github.io/webcodecs/#dom-audioencoder-reset).

public void Reset()

Exceptions

DomException
An InvalidStateError when the encoder is closed.

See also