TXDeviceManager
Copyright (c) 2026 Tencent. All rights reserved.
Module: TXDeviceManager @ TXLiteAVSDK
Function: Audio/video device management (camera, microphone, speaker, audio route, etc.)
Version: 13.5
Audio/video device management APIs. Flutter SDK:
tencent_rtc_sdk. Obtain the instance via TRTCCloud's getDeviceManager() and then call the APIs.Platform Category | Applicable Platforms | Return Value on Unsupported Platforms |
Mobile only | Android / iOS / HarmonyOS | int/double returns -1.bool returns false. |
Desktop only | Windows / macOS | int returns -1.bool returns false.List returns an empty list.TXDeviceInfo returns an empty object. |
Windows only | Windows | int returns -1. |
Function List
Mobile Device APIs
API | Description |
Queries whether the front camera is being used (mobile only). | |
Switches between the front and rear cameras (mobile only). | |
Gets the maximum zoom ratio of the camera (mobile only). | |
Sets the zoom ratio of the camera (mobile only). | |
Queries whether automatic face position recognition is supported (mobile only). | |
Enables auto focus (mobile only). | |
Sets the focus position of the camera (mobile only). | |
Turns on/off the flash, i.e., the torch mode (mobile only). | |
Sets the audio route (mobile only). |
Desktop Device APIs
API | Description |
Gets the device list (desktop only). | |
Sets the device to use (desktop only). | |
Gets the device currently in use (desktop only). | |
Sets the volume of the current device (desktop only). | |
Gets the volume of the current device (desktop only). | |
Sets the mute status of the current device (desktop only). | |
Queries whether the current device is muted (desktop only). | |
Sets the audio device used by the SDK to follow the system default device (desktop only). |
Device Testing (Desktop)
API | Description |
Starts camera test (desktop only). | |
Stops camera test (desktop only). | |
Starts microphone test (desktop only). | |
Starts microphone test, with the option to play back the microphone sound (desktop only). | |
Stops microphone test (desktop only). | |
Starts speaker test (desktop only). | |
Stops speaker test (desktop only). |
Windows Volume Mixer
API | Description |
Sets the volume of the current process in the Windows volume mixer (Windows only). | |
Gets the volume of the current process in the Windows volume mixer (Windows only). | |
Sets the mute status of the current process in the Windows volume mixer (Windows only). | |
Gets the mute status of the current process in the Windows volume mixer (Windows only). |
General APIs
API | Description |
Sets camera capture preferences. | |
Sets the device status change callback ( onDeviceChanged). |
API Details
The following describes the signature, function, parameters, return value and notes of each API, in the order of the function list.
isFrontCamera
bool isFrontCamera()
Queries whether the front camera is being used (mobile only).
Return Value
true: The front camera is being used.false: The rear camera is being used, or this API is not supported on the current platform.switchCamera
int switchCamera(bool frontCamera)
Switches between the front and rear cameras (mobile only).
Parameter | Type | Description |
frontCamera | bool | true: Front camera.false: Rear camera. |
Return Value
Result of the API call. Returns
-1 if not supported on the current platform.getCameraZoomMaxRatio
double getCameraZoomMaxRatio()
Gets the maximum zoom ratio of the camera (mobile only).
Return Value
Maximum zoom ratio supported by the camera. Returns
-1 if not supported on the current platform.setCameraZoomRatio
int setCameraZoomRatio(double ratio)
Sets the zoom ratio of the camera (mobile only).
Parameter | Type | Description |
ratio | double | Zoom ratio. Value range: 1 - 5. 1: Widest view (normal lens).5: Closest view (zoomed-in lens).It is recommended that the maximum value not exceed 5; beyond that, the image becomes blurry. |
Return Value
Result of the API call. Returns
-1 if not supported on the current platform.isAutoFocusEnabled
bool isAutoFocusEnabled()
Queries whether automatic face position recognition is supported (mobile only).
Return Value
true: Supported.false: Not supported, or this API is not supported on the current platform.enableCameraAutoFocus
int enableCameraAutoFocus(bool enabled)
Enables auto focus (mobile only).
After it is enabled, the SDK automatically detects faces in the image and keeps the focus on them.
Parameter | Type | Description |
enabled | bool | true: Enable.false: Disable. |
Return Value
Result of the API call. Returns
-1 if not supported on the current platform.setCameraFocusPosition
int setCameraFocusPosition(double x, double y)
Sets the focus position of the camera (mobile only).
You can use this API to implement the following interaction:
1. The user taps an area on the local camera preview.
2. A rectangle is displayed at the tapped position, indicating that the camera will focus there.
3. Pass the coordinates of the tapped position to the SDK via this API, and the SDK will control the camera to focus on that position.
Parameter | Type | Description |
x | double | X coordinate of the desired focus point. |
y | double | Y coordinate of the desired focus point. |
Description:
Return Value
0: Operation succeeded.Negative number: Operation failed (returns
-1 if not supported on the current platform).enableCameraTorch
int enableCameraTorch(bool enabled)
Turns on/off the flash, i.e., the torch mode (mobile only).
Parameter | Type | Description |
enabled | bool | true: Enable.false: Disable. |
Return Value
Result of the API call. Returns
-1 if not supported on the current platform.setAudioRoute
int setAudioRoute(TXAudioRoute route)
Sets the audio route (mobile only).
A mobile phone has two audio playback devices: the earpiece at the top of the phone and the stereo speaker at the bottom.
Earpiece: The sound is relatively low and can be heard clearly only when the ear is close to it. It offers better privacy and is suitable for answering calls.
Speaker: The sound is relatively loud and can be heard clearly without holding the phone to the face, i.e., the "hands-free" feature.
Parameter | Type | Description |
route |
Return Value
Result of the API call. Returns
-1 if not supported on the current platform.getDevicesList
List<TXDeviceInfo> getDevicesList(TXMediaDeviceType type)
Gets the device list (desktop only).
Parameter | Type | Description |
type |
Return Value
List of device information. For details, see TXDeviceInfo. Returns an empty list if not supported on the current platform.
Sample Code
List<TXDeviceInfo> cameras = deviceManager.getDevicesList(TXMediaDeviceType.camera);for (TXDeviceInfo device in cameras) {debugPrint('${device.deviceName} (${device.devicePid})');}
setCurrentDevice
int setCurrentDevice(TXMediaDeviceType type, String deviceId)
Sets the device to use (desktop only).
Parameter | Type | Description |
type | ||
deviceId | String |
Return Value
0: Operation succeeded.Negative number: Operation failed (returns
-1 if not supported on the current platform).getCurrentDevice
TXDeviceInfo getCurrentDevice(TXMediaDeviceType type)
Gets the device currently in use (desktop only).
Parameter | Type | Description |
type |
Return Value
Current device information. For details, see TXDeviceInfo. Returns an object with all fields as empty strings if not supported on the current platform.
setCurrentDeviceVolume
int setCurrentDeviceVolume(TXMediaDeviceType type, int volume)
Sets the volume of the current device (desktop only).
This API sets the capture volume of the microphone or the playback volume of the speaker. Cameras are not supported.
Parameter | Type | Description |
type | ||
volume | int | Volume. Value range: 0 - 100. Default value: 100. |
Return Value
Result of the API call. Returns
-1 if not supported on the current platform.getCurrentDeviceVolume
int getCurrentDeviceVolume(TXMediaDeviceType type)
Gets the volume of the current device (desktop only).
This API gets the capture volume of the microphone or the playback volume of the speaker. Cameras are not supported.
Parameter | Type | Description |
type |
Return Value
Volume of the current device. Returns
-1 if not supported on the current platform.setCurrentDeviceMute
int setCurrentDeviceMute(TXMediaDeviceType type, bool mute)
Sets the mute status of the current device (desktop only).
This API mutes the microphone or speaker. Cameras are not supported.
Parameter | Type | Description |
type | ||
mute | bool | true: Mute.false: Unmute. |
Return Value
Result of the API call. Returns
-1 if not supported on the current platform.getCurrentDeviceMute
bool getCurrentDeviceMute(TXMediaDeviceType type)
Queries whether the current device is muted (desktop only).
This API queries whether the microphone or speaker is muted. Cameras are not supported.
Parameter | Type | Description |
type |
Return Value
true: The current device is muted.false: The current device is not muted, or this API is not supported on the current platform.enableFollowingDefaultAudioDevice
int enableFollowingDefaultAudioDevice(TXMediaDeviceType type, bool enable)
Sets the audio device used by the SDK to follow the system default device (desktop only).
This API supports only microphones and speakers. Cameras cannot follow the system default device.
Parameter | Type | Description |
type | ||
enable | bool | Whether to follow the system default audio device. true: Follow. When the system default audio device changes or a new audio device is plugged in, the SDK switches the audio device immediately.false: Do not follow. When the system default audio device changes or a new audio device is plugged in, the SDK does not switch the audio device. |
Return Value
Result of the API call. Returns
-1 if not supported on the current platform.startCameraDeviceTest
int startCameraDeviceTest(int viewId)
Starts camera test (desktop only).
Parameter | Type | Description |
viewId | int | ID of the control for rendering the camera test image. |
Description:
Return Value
Result of the API call. Returns
-1 if not supported on the current platform.stopCameraDeviceTest
void stopCameraDeviceTest()
Stops camera test (desktop only).
startMicDeviceTest
int startMicDeviceTest(int interval)
Starts microphone test (desktop only).
This API tests whether the microphone works properly. The detected microphone volume (value range: 0 - 100) is notified to you through the
onTestMicVolume callback in TRTCCloudListener.Parameter | Type | Description |
interval | int | Interval of the volume callback. |
Description:
After this API is called, the sound captured by the microphone is played back through the speaker by default. To control whether to play it back, use startMicDeviceTestAndPlayback.
Return Value
Result of the API call. Returns
-1 if not supported on the current platform.startMicDeviceTestAndPlayback
int startMicDeviceTestAndPlayback(int interval, bool playback)
Starts microphone test, with the option to play back the microphone sound (desktop only).
This API tests whether the microphone works properly. The detected microphone volume (value range: 0 - 100) is notified to you through the
onTestMicVolume callback in TRTCCloudListener.Parameter | Type | Description |
interval | int | Interval of the volume callback. |
playback | bool | Whether to play back the microphone sound. If true, the user will hear their own voice when testing the microphone. |
Return Value
Result of the API call. Returns
-1 if not supported on the current platform.stopMicDeviceTest
void stopMicDeviceTest()
Stops microphone test (desktop only).
startSpeakerDeviceTest
int startSpeakerDeviceTest(String filePath)
Starts speaker test (desktop only).
This API tests whether the playback device works properly by playing a specified audio file. If the user can hear the sound during the test, the playback device works properly. The playback volume is notified to you through the
onTestSpeakerVolume callback in TRTCCloudListener.Parameter | Type | Description |
filePath | String | Path of the audio file. |
Return Value
Result of the API call. Returns
-1 if not supported on the current platform.stopSpeakerDeviceTest
void stopSpeakerDeviceTest()
Stops speaker test (desktop only).
setApplicationPlayVolume
int setApplicationPlayVolume(int volume)
Sets the volume of the current process in the Windows volume mixer (Windows only).
Parameter | Type | Description |
volume | int | Volume of the current process. |
Return Value
Result of the API call. Returns
-1 if not supported on the current platform.getApplicationPlayVolume
int getApplicationPlayVolume()
Gets the volume of the current process in the Windows volume mixer (Windows only).
Return Value
Volume of the current process. Returns
-1 if not supported on the current platform.setApplicationMuteState
int setApplicationMuteState(bool mute)
Sets the mute status of the current process in the Windows volume mixer (Windows only).
Parameter | Type | Description |
mute | bool | true: Mute.false: Unmute. |
Return Value
Result of the API call. Returns
-1 if not supported on the current platform.getApplicationMuteState
int getApplicationMuteState()
Gets the mute status of the current process in the Windows volume mixer (Windows only).
Return Value
Mute status of the current process. Returns
-1 if not supported on the current platform.setCameraCaptureParam
void setCameraCaptureParam(TXCameraCaptureParam params)
Sets camera capture preferences.
Parameter | Type | Description |
params |
Sample Code
deviceManager.setCameraCaptureParam(TXCameraCaptureParam(mode: TXCameraCaptureMode.manual,width: 1280,height: 720,));
setDeviceObserver
int setDeviceObserver(TXDeviceObserver? observer)
Sets the device status change callback (
onDeviceChanged).Parameter | Type | Description |
observer | TXDeviceObserver? | Device status change callback object. For details, see TXDeviceObserver. Pass null to remove the callback. |
Return Value
0: Set successfully.Sample Code
deviceManager.setDeviceObserver(TXDeviceObserver(onDeviceChanged: (String deviceId, TXMediaDeviceType type, TXMediaDeviceState state) {debugPrint('device changed: $deviceId, $type, $state');},));
Type Definitions
TXAudioRoute
Audio route (i.e., the sound playback mode).
Enum Value | Value | Description |
unknown | -1 | Unknown. The default routing device is used. |
speakerPhone | 0 | Speaker: Plays through the speaker at the bottom of the phone (i.e., "hands-free") at a high volume, suitable for playing music aloud. |
earpiece | 1 | Earpiece: Plays through the earpiece at the top of the phone at a low volume, suitable for call scenarios requiring privacy. |
wiredHeadset | 2 | Wired headset. |
bluetoothHeadset | 3 | Bluetooth headset. |
soundCard | 4 | Sound card. |
TXMediaDeviceType
Device type (desktop platforms only).
This enum defines three types of audio/video devices, i.e., camera, microphone and speaker, so that you can manage all three with the same set of device management APIs.
Enum Value | Value | Description |
unknown | -1 | Undefined device type. |
mic | 0 | Microphone. |
speaker | 1 | Speaker or earpiece. |
camera | 2 | Camera. |
TXMediaDeviceState
Device operation.
This enum is used to notify status changes of local devices in the
onDeviceChanged callback.Enum Value | Value | Description |
add | 0 | The device has been plugged in. |
remove | 1 | The device has been removed. |
active | 2 | The device has been enabled. |
defaultDeviceChanged | 3 | The system default device has changed. |
TXCameraCaptureMode
Camera capture preference.
This enum is used to set camera capture parameters.
Enum Value | Value | Description |
auto | 0 | Automatically adjusts capture parameters. The SDK selects appropriate camera output parameters based on the actual capture device performance and network conditions, balancing device performance and video preview quality. |
performance | 1 | Prioritizes device performance. The SDK selects the camera output parameters closest to the encoder resolution and frame rate set by the user, thereby ensuring device performance. |
highQuality | 2 | Prioritizes video preview quality. The SDK selects higher camera output parameters to improve the quality of the preview video. In this case, more CPU and memory are consumed for video pre-processing. |
manual | 3 | Allows the user to set the width and height of the video captured by the local camera. |
TXCameraCaptureParam
Camera capture parameters.
This setting determines the quality of the local preview image.
Field | Type | Default Value | Description |
mode | TXCameraCaptureMode.auto | ||
width | int | 640 | Width of the captured image. |
height | int | 360 | Height of the captured image. |
TXDeviceInfo
Device information.
Field | Type | Default Value | Description |
deviceName | String | '' | Device name. |
devicePid | String | '' | Device ID. |
deviceProperties | String | '' | Device properties. |
TXDeviceObserver
Device status change callback.
onDeviceChanged
final void Function(String deviceId, TXMediaDeviceType type, TXMediaDeviceState state) onDeviceChanged
The connection status of a local device changed (desktop systems only).
The SDK throws this event callback when a local device (including cameras, microphones and speakers) is plugged in or unplugged.
Parameter | Type | Description |
deviceId | String | Device ID. |
type | ||
state |
