Class MediaRecorder
- Namespace
- CSharpToJavaScript.APIs.JS
- Assembly
- CSharpToJavaScript.dll
The MediaRecorder interface of the MediaStream Recording API provides functionality to easily record media. It is created using the MediaRecorder(MediaStream, MediaRecorderOptions) constructor.
[Value("MediaRecorder")]
public class MediaRecorder : EventTarget
- Inheritance
-
MediaRecorder
- Inherited Members
Remarks
-Using the MediaStream Recording API
-Web Dictaphone: MediaRecorder + getUserMedia + Web Audio API visualization demo, by Chris Mills (source on GitHub.)
-Recording a media element
-simpl.info MediaStream Recording demo, by Sam Dutton.
-GetUserMedia(MediaStreamConstraints)
-OpenLang: HTML video language lab web application using MediaDevices and the MediaStream Recording API for video recording (source on GitHub)
Constructors
MediaRecorder()
public MediaRecorder()
MediaRecorder(MediaStream, MediaRecorderOptions)
The MediaRecorder() constructor
creates a new MediaRecorder object that will record a specified
MediaStream.
public MediaRecorder(MediaStream stream, MediaRecorderOptions options = null)
Parameters
streamMediaStreamoptionsMediaRecorderOptions
Remarks
The object can optionally be configured to record
using a specific media container (file type), and, further, can specify the exact codec
and codec configuration(s) to use by specifying the codecs parameter.
-Using the MediaStream Recording API
-Web Dictaphone: MediaRecorder +
getUserMedia + Web Audio API visualization demo, by Chris Mills (source on GitHub.)
-simpl.info MediaStream Recording demo, by Sam Dutton.
-GetUserMedia(MediaStreamConstraints)
Properties
AudioBitrateMode
NOTE
ExperimentalaudioBitrateMode read-only property of the MediaRecorder interface returns the bitrate mode used to encode audio tracks.
[Value("audioBitrateMode")]
public BitrateMode AudioBitrateMode { get; }
Property Value
- BitrateMode
One of the following:
Remarks
AudioBitsPerSecond
The audioBitsPerSecond read-only
property of the MediaRecorder interface returns the audio encoding bit
rate in use.
[Value("audioBitsPerSecond")]
public ulong AudioBitsPerSecond { get; }
Property Value
Remarks
This may differ from the bit rate specified in the constructor (if
it was provided).
MimeType
The mimeType read-only property of the MediaRecorder interface returns the {{Glossary("MIME")}} media type that was specified when creating the MediaRecorder object, or, if none was specified, which was chosen by the browser.
This is the file format of the file that would result from writing all of the recorded data to disk.
[Value("mimeType")]
public string MimeType { get; }
Property Value
- string
The MIME media type which describes the format of the recorded media, as a string.
This string may include thecodecsparameter, giving details about the codecs and the codec configurations used by the media recorder.The media type strings are standardized by the Internet Assigned Numbers Authority (IANA).
For their official list of defined media type strings, see the article Media Types on the IANA site.
See also media types to learn more about media types and how they're used in web content and by web browsers.
Remarks
Keep in mind that not all codecs are supported by a given container; if you write media using a codec that is not supported by a given media container, the resulting file may not work reliably if at all when you try to play it back.
See our media type and format guide for information about container and codec support across browsers.
NOTE
The term "MIME type" is officially considered to be historical; these strings are now officially known as media types.
MDN Web Docs content uses the terms interchangeably.
-Using the MediaStream Recording API
-Codecs in common media types
-Web Dictaphone: MediaRecorder + getUserMedia + Web Audio API visualization demo, by Chris Mills (source on GitHub.)
-simpl.info MediaStream Recording demo, by Sam Dutton.
-GetUserMedia(MediaStreamConstraints)
Ondataavailable
[Value("ondataavailable")]
public EventHandlerNonNull Ondataavailable { get; set; }
Property Value
Onerror
[Value("onerror")]
public EventHandlerNonNull Onerror { get; set; }
Property Value
Onpause
[Value("onpause")]
public EventHandlerNonNull Onpause { get; set; }
Property Value
Onresume
[Value("onresume")]
public EventHandlerNonNull Onresume { get; set; }
Property Value
Onstart
[Value("onstart")]
public EventHandlerNonNull Onstart { get; set; }
Property Value
Onstop
[Value("onstop")]
public EventHandlerNonNull Onstop { get; set; }
Property Value
State
The state read-only property of the MediaRecorder interface returns the current state of the current MediaRecorder object.
[Value("state")]
public RecordingState State { get; }
Property Value
- RecordingState
A string containing one of the following values:
Remarks
-Using the MediaStream Recording API
-Web Dictaphone: MediaRecorder +
getUserMedia + Web Audio API visualization demo, by Chris Mills (source on GitHub.)
-simpl.info MediaStream Recording demo, by Sam Dutton.
-Navigator.GetUserMedia
Stream
The stream read-only property of the MediaRecorder interface returns the stream that was passed into the MediaRecorder(MediaStream, MediaRecorderOptions) constructor when the MediaRecorder was created.
[Value("stream")]
public MediaStream Stream { get; }
Property Value
- MediaStream
The MediaStream passed into the
MediaRecorder()constructor when theMediaRecorderwas originally created.
Remarks
-Using the MediaStream Recording API
-Web Dictaphone: MediaRecorder +
getUserMedia + Web Audio API visualization demo, by Chris Mills (source on GitHub.)
-simpl.info MediaStream Recording demo, by Sam Dutton.
-Navigator.GetUserMedia
VideoBitsPerSecond
The videoBitsPerSecond read-only
property of the MediaRecorder interface returns the video encoding
bit rate in use.
[Value("videoBitsPerSecond")]
public ulong VideoBitsPerSecond { get; }
Property Value
Remarks
This may differ from the bit rate specified in the
constructor, if it was provided.
Methods
IsTypeSupported(string)
The isTypeSupported() static method of the MediaRecorder interface returns a {{jsxref("Boolean")}} which is true if the MIME media type specified is one the user agent should be able to successfully record.
[Value("isTypeSupported")]
public static bool IsTypeSupported(string type)
Parameters
typestring
Returns
- bool
A Boolean,
trueif the MediaRecorder implementation is capable of recording Blob objects for the specified MIME type.
Recording may still fail if there are insufficient resources to support the recording and encoding process.
If the value isfalse, the user agent is incapable of recording the specified format.
Remarks
-MediaStream Recording API
-Using the MediaStream Recording API
-Guide to media types and formats on the web
-Codecs in common media types
-MediaStreamTrack
-MediaStream
-MediaCapabilities
Pause()
The pause() method of the MediaRecorder interface is used
to pause recording of media streams.
[Value("pause")]
public GlobalObject.Undefined Pause()
Returns
Remarks
When a MediaRecorder object's pause() method is called, the
browser queues a task that runs the below steps:
-Using the MediaStream Recording API
-Web Dictaphone: MediaRecorder +
getUserMedia + Web Audio API visualization demo, by Chris Mills (source on GitHub.)
-simpl.info MediaStream Recording demo, by Sam Dutton.
-Navigator.GetUserMedia
RequestData()
The requestData()
method of the MediaRecorder interface is used to raise a MediaRecorder.Dataavailable event containing a
Blob object of the captured media as it was when the method was
called. This can then be grabbed and manipulated as you wish.
[Value("requestData")]
public GlobalObject.Undefined RequestData()
Returns
Remarks
When the requestData() method is invoked, the browser queues a task that
runs the following steps:
-Using the MediaStream Recording API
-Web Dictaphone: MediaRecorder +
getUserMedia + Web Audio API visualization demo, by Chris Mills (source on GitHub.)
-simpl.info MediaStream Recording demo, by Sam Dutton.
-Navigator.GetUserMedia
Resume()
The resume() method of the MediaRecorder interface is used to resume media recording when it has been previously paused.
[Value("resume")]
public GlobalObject.Undefined Resume()
Returns
Remarks
If State is already "recording", calling resume() has no effect.
When the resume() method is invoked, the browser queues a task that runs
the following steps:
-Using the MediaStream Recording API
-Web Dictaphone: MediaRecorder +
getUserMedia + Web Audio API visualization demo, by Chris Mills (source on GitHub.)
-simpl.info MediaStream Recording demo, by Sam Dutton.
-Navigator.GetUserMedia
Start(ulong)
The start() method of the MediaRecorder interface begins recording media into one or more Blob objects.
[Value("start")]
public GlobalObject.Undefined Start(ulong timeslice = 0)
Parameters
timesliceulong
Returns
Remarks
You can
record the entire duration of the media into a single Blob (or until you
call RequestData()), or you can specify the
number of milliseconds to record at a time. Then, each time that amount of media has
been recorded, an event will be delivered to let you act upon the recorded media, while
a new Blob is created to record the next slice of the media.
Assuming the MediaRecorder's State
is inactive, start() sets the state torecording, then begins capturing media from the input stream. ABlob is created and the data is collected in it until the time slice period
elapses or the source media ends. Each time a Blob is filled up to that
point (the timeslice duration or the end-of-media, if no slice duration was provided), a
MediaRecorder.Dataavailable event is sent to the MediaRecorder with the
recorded data. If the source is still playing, a new Blob is created and
recording continues into that, and so forth.
When the source stream ends, state is set to inactive and
data gathering stops. A final MediaRecorder.Dataavailable event is sent to theMediaRecorder, followed by a MediaRecorderstop event.
NOTE
If the browser is unable to start recording or continue
recording, it will raise an MediaRecorder.Error event, followed by a
MediaRecorder.Dataavailable event containing theBlobit
has gathered, followed by the MediaRecorderstop event.
-Using the MediaStream Recording API
-Web Dictaphone: MediaRecorder +
getUserMedia + Web Audio API visualization demo, by Chris Mills (source on GitHub.)
-simpl.info MediaStream Recording demo, by Sam Dutton.
-GetUserMedia(MediaStreamConstraints)
Stop()
The stop() method of the MediaRecorder interface is
used to stop media capture.
[Value("stop")]
public GlobalObject.Undefined Stop()
Returns
Remarks
When the stop() method is invoked, the UA queues a task that runs the
following steps:
-Using the MediaStream Recording API
-Web Dictaphone: MediaRecorder +
getUserMedia + Web Audio API visualization demo, by Chris Mills (source on GitHub.)
-simpl.info MediaStream Recording demo, by Sam Dutton.
-Navigator.GetUserMedia