The base local audio track, which provides the primary features for local audio.
Inherits from: LocalTrack
Properties
Property | Type | Description | Minimum supported version |
deviceId | string | You can obtain the device ID. | 1.0.0 |
isPlaying | boolean | Indicates whether the media track is playing. | 1.0.0 |
API List
Interface | Description | Minimum supported version |
Enables or disables the audio track. | 1.0.0 | |
Pause or resume an audio track | 1.0.0 | |
Gets the current playback volume. | 1.0.0 | |
Set the playback volume | 1.0.0 | |
Gets the track ID of the stream. | 1.0.0 | |
Removes a listener for a specified event. | 1.0.0 | |
Adds a listener for a specified event. | 1.0.0 | |
Adds a one-time listener for a specified event. | 1.0.0 | |
Removes all listeners for a specified event or for all events. | 1.0.0 |
API Details
getVolume()
Retrieves the current playback volume.
Type signature
getVolume(): number;
Returns
The current playback volume.
getVolumeLevel()
Retrieves the volume level of the local audio track.
Type signature
getVolumeLevel(): number;
Returns
number
The volume level. The value ranges from 0 to 1. A value of 1 indicates the theoretical maximum volume. A value greater than 0.6 usually indicates that the user is speaking continuously.
setVolume()
Sets the playback volume.
Type signature
setVolume(volume: number): void;
Parameters
Parameter | Type | Description |
volume | number | The volume level. The value ranges from 0 to 1. A value of 0 indicates mute, and 1 indicates the original volume. |
Returns
void
getTrackId()
Retrieves the track ID of the stream.
Type Signature
getTrackId(): string;
Returns
string
The track ID of the stream.
play()
Plays the media track on the webpage.
Type Signature
play(): void;
Returns
void
stop()
Stops the playback.
Type Signature
stop(): void;
Returns
void
close()
Closes the local track and releases the associated capture device.
Once a local track is closed, it cannot be reused. To use the track again, you must create a new one.
Type Signature
close(): void;
Returns
void
getTrackLabel()
Retrieves the source description of the local track.
Type signature
getTrackLabel(): string;
Returns
string
Description of the audio or video track
setDevice()
Updates the media device used by the track.
Type signature
setDevice(deviceId: string): Promise<void>;
Parameters
Parameter | Type | Description |
deviceId | string | The device ID. |
Returns
Promise<void>
setEnabled()
Enables or disables the track.
When a track is disabled, both playback and publishing stop. If the track is already published, this call triggers the `user-info-updated` event on the remote client.
Type signature
setEnabled(enabled: boolean): Promise<void>;
Parameters
Parameter | Parameters | Description |
enabled | boolean | Specifies whether to enable the track.`true`: Enable the track.`false`: Disable the track. |
Back
Promise<void>
The difference between `setEnabled` and `setMuted` is that `setMuted` responds faster and does not affect the capture state of the audio or video device. For example, when you call `setEnabled` to disable a camera track, the camera's LED indicator turns off, whereas `setMuted` does not.
Do not call `setEnabled` and `setMuted` at the same time.
setMuted()
Stops or resumes sending the media data of the track.
If the track is already published, this call triggers the `user-info-updated` event on the remote client.
Type Signature
setMuted(muted: boolean): Promise<void>;
Parameters
Parameter | Parameters | Description |
muted | boolean | Specifies whether to send (true) or pause sending (false) the media data for the track. |
Returns
Promise<void>
on()
Adds a listener for a specified event and registers a callback function.
Type Signature
on(event: string, fn: Function): void;
Parameters
Parameter | Type | Description |
event | string | The event to listen for. |
fn | Function | The callback function that is triggered when the event occurs. |
Returns
void
off()
Removes a listener for a specified event.
Type signature
off(event: string, fn: Function): void;
Parameters
Parameter | Type | Description |
event | string | Specify events to monitor |
fn | Function | Callback function for event triggers |
Returns
void
once()
Adds a one-time listener for a specified event. The listener is removed after the callback function is triggered.
Type signature
once(event: string, fn: Function): void;
Parameters
Parameter | Type | Description |
event | string | The event to listen for. |
fn | Function | The callback function that is triggered when the event occurs. |
Returns
void
removeAllListeners()
Removes listeners for a specified event or for all events on the object.
Type signature
removeAllListeners(event?: string): void;
Parameters
Parameter | Type | Description |
event | string | (Optional) The event for which to remove listeners. If you specify an event, all listeners for that event are removed. If you do not specify this parameter, all listeners for all events on the object are removed. |
Returns
void