MicrophoneAudioTrack
MicrophoneAudioTrack is an audio track captured from a local microphone.
Inherited from:LocalAudioTrack
Properties
Property | Type | Description | Supported since |
deviceId | string | The ID of the media device. | 1.0.0 |
isPlaying | boolean | Indicates if the media track is playing. | 1.0.0 |
APIs
API | Description | Supported since |
Changes the media device used for the track. | 1.0.0 | |
Enables or disables the microphone track. | 1.0.0 | |
Pauses or resumes sending the track's media data. | 1.0.0 | |
Pauses or resumes sending media data from the microphone. | 1.0.0 | |
Gets the current playback volume. | 1.0.0 | |
Gets the volume level of the local audio track. | 1.0.0 | |
Sets the playback volume. | 1.0.0 | |
Gets the track ID. | 1.0.0 | |
Gets the track label. | 1.0.0 | |
Plays the media track for local preview. | 1.0.0 | |
Stops playback. | 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 | |
Enables or disables mixing of system audio. | 1.0.0 | |
Starts testing the microphone track. | 1.0.0 | |
Stops testing the microphone track. | 1.0.0 |
API details
setDevice()
Changes the microphone used for this audio track.
Signature
setDevice(deviceId: string): Promise<void>;
Returns
A Promise that resolves when the device is successfully changed.
getVolume()
Gets the current playback volume.
Signature
getVolume(): number;
Returns
number
The current playback volume.
getVolumeLevel()
Gets the volume level of the local audio track.
Signature
getVolumeLevel(): number;
Returns
number
The volume level, from 0 to 1, where 1 is the maximum volume. A value over 0.6 typically indicates the user is speaking.
setVolume()
Sets the playback volume.
Signature
setVolume(volume: number): void;
Parameters
Parameter | Type | Description |
volume | number | The volume, from 0 (mute) to 1 (original volume). |
Returns
void
getTrackId()
Gets the track ID.
Signature
getTrackId(): string;
Returns
string
The track ID.
play()
Plays the media track for local preview.
Signature
play(): void;
Returns
void
stop()
Stops playback.
Signature
stop(): void;
Returns
void
close()
Closes the local track and releases the associated capture device.
A closed track cannot be reused. You must create a new track to use the device again.
Signature
close(): void;
Returns
void
getTrackLabel()
Gets the track label.
Signature
getTrackLabel(): string;
Returns
string
The track label.
setDevice()
Changes the microphone used for this audio track.
Signature
setDevice(deviceId: string): Promise<void>;
Parameters
Parameter | Type | Description |
deviceId | string | The device ID. |
Returns
A Promise that resolves when the device is successfully changed.
setEnabled()
Enables or disables the track.
Disabling a track stops both local playback and remote publishing. If the track is published, this action triggers a user-info-updated event for remote users.
Signature
setEnabled(enabled: boolean): Promise<void>;
Parameters
Parameter | Type | Description |
enabled | boolean | Specifies whether to enable the track. |
Returns
Promise<void>
setEnabled differs from setMuted. The setMuted method responds faster and does not affect the device's capture status. For example, using setEnabled(false) on a camera track turns off its indicator light, while setMuted(true) does not.
Do not call setEnabled and setMuted concurrently.
setMuted()
Pauses or resumes sending the track's media data.
If the track is already published, calling setMuted triggers a user-info-updated event for remote users.
Signature
setMuted(muted: boolean): Promise<void>;
Parameters
Parameter | Type | Description |
muted | boolean | Specifies whether to mute the track's media data. |
Returns
Promise<void>
setDataMuted()
Pauses or resumes sending media data from the microphone without affecting shared audio.
Signature
setDataMuted(muted: boolean): Promise<void>;
Parameters
Parameter | Type | Description |
muted | boolean | Specifies whether to mute the microphone's media data. |
Returns
Promise<void>
on()
Adds a listener for a specified event.
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.
Signature
off(event: string, fn: Function): void;
Parameters
Parameter | Type | Description |
event | string | The event to stop listening for. |
fn | Function | The callback function to remove. |
Returns
void
once()
Adds a one-time listener that is removed after it is triggered.
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. |
Returns
void
removeAllListeners()
Removes all listeners for a specified event. If the event is omitted, it removes all listeners for all events.
Signature
removeAllListeners(event?: string): void;
Parameters
Parameter | Type | Description |
event | string | (Optional) The event for which to remove all listeners. If this parameter is omitted, all listeners for all events on the object are removed. |
Returns
void
enableSystemAudio()
Enables or disables mixing of system audio.
Signature
enableSystemAudio(enable: boolean): void
Parameters
Parameter | Type | Description |
enable | boolean | Specifies whether to enable system audio mixing. Use true to enable or false to disable. |
Returns
void
startTest()
Starts testing the microphone track.
Signature
startTest(): voidReturns
void
stopTest()
Stops testing the microphone track.
Signature
stopTest(): voidReturns
void