LocalVideoTrack

更新时间: 2026-01-18 18:59:14

LocalVideoTrack is the base class for local video tracks. It provides the primary features of local video tracks.

Inherits from: LocalTrack

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

API

Description

Minimum supported version

setEnabled()

Enables or disables the video track.

1.0.0

setMuted()

Pauses or resumes the video track.

1.0.0

getCurrentFrameData()

Gets the data of the currently rendered video frame.

1.0.0

setEncoderConfiguration()

Updates the video track encoding settings to adjust video quality.

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 the playback.

1.0.0

off()

Removes the callback function for a specified event.

1.0.0

on()

Listens for a specified event and sets a callback function.

1.0.0

once()

Listens for a specified event once. The callback function is removed after it is triggered.

1.0.0

removeAllListeners()

Removes the callbacks for a specified event or all events of this object.

1.0.0

setDevice()

Updates the media device that the track uses.

1.0.0

API details

getCurrentFrameData()

You can call this method only after playback starts. If play() has not been called, this method returns empty data.

Retrieves the data of the currently rendered video frame.

Type signature

getCurrentFrameData(): string;

Returns

A data URL of the 'image/png' type.

setEncoderConfiguration()

For versions earlier than 3.8.0, ensure that the video track is not being published when you call this method. If the track is already published, you must first unpublish it, call this method, and then publish it again.

Updates the video track encoding settings to adjust the video quality.

Type Signature

VideoEncoderConfigurationsetEncoderConfiguration(config: <a baseurl="t3055974_v1_0_0.xdita" data-node="4688872" data-root="16740" data-tag="xref" href="t2584362.xdita#bbc425705ddqw" id="71f2001279oh4">VideoEncoderConfiguration</a>): Promise<void>;

Returns

Promise<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(element?: string | HTMLElement, config?: VideoPlayerConfig): void;

Parameters

Parameter

Type

Description

element

string | HTMLElement

(Optional) Specifies a DOM element. The SDK creates a video element under this DOM element to play the video track. Two types are supported:

- string: The ID of the DOM element.

- HTMLElement: The DOM element object itself.

config

VideoPlayerConfig

(Optional) The video media playback parameters.

Back

void

stop()

Stop playback

Type Signature

stop(): void;

Returns

void

close()

Closes the local track and releases the associated capture device.

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

Type Signature

close(): void;

Returns

void

getTrackLabel()

Obtains the source description of the local track.

Type signature

getTrackLabel(): string;

Back

string

The 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

Parameters

Description

deviceId

string

The device ID.

Returns

Promise<void>

setEnabled()

You can enable or disable the track.

Disabling a track stops both playback and publishing. If the track is already published, calling setEnabled 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.

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, calling setEnabled to disable a camera track turns off the camera's LED indicator, whereas calling setMuted does not.

Do not call setEnabled and setMuted at the same time.

setMuted()

Starts or stops sending media data on the track.

Calling setMuted on a published track triggers the user-info-updated event on the remote client.

Signature

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

Parameters

Parameter

Parameters

Description

muted

boolean

Sends (`true`) or pauses sending (`false`) media data for the track.

Returns

Promise<void>

on()

Sets a callback function to listen for a specified event.

Type signature

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

Parameters

Parameter

Type

Description

event

string

The specified event to listen for.

fn

Function

The callback function that is triggered when the event occurs.

Back

void

off()

Removes the callback function for a specified event.

Type signature

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

Parameters

Parameter

Type

Description

event

string

Specify an event for the listener

fn

Function

The callback function for the event listener.

Back

void

once()

Listens for a specified event once. The callback function is removed after being triggered.

Type signature

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

Parameters

Parameter

Type

Description

event

string

The specified event to listen for.

fn

Function

The callback function that is triggered when the event occurs.

Returns

void

removeAllListeners()

Removes the callbacks for a specified event or all callbacks from this object.

Type Signature

removeAllListeners(event?: string): void;

Parameters

Parameter

Type

Description

event

string

(Optional) If an event is specified, its corresponding callback functions are removed. If this parameter is left empty, the listeners for all events of the object are removed.

Back

void

上一篇: LocalTrack 下一篇: CameraVideoTrack
阿里云首页 音视频通信 相关技术圈