LocalAudioTrack

更新时间:
复制 MD 格式

This is the base class for local audio tracks and provides their core features.

Inherits from:LocalTrack

Properties

Property

Type

Description

Minimum supported version

isPlaying

boolean

Indicates whether the media track is playing.

3.0.0

trackMediaType

TrackMediaType

The media track type.

3.0.0

enabled

boolean

The current enabled state of the local track.

3.0.0

muted

boolean

Indicates whether the track is muted.

3.0.0

API list

Interface

Description

Minimum supported version

setEnabled()

Enables or disables the audio track.

3.0.0

setMuted()

Pausing and Resuming an Audio Track

3.0.0

getVolume()

Gets the current playback volume.

3.0.0

setVolume()

Sets the playback volume.

3.0.0

getMediaStreamTrack()

Gets the media track.

3.0.0

getTrackId()

Gets the track ID of the stream.

3.0.0

play()

Plays the media track on the page.

3.0.0

replaceTrack()

Replaces the audio or video track.

3.0.0

stop()

Stops the playback.

3.0.0

off()

Removes the callback function for a specific event listener.

3.0.0

on()

Listens for a specific event and sets a callback function.

3.0.0

once()

Listens for a specific event once. The listener is removed after the callback function is triggered.

3.0.0

removeAllListeners()

Removes the listeners for a specific event or for all events of the object.

3.0.0

API Details

getVolume()

Retrieves the current playback volume.

Type signature

getVolume(): number;

Returns

The current playback volume.

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 means muted, and a value of 1 means the original volume.

Returns

void

getMediaStreamTrack()

Retrieves the media track.

Type Signature

getMediaStreamTrack(): MediaStreamTrack;

Returns

MediaStreamTrack

The media track.

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 page.

Signature

play(): void;

Returns

void

replaceTrack()

Replaces the audio or video track.

Type Signature

replaceTrack(track: MediaStreamTrack, stopOldTrack?: boolean): void;

Parameter

Type

Description

track

MediaStreamTrack

Audio and video tracks

stopOldTrack

boolean

(Optional) Specifies whether to stop the previous track.

Back

void

stop()

Stops the playback.

Type Signature

stop(): void;

Returns

void

close()

Closes the local track and releases the associated capture device.

After a local track is closed, it cannot be reused. To use the local track again, you must create a new one.

Type Signature

close(): void;

Returns

void

getTrackLabel()

Retrieves the source description of the local track.

Signature

getTrackLabel(): string;

Returns

string

The description of the audio or video track.

setDevice()

Updates the media device used by the track.

Signature

setDevice(deviceId: string): Promise<void>;

Parameters

Parameter

Type

Description

deviceId

string

The device ID.

Back

Promise<void>

setEnabled()

Enables or disables the track.

When a track is disabled, both playback and publishing are stopped. If the track is already published, calling `setEnabled` may trigger the `user-info-updated` event for other users. The rules are the same as for `setMuted`. The difference between this method and `setMuted` is whether the internal `MediaStream` is destroyed and whether the media device remains in use.

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.

Returns

Promise<void>

Note

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. When you call `setMuted`, the LED indicator does not turn off.

Do not call `setEnabled` and `setMuted` at the same time.

setMuted()

Sends or stops sending the media data of the track.

If the track is already published, calling `setMuted` triggers the `user-info-updated` event on the remote client.

If the current track is an audio stream from a microphone or screen sharing, other users receive a `user-info-updated` event only when the last audio source is muted. The event parameter is `mute-audio` or `unmute-audio`.

You can call this method before you publish the track. The mute action is applied after publishing. If this is the last track to be muted, other users receive a `user-info-updated` event.

Type signature

setMuted(muted: boolean): Promise<void>;

Parameters

Parameter

Parameters

Description

muted

boolean

Specifies whether to send or stop sending the media data of the track. - true: Stop sending media data. - false: Resume sending media data.

Returns

Promise<void>

on()

Listens for a specific event and sets 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 the callback function for a specific event listener.

Type Signature

off(event: string, fn: Function): void;

Parameters

Parameter

Type

Description

event

string

The specified event to listen for.

fn

Function

The callback function that is executed when the event is triggered.

Returns

void

once()

Listens for a specific event once. 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 the listeners for a specific event or for all events of the object.

Type signature

removeAllListeners(event?: string): void;

Parameters

Parameter

Type

Description

event

string

(Optional) If you specify an event, the listeners for that event are removed. If you do not specify this parameter, all listeners for all events of the object are removed.

Returns

void