PlaybackAudioTrack

更新时间:
复制 MD 格式

The PlaybackAudioTrack is the audio track for the local speaker.

Inherits from: LocalAudioTrack

Properties

Property

Type

Description

Minimum supported version

deviceId

string

Gets 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

setDevice()

Update the media device set for capturing track data

1.0.0

setEnabled()

Enables or disables the microphone track.

1.0.0

setMuted()

Mutes or unmutes the microphone track.

1.0.0

getVolume()

Gets the current playback volume.

1.0.0

getVolumeLevel()

Gets the volume level of the local audio track.

1.0.0

setVolume()

Sets the playback volume.

1.0.0

getTrackId()

Gets the stream track ID.

1.0.0

getTrackLabel()

Gets the stream track label.

1.0.0

play()

Plays the media track on the page.

1.0.0

stop()

Stops playback.

1.0.0

off()

Removes a listener for a specified event.

1.0.0

on()

Adds a listener for a specified event.

1.0.0

once()

Adds a one-time listener for a specified event. The listener is removed after the event is triggered.

1.0.0

removeAllListeners()

Removes all listeners for a specified event or for all events.

1.0.0

startTest()

Starts testing the microphone track.

1.0.0

stopTest()

Stops testing the microphone track.

1.0.0

Interface Details

setDevice()

Update the media device for track data capture

Type signature

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

Back

void

getVolume()

Retrieves the current playback volume.

Type Signature

getVolume(): number;

Returns

number

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

Returns

void

getTrackId()

Retrieves the stream track ID.

Type Signature

getTrackId(): string;

Returns

string

The stream track ID.

play()

Plays the media track on the page.

Type signature

play(): void;

Returns

void

stop()

Stops playback.

Type signature

stop(): void;

Returns

void

close()

Closes the local track and releases the related capture device.

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

Type Signature

close(): void;

Back

void

getTrackLabel()

Retrieves the source description of the local track.

Signature

getTrackLabel(): string;

Returns

string

The description of the audio or video track.

setDevice()

Sets the media device for the track.

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, playback and publishing stop. If the track is already published, calling `setEnabled` triggers the `user-info-updated` event on the remote end.

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>

Note

The difference between `setEnabled` and `setMuted` is that `setMuted` has a faster response 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 indicator stays on.

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

Type signature

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

Parameters

Parameter

Parameter

Description

muted

boolean

Specifies whether to send (true) or pause sending (false) media data for this track.

Returns

Promise<void>

on()

Adds a listener for a specified event.

Type Signature

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

Parameters

Parameter

Type

Description

event

string

The event to listen for.

fn

Function

The callback function to execute when the event is triggered.

Returns

void

off()

Removes a listener for a specified event.

Type signature

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

Parameters

Parameter

Type

Description

event

string

The specific event to listen for.

fn

Function

The callback function that runs when the event is triggered.

Returns

void

once()

Adds a one-time listener for a specified event. The listener is removed after the callback function is executed.

Type signature

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

Parameters

Parameter

Type

Description

event

string

The event to listen for.

fn

Function

The callback function to execute when the event is triggered.

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

enableSystemAudio()

Enables or disables system audio mixing.

Type Signature

enableSystemAudio(enable: boolean): void

Parameters

Parameter

Type

Description

enable

boolean

Specifies whether to mix system audio.

Returns

void

startTest()

Starts testing the microphone track.

Signature

startTest(): void

Returns

void

stopTest()

Stops testing the microphone track.

Type signature

stopTest(): void

Returns

void