MediaRecorder Class

Records the tracks of a MediaStream (https://w3c.github.io/mediacapture-record/): the video and the audio are encoded by the codecs of BrowsingContextOptions.MediaCodecs (VP8 and Opus) and muxed into a WebM stream, delivered in dataavailable events. The video frames are sampled at the frame rate of the track (30 frames per second by default), on the clock of the event loop.

public sealed class MediaRecorder : EventTarget
Inheritance
EventTarget MediaRecorder

Constructors

NameDescription
MediaRecorder(MediaStream, MediaRecorderOptions?)Creates a recorder (https://w3c.github.io/mediacapture-record/#dom-mediarecorder-mediarecorder).

MediaRecorder(MediaStream, MediaRecorderOptions?)

MediaRecorder.cs

Creates a recorder (https://w3c.github.io/mediacapture-record/#dom-mediarecorder-mediarecorder).

public MediaRecorder(MediaStream stream, MediaRecorderOptions? options = null)

Parameters

stream MediaStream
The stream to record.
options MediaRecorderOptions?
The type, the bitrates and the key frame interval of the recording.

Exceptions

DomException
A NotSupportedError when the type is not supported, the options give both key frame intervals, or the document is not fully active.

See also

Properties

NameDescription
AudioBitrateModeGets how the audio encoder controls its bitrate.
AudioBitsPerSecondGets the target bitrate of the audio, in bits per second.
MimeTypeGets the type of the recording: the one of the options, or the one chosen when the recording starts.
OnDataAvailableGets or sets the event handler of the dataavailable event.
OnErrorGets or sets the event handler of the error event.
OnPauseGets or sets the event handler of the pause event.
OnResumeGets or sets the event handler of the resume event.
OnStartGets or sets the event handler of the start event.
OnStopGets or sets the event handler of the stop event.
StateGets the state of the recorder.
StreamGets the recorded stream.
VideoBitsPerSecondGets the target bitrate of the video, in bits per second.

AudioBitrateMode

MediaRecorder.cs

Gets how the audio encoder controls its bitrate.

public BitrateMode AudioBitrateMode { get; }

AudioBitsPerSecond

MediaRecorder.cs

Gets the target bitrate of the audio, in bits per second.

public uint AudioBitsPerSecond { get; }

Gets the type of the recording: the one of the options, or the one chosen when the recording starts.

public string MimeType { get; }

OnDataAvailable

MediaRecorder.cs

Gets or sets the event handler of the dataavailable event.

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

Gets or sets the event handler of the error event.

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

Gets or sets the event handler of the pause event.

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

Gets or sets the event handler of the resume event.

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

Gets or sets the event handler of the start event.

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

Gets or sets the event handler of the stop event.

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

Gets the state of the recorder.

public RecordingState State { get; }

Gets the recorded stream.

public MediaStream Stream { get; }

VideoBitsPerSecond

MediaRecorder.cs

Gets the target bitrate of the video, in bits per second.

public uint VideoBitsPerSecond { get; }

Methods

NameDescription
IsTypeSupported(string)Returns whether the recorder can record a type (https://w3c.github.io/mediacapture-record/#dom-mediarecorder-istypesupported).
Pause()Pauses the recording (https://w3c.github.io/mediacapture-record/#dom-mediarecorder-pause).
RequestData()Delivers the data recorded so far in a dataavailable event (https://w3c.github.io/mediacapture-record/#dom-mediarecorder-requestdata).
Resume()Resumes a paused recording (https://w3c.github.io/mediacapture-record/#dom-mediarecorder-resume).
Start(uint?)Starts the recording (https://w3c.github.io/mediacapture-record/#dom-mediarecorder-start).
Stop()Stops the recording (https://w3c.github.io/mediacapture-record/#dom-mediarecorder-stop): the data is delivered, then a stop event is fired.

IsTypeSupported(string)

MediaRecorder.cs

Returns whether the recorder can record a type (https://w3c.github.io/mediacapture-record/#dom-mediarecorder-istypesupported).

public static bool IsTypeSupported(string type)

Parameters

type string
The MIME type (e.g. video/webm;codecs=vp8,opus), or an empty string.

Returns

bool

See also

Pauses the recording (https://w3c.github.io/mediacapture-record/#dom-mediarecorder-pause).

public void Pause()

Exceptions

DomException
An InvalidStateError when the recorder is inactive.

See also

RequestData()

MediaRecorder.cs

Delivers the data recorded so far in a dataavailable event (https://w3c.github.io/mediacapture-record/#dom-mediarecorder-requestdata).

public void RequestData()

Exceptions

DomException
An InvalidStateError when the recorder is inactive.

See also

Resumes a paused recording (https://w3c.github.io/mediacapture-record/#dom-mediarecorder-resume).

public void Resume()

Exceptions

DomException
An InvalidStateError when the recorder is inactive.

See also

Start(uint?)

MediaRecorder.cs

Starts the recording (https://w3c.github.io/mediacapture-record/#dom-mediarecorder-start).

public void Start(uint? timeslice = null)

Parameters

timeslice uint?
The duration in milliseconds of the data of each dataavailable event, or null to deliver all the data when the recording stops.

Exceptions

DomException
An InvalidStateError when the recorder is recording, a NotSupportedError when the stream is inactive, a SecurityError when a track is not origin-clean.

See also

Stops the recording (https://w3c.github.io/mediacapture-record/#dom-mediarecorder-stop): the data is delivered, then a stop event is fired.

public void Stop()