Adds the Audio or Video Track
This method adds the audio or video tracks into the stream.
The track can be retrieved from the mediaStream
method.
Adjusts Audio Mixing Volume
The volume of the mixing audio. The value ranges between 0 and 100 (default).
Closes the Audio/Video Stream
This method closes the video/audio stream.
After calling this method, the camera and microphone authorizations are reset.
Disables the Audio
DEPRECATED from v 2.5.1, use muteAudio instead.
This method disables the audio track in the stream.
It works only when the audio flag is true
in the stream.
Disables the Video
DEPRECATED from v 2.5.1, use muteVideo instead.
This method disables the video track in the stream.
It works only when the video flag is true
in the stream.
Enables the Audio
DEPRECATED from v 2.5.1, use unmuteAudio instead.
This method enables the audio track in the stream.
It works only when the audio flag is true
in the stream.
By default the audio track is enabled. If you call disableAudio, call this method to enable audio.
Enables the Video
DEPRECATED from v 2.5.1, use unmuteVideo instead.
This method enables the video track in the stream.
It works only when the video flag is true
in the stream.
By default the video track is enabled. If you call disableVideo, call this method to enable video.
Retrieves the Current Audio Level
This method retrieves the current audio level.
Call setTimeout
or setInterval
to retrieve the local or remote audio change.
Retrieves the Current Position of the Audio Mixing
Retrieves the playback position (ms) of the audio.
Returns the current position of the audio mixing if successful.
Retrieves Audio Mixing Duration
Returns the audio mixing duration (ms) if successful.
Retrieves the Audio Track
This method retrieves the audio track in the stream and can be used together with replaceTrack.
If the stream contains an audio track, it will be returned in a MediaStreamTrack
object.
Retrieves the Stream ID
This method retrieves the stream ID.
Gets Connection Statistics
This method gets the connection statistics of the stream.
Note:
It may take some time to get some of the statistics.
The callback contains the connection statistics of the stream.
Retrieves the Video Track
This method retrieves the video track in the stream and can be used together with replaceTrack.
If the stream contains a video track, it will be returned in a MediaStreamTrack
object.
Retrieves the Audio Flag
This method retrieves the audio flag.
Retrieves the Video Flag
This method retrieves the video flag.
Initializes the Stream Object
This method initializes the local stream object.
If this method fails, the returned callback will show the error message, for example: {type: "error", msg: "NotAllowedError", info: "Permission denied"}
.
The possible error information in the msg
field includes:
The info
field shows the extra information for the error. If no more extra information, its value will be null
.
The callback when the method succeeds.
The callback when the method fails.
Returns Whether the Stream is Playing
true
: The stream is being rendered or playing on the page.false
: The stream is neither being rendered nor playing on the page.Disables the Audio
This method disables the audio track in the stream.
Note: For local streams, it works only when the audio flag is true
in the stream.
true
: Success.false
: Failure. Possible reasons include no audio, stream not initialized, and audio track already disabled.Disables the Video
This method disables the video track in the stream.
Note: For local streams, it works only when the video flag is true
in the stream.
true
: Success.false
: Failure. Possible reasons include no video, stream not initialized, and video track already disabled.Occurs when the user gives access to the camera and microphone.
Occurs when the user denies access to the camera and microphone.
Occurs when screen-sharing stops.
Occurs when the audio mixing stream playback starts/resumes.
Note: This callback is triggered when the audio mixing stream is loaded and starts playing, or when the paused audio mixing stream resumes playing.
Occurs when the last audio mixing stream playback finishes.
Pauses Audio Mixing
Plays the Audio/Video Stream
This method plays the video or audio stream.
Note:
Due to browser policy changes, this method must be triggered by the user's gesture on the Chrome 70+ and Safari browsers. See Autoplay Policy Changes for details.
Represents the HTML element ID. Digits and letters in the ASCII character set, “_”, “-", and ".". The string length must be greater than 0 and less than 256 bytes.
Options for playing the stream.
Video display mode:
"cover"
: Uniformly scale the video until it fills the visible boundaries (cropped).
One dimension of the video may have clipped contents. Refer to the cover
option of object-fit
in CSS.
"contain"
: Uniformly scale the video until one of its dimension fits the boundary (zoomed to fit).
Areas that are not filled due to the disparity in the aspect ratio will be filled with black. Refer to the contain
option of object-fit
in CSS.
For local streams, by default the cover mode is used for video playing and the contain mode is used for screen sharing; for remote streams, by default the cover mode is used.
Sets whether to mute the playing stream.
The muted
flag can be used as a workaround for the browser's autoplay policy.
On Chrome 70+ and Safari, a video stream with sound does not play until triggered by a user gesture.
If you want to play the video anyway without a user gesture, you can set the muted
flag to true, so that the video is automatically played without sound.
For more information, see Autoplay Policy Changes.
Removes the Audio or Video Track
This method removes the audio or video tracks from the stream.
Note:
The track can be retrieved from the mediaStream
method.
Replaces the Audio/Video Track
This method replaces the audio or video MediaStreamTrack
in the local stream.
After the local stream is published, you can use this method to switch the cameras, or switch between the microphone and the music player.
The new track can be retrieved by getUserMedia
, MediaElement.captureStream
or other methods.
The replaced track will be stopped.
Note:
The new track.
The callback when the method succeeds.
The callback when the method fails.
Resumes Audio Mixing
Sets the Audio Mixing Position
Sets the playback position of the audio mixing file to a different start position (by default plays from the beginning).
The time (ms) to start playing the audio mixing file, an integer. The value range is [0,100000000].
Sets the Audio Output
This method sets the audio output device for the remote stream. You can use it to switch between the microphone and the speakerphone.
It can be called either before or after the remote stream is played.
Note:
Only Chrome 49+ supports this function.
The device ID can be retrieved from getDevices, whose kind should be "audiooutput".
The retrieved ID is ASCII characters, and the string length is greater than 0 and less than 256 bytes.
Sets the Audio Profile
This method sets the audio profile.
It is optional and works only when called before Stream.init. The default value is "music_standard"
.
Note:
Due to the limitations of browsers, some browsers may not be fully compatible with the audio profile you set.
The audio profile has the following options:
"speech_low_quality"
: Sample rate 16 kHz, mono, encoding rate 24 Kbps."speech_standard"
: Sample rate 32 kHz, mono, encoding rate 24 Kbps."music_standard"
: Sample rate 48 kHz, mono, encoding rate 40 Kbps."standard_stereo"
: Sample rate 48 kHz, stereo, encoding rate 64 Kbps."high_quality"
: Sample rate 48 kHz, mono, encoding rate 128 Kbps."high_quality_stereo"
: Sample rate 48 kHz, stereo, encoding rate 192 Kbps.Sets the Volume
This method set the volume for the remote stream.
It can be called either before or after the remote stream is played.
Ranges from 0 (muted) to 100 (loudest).
Sets the Screen Profile
This method sets the profile of the screen in screen-sharing.
The screen profile. See the following table for details.
Screen Profile Definition
Screen Profile | Resolution | Frame Rate |
---|---|---|
480p_1 | 640 × 480 | 5 |
480p_2 | 640 × 480 | 30 |
720p_1 | 1280 × 720 | 5 |
720p_2 | 1280 × 720 | 30 |
1080p_1 | 1920 × 1080 | 5 |
1080p_2 | 1920 × 1080 | 30 |
Note:
Due to limitations of some devices and browsers, the resolution you set may fail to take effect and get adjusted by the browser. In this case, billings will be calculated based on the actual resolution.
Sets the Video Profile
This method sets the video profile.
It is optional and works only when called before Stream.init. The default value is "480p_1"
.
The video profile. See the following table for its definition and supported profiles in different scenarios.
Video Profile Definition
Video profile | Resolution | Frame rate (fps) | Bitrate (Kbps) | Chrome | Firefox/Opera | Safari |
---|---|---|---|---|---|---|
120p | 160 × 120 | 15 | 65 | ✓ | ||
120p_1 | 160 × 120 | 15 | 65 | ✓ | ||
120p_3 | 120 × 120 | 15 | 50 | ✓ | ||
180p | 320 × 180 | 15 | 140 | ✓ | ||
180p_1 | 320 × 180 | 15 | 140 | ✓ | ||
180p_3 | 180 × 180 | 15 | 100 | ✓ | ||
180p_4 | 240 × 180 | 15 | 120 | ✓ | ||
240p | 320 × 240 | 15 | 200 | ✓ | ||
240p_1 | 320 × 240 | 15 | 200 | ✓ | ||
240p_3 | 240 × 240 | 15 | 140 | ✓ | ||
240p_4 | 424 × 240 | 15 | 220 | ✓ | ||
360p | 640 × 360 | 15 | 400 | ✓ | ||
360p_1 | 640 × 360 | 15 | 400 | ✓ | ||
360p_3 | 360 × 360 | 15 | 260 | ✓ | ||
360p_4 | 640 × 360 | 30 | 600 | ✓ | ||
360p_6 | 360 × 360 | 30 | 400 | ✓ | ||
360p_7 | 480 × 360 | 15 | 320 | ✓ | ||
360p_8 | 480 × 360 | 30 | 490 | ✓ | ||
360p_9 | 640 × 360 | 15 | 800 | ✓ | ||
360p_10 | 640 × 360 | 24 | 800 | ✓ | ||
360p_11 | 640 × 360 | 24 | 1000 | ✓ | ||
480p | 640 × 480 | 15 | 500 | ✓ | ✓ | ✓ |
480p_1 | 640 × 480 | 15 | 500 | ✓ | ✓ | ✓ |
480p_2 | 648 × 480 | 30 | 1000 | ✓ | ✓ | ✓ |
480p_3 | 480 × 480 | 15 | 400 | ✓ | ✓ | ✓ |
480p_4 | 640 × 480 | 30 | 750 | ✓ | ✓ | ✓ |
480p_6 | 480 × 480 | 30 | 600 | ✓ | ✓ | ✓ |
480p_8 | 848 × 480 | 15 | 610 | ✓ | ✓ | ✓ |
480p_9 | 848 × 480 | 30 | 930 | ✓ | ✓ | ✓ |
480p_10 | 640 × 480 | 10 | 400 | ✓ | ✓ | ✓ |
720p | 1280 × 720 | 15 | 1130 | ✓ | ✓ | ✓ |
720p_1 | 1280 × 720 | 15 | 1130 | ✓ | ✓ | ✓ |
720p_2 | 1280 × 720 | 15 | 2080 | ✓ | ✓ | ✓ |
720p_3 | 1280 × 720 | 30 | 1710 | ✓ | ✓ | ✓ |
720p_5 | 960 × 720 | 15 | 910 | ✓ | ✓ | ✓ |
720p_6 | 960 × 720 | 30 | 1380 | ✓ | ✓ | ✓ |
1080p | 1920 × 1080 | 15 | 2080 | ✓ | ✓ | |
1080p_1 | 1920 × 1080 | 15 | 2080 | ✓ | ✓ | |
1080p_2 | 1920 × 1080 | 30 | 3000 | ✓ | ✓ | |
1080p_3 | 1920 × 1080 | 30 | 3150 | ✓ | ✓ | |
1080p_5 | 1920 × 1080 | 60 | 4780 | ✓ | ✓ | |
1440p | 2560 × 1440 | 30 | 4850 | ✓ | ✓ | |
1440p_1 | 2560 × 1440 | 30 | 4850 | ✓ | ✓ | |
1440p_2 | 2560 × 1440 | 60 | 7350 | ✓ | ✓ | |
4K | 3840 × 2160 | 30 | 8910 | ✓ | ✓ | |
4K_1 | 3840 × 2160 | 30 | 8910 | ✓ | ✓ | |
4K_3 | 3840 × 2160 | 60 | 13500 | ✓ | ✓ |
Note:
Whether 1080 resolution or above can be supported depends on the device. If the device cannot support 1080p, the actual frame rate is lower than the one listed in the table. Agora optimizes the video on low-end devices.
The Safari browser does not support modifying the video frame rate (30 fps by default). If you set a frame rate other than 30 fps on Safari, the browser may change or reject your setting.
Due to limitations of some devices and browsers, the resolution you set may fail to take effect and get adjusted by the browser. In this case, billings are calculated based on the actual resolution.
Starts Audio Mixing
This method mixes the specified online audio file with the audio stream from the microphone; or, it replaces the microphone’s audio stream with the specified online audio file.
You can specify the number of playback loops and play time duration.
Note:
Audio mixing settings.
Number of playback loops (only supports Chrome 65+)
A positive integer. The value range is [1,10000]. The default value is 1.
Path of the online audio file to mix. ASCII characters only, and the string length must be greater than 0 and less than 256 bytes.
Supported audio formats: mp3, aac, and other audio formats depending on the browser.
Whether the audio mixing file loops infinitely.
true
: The audio mixing file loops infinitely. Do not use this option if cycle
is specified.false
: (Default) Disables the infinite loops.Sets the playback position (ms) of the audio mixing file. An integer, and the value range is [0,100000000].
If you need to play the file from the beginning, set this paramter to 0.
Whether the online audio file replaces the local audio stream.
true
: The content of the online audio file replaces the audio stream from the microphone.false
: (Default) The online audio file is mixed with the audio stream from the microphone.Note:
Safari does not support this parameter.
The callback of this method:
Note: The callbacks of the other audio mixing methods are the same as this one, using the Node.js callback pattern.
Stops the Audio/Video Stream
Call this method to stop playing the stream set by Stream.play.
Stops Audio Mixing
Switches the Media Input Device
This method switches between the media input devices:
If you call this method after publish, there is no need to re-publish the stream after switching the device.
Note:
This method does not support the following scenarios:
Type of the device: "audio" or "video".
Device ID, which can be retrieved from getDevices. The retrieved ID is ASCII characters, and the string length is greater than 0 and less than 256 bytes.
The callback when the method succeeds.
The callback when the method fails.
Enables the Audio
This method enables the audio track in the stream.
Note: For local streams, it works only when the audio flag is true
in the stream.
By default the audio track is enabled. If you call muteAudio, call this method to enable audio.
true
: Success.false
: Failure. Possible reasons include no audio, stream not initialized, and audio track already enabled.Enables the Video
This method enables the video track in the stream.
Note: For local streams, it works only when the video flag is true
in the stream.
By default the video track is enabled. If you call muteVideo, call this method to enable video.
true
: Success.false
: Failure. Possible reasons include no video, stream not initialized, and video track already enabled.
The Stream object created by the createStream method.
A stream represents a published local or remote media stream object in a call session.
All Stream methods can be called for both local and remote streams, except for Stream.init that only applies to the local stream.