MicrophoneAudioTrack

更新时间:
复制 MD 格式

MicrophoneAudioTrack represents a local audio track from a microphone.

Inherits from: LocalAudioTrack

Properties

Property

Type

Description

Minimum supported version

isPlaying

boolean

Indicates whether the media track is playing.

3.0.0

trackMediaType

TrackMediaType

The type of the media track.

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

setDevice()

Updates the media device that collects data for the track.

3.0.0

setEnabled()

Enables or disables the microphone track.

3.0.0

setMuted()

Mutes or unmutes the microphone track.

3.0.0

getVolume()

Gets the current playback volume.

3.0.0

getVolumeLevel()

Gets the volume level of the local audio track.

3.0.0

setVolume()

Sets the playback volume.

3.0.0

getMediaStreamTrack()

Gets the media track.

3.0.0

getTrackId()

Gets the stream track ID.

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 specified event.

3.0.0

on()

Adds a listener for a specified event.

3.0.0

once()

Adds a one-time listener for a specified event. The listener is removed after it is invoked.

3.0.0

removeAllListeners()

Removes the listeners for a specified event or all events on this object.

3.0.0

API details

setDevice()

Update the media device to capture track data

Type signature

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

Returns

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, where 1 is the theoretical maximum volume. A value greater than 0.6 typically indicates that the user is speaking.

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, where 0 is muted and 1 is the original volume.

Returns

void

getMediaStreamTrack()

Obtaining a media track

Type signature

getMediaStreamTrack(): MediaStreamTrack;

Returns

MediaStreamTrack

The MediaStreamTrack object.

getTrackId()

Retrieves the ID of the stream track.

Type Signature

getTrackId(): string;

Returns

string

The ID of the stream track.

play()

Plays the audio track on the page.

Type signature

play(): void;

Returns

void

replaceTrack()

Replacing audio and video tracks

Type signature

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

Parameter

Type

Description

track

MediaStreamTrack

The audio or video track.

stopOldTrack

boolean

(Optional) Specifies whether to stop the previous track.

Returns

void

stop()

Stops the audio 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. You must create a new instance to use the local track again.

Type Signature

close(): void;

Returns

void

getTrackLabel()

Retrieves the source description of the local track.

Type signature

getTrackLabel(): string;

Back

string

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.

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, calling setEnabled triggers the user-info-updated event for remote users.

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

`setMuted` is faster than `setEnabled` and does not affect the device's capture state. For example, calling `setEnabled(false)` on a camera track turns off the camera's LED indicator, but calling `setMuted(true)` does not.

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

setMuted()

Pauses or sends the media data on the track.

If the track is already published, calling setMuted triggers the user-info-updated event for remote users.

Type Signature

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

Parameters

Parameter

Parameters

Description

muted

boolean

Specifies whether to send media data for the track - true: Sends media data - false: Pauses sending media data

Returns

Promise<void>

on()

Registers 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 run when the event is triggered.

Returns

void

off()

You can remove a listener for a specified event.

Type signature

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

Parameters

Parameter

Type

Description

event

string

The event to listen for.

fn

Function

The callback function to run when the event is triggered.

Back

void

once()

Adds a one-time listener for a specified event. The listener is invoked only once.

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 run when the event is triggered.

Returns

void

removeAllListeners()

Removes all listeners for a specified event, or for all events if no event is specified.

Type Signature

removeAllListeners(event?: string): void;

Parameters

Parameter

Type

Description

event

string

(Optional) The event to remove listeners from. If you specify an event, all listeners for that event are removed. If you omit this parameter, all listeners for all events on the object are removed.

Returns

void