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 will be reset.
Disables the Audio
This method disables the audio track in the stream.
It works only when the audio flag is true
in the stream.
Disables the Video
This method disables the video track in the stream.
It works only when the video flag is true
in the stream.
Enables the Audio
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 called disableAudio, call this method to enable audio.
Enables the Video
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 called 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 stream object.
If this method fails, the returned callback will show the error message, for example: {type: "error", msg: "MEDIA_OPTION_INVALID"}
.
The error messages include:
The callback when the method succeeds.
The callback when the method fails.
This callback notifies the application that the user has given access to the camera and microphone.
This callback notifies the application that the user has denied access to the camera and microphone.
This callback notifies the application that screen-sharing has stopped.
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.
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.
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.
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".
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:
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.
Path of the online audio file to mix. Supported audio formats: mp3, aac, and other audio formats depending on the browser.
Whether the audio mixing file loops infinitely.
cycle
is specified.Sets the playback position (ms) of the audio mixing file. 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.
Note:
Safari does not support this parameter.
The callback of this method:
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 callback when the method succeeds.
The callback when the method fails.
The Stream object created by the createStream method.
A stream represents a published local or remote media stream object in a call session.