TUIDeviceManager
是音视频设备管理器,用于管理摄像头、麦克风和扬声器等音视频相关的硬件设备。// 使用 npmnpm i @tencentcloud/tuiroom-engine-electron@2.4.0-alpha.3 --save// 使用 pnpmpnpm i @tencentcloud/tuiroom-engine-electron@2.4.0-alpha.3 --save// 使用 yarnyarn add @tencentcloud/tuiroom-engine-electron@2.4.0-alpha.3
import TUIRoomEngine, {TUIDeviceManager, TUIDeviceInfo} from '@tencentcloud/tuiroom-engine-electron';const deviceManager:TUIDeviceManager = TUIRoomEngine.getDeviceManager();const cameraList: Array<TUIDeviceInfo> = deviceManager.getCameraDevicesList();
方法 | 说明 |
获取摄像头设备列表 | |
获取麦克风设备列表 | |
获取扬声器设备列表 | |
设置当前设备 | |
获取当前设备 | |
设置当前设备音量 | |
获取当前设备音量 | |
静音当前设备 | |
获取当前设备静音状态 | |
启动系统设备跟随 | |
开启麦克风测试 | |
结束麦克风测试 | |
开启扬声器测试 | |
结束扬声器测试 | |
开启摄像头测试 | |
结束摄像头测试 | |
摄像头测试时,开启镜像 | |
摄像头测试时,设置摄像头设备 | |
摄像头测试时,设置摄像头采集分辨率 | |
摄像头测试时,设置视频预处理插件库文件路径 | |
摄像头测试时,设置视频预处理参数 | |
注册事件监听 | |
取消事件监听 |
类型 | 说明 |
摄像头采集参数 | |
音视频设备信息 | |
矩形坐标区域 |
枚举 | 说明 |
摄像头采集模式 | |
音视频设备事件类型 | |
音视频设备状态 | |
音视频设备类型 |
import TUIRoomEngine, {TUIDeviceManager, TUIDeviceInfo} from '@tencentcloud/tuiroom-engine-electron';const deviceManager:TUIDeviceManager = TUIRoomEngine.getDeviceManager();const cameraList: Array<TUIDeviceInfo> = deviceManager.getCameraDevicesList();
TUIDeviceInfo
>import TUIRoomEngine, {TUIDeviceManager, TUIDeviceInfo} from '@tencentcloud/tuiroom-engine-electron';const deviceManager:TUIDeviceManager = TUIRoomEngine.getDeviceManager();const cameraList: Array<TUIDeviceInfo> = deviceManager.getMicDevicesList();
TUIDeviceInfo
>import TUIRoomEngine, {TUIDeviceManager, TUIDeviceInfo} from '@tencentcloud/tuiroom-engine-electron';const deviceManager:TUIDeviceManager = TUIRoomEngine.getDeviceManager();const cameraList: Array<TUIDeviceInfo> = deviceManager.getSpeakerDevicesList();
TUIDeviceInfo
>import TUIRoomEngine, {TUIDeviceManager, TUIMediaDeviceType} from '@tencentcloud/tuiroom-engine-electron';const deviceManager:TUIDeviceManager = TUIRoomEngine.getDeviceManager();deviceManager.setCurrentDevice(TUIMediaDeviceType.kMediaDeviceTypeAudioOutput, 'Your speaker ID');
参数 | 类型 | 校验 | 默认值 | 说明 |
type | - | - | 设备类型 | |
deviceId | string | - | - | 设备 ID |
Promise
<void
>import TUIRoomEngine, {TUIDeviceManager, TUIMediaDeviceType} from '@tencentcloud/tuiroom-engine-electron';const deviceManager:TUIDeviceManager = TUIRoomEngine.getDeviceManager();const currentSpeaker:TUIDeviceInfo = await deviceManager.getCurrentDevice(TUIMediaDeviceType.kMediaDeviceTypeAudioOutput);
参数 | 类型 | 校验 | 默认值 | 说明 |
type | - | - | 设备类型 |
Promise
<TUIDeviceInfo
>import TUIRoomEngine, {TUIDeviceManager, TUIMediaDeviceType} from '@tencentcloud/tuiroom-engine-electron';const deviceManager:TUIDeviceManager = TUIRoomEngine.getDeviceManager();deviceManager.setCurrentDeviceVolume(TUIMediaDeviceType.kMediaDeviceTypeAudioInput, value);
参数 | 类型 | 校验 | 默认值 | 说明 |
type | - | - | 设备类型 | |
volume | number | [0-100] | 60 | 音量 |
Promise
<void
>import TUIRoomEngine, {TUIDeviceManager, TUIMediaDeviceType} from '@tencentcloud/tuiroom-engine-electron';const deviceManager:TUIDeviceManager = TUIRoomEngine.getDeviceManager();const currentMicVolume = await deviceManager.getCurrentDeviceVolume(TUIMediaDeviceType.kMediaDeviceTypeAudioInput);
参数 | 类型 | 校验 | 默认值 | 说明 |
type | - | - | 设备类型 |
Promise
<number
>import TUIRoomEngine, {TUIDeviceManager, TUIMediaDeviceType} from '@tencentcloud/tuiroom-engine-electron';const deviceManager:TUIDeviceManager = TUIRoomEngine.getDeviceManager();deviceManager.setCurrentDeviceMute(TUIMediaDeviceType.kMediaDeviceTypeAudioInput, true);
参数 | 类型 | 校验 | 默认值 | 说明 |
type | - | - | 设备类型 | |
mute | boolean | - | - | 是否静音 |
Promise
<void
>import TUIRoomEngine, {TUIDeviceManager, TUIMediaDeviceType} from '@tencentcloud/tuiroom-engine-electron';const deviceManager:TUIDeviceManager = TUIRoomEngine.getDeviceManager();const isCurrentMicMuted = await deviceManager.getCurrentDeviceMute(TUIMediaDeviceType.kMediaDeviceTypeAudioInput, true);
参数 | 类型 | 校验 | 默认值 | 说明 |
type | - | - | 设备类型 |
Promise
<boolean
>import TUIRoomEngine, {TUIDeviceManager, TUIMediaDeviceType} from '@tencentcloud/tuiroom-engine-electron';const deviceManager:TUIDeviceManager = TUIRoomEngine.getDeviceManager();deviceManager.enableFollowingDefaultAudioDevice(TUIMediaDeviceType.kMediaDeviceTypeAudioInput, true);
参数 | 类型 | 校验 | 默认值 | 说明 |
type | - | - | 设备类型 | |
enable | boolean | - | - | 是否跟随系统默认的音频设备 |
Promise
<void
>import TUIRoomEngine, {TUIDeviceManager} from '@tencentcloud/tuiroom-engine-electron';const deviceManager:TUIDeviceManager = TUIRoomEngine.getDeviceManager();deviceManager.startMicDeviceTest(300, true);
参数 | 类型 | 校验 | 默认值 | 说明 |
interval | number | - | - | 麦克风音量的回调间隔,单位:毫秒。 |
playback | boolean | - | - | 是否开启麦克风声音回播,开启后用户测试麦克风时会听到自己的声音,如果不传递playback参数,则默认为false。 |
Promise
<void
>import TUIRoomEngine, {TUIDeviceManager} from '@tencentcloud/tuiroom-engine-electron';const deviceManager:TUIDeviceManager = TUIRoomEngine.getDeviceManager();deviceManager.stopMicDeviceTest();
Promise
<void
>import TUIRoomEngine, {TUIDeviceManager} from '@tencentcloud/tuiroom-engine-electron';const deviceManager:TUIDeviceManager = TUIRoomEngine.getDeviceManager();const audioFilePath = '';deviceManager.startSpeakerDeviceTest(audioFilePath);
参数 | 类型 | 校验 | 默认值 | 说明 |
filePath | string | 有效音频文件路径 | - | 测试音频文件路径 |
Promise
<void
>import TUIRoomEngine, {TUIDeviceManager} from '@tencentcloud/tuiroom-engine-electron';const deviceManager:TUIDeviceManager = TUIRoomEngine.getDeviceManager();deviceManager.stopSpeakerDeviceTest();
Promise
<void
>import TUIRoomEngine, {TUIDeviceManager, TUIRect} from '@tencentcloud/tuiroom-engine-electron';const deviceManager:TUIDeviceManager = TUIRoomEngine.getDeviceManager();const rect: TUIRect = {left: 100,top: 50,right: 740,bottom: 410,};const windowID: Uint8Array; // 通过 Electron API BrowserWindow.getNativeWindowHandle() 拿到deviceManager.startCameraDeviceTest(windowID, rect);
参数 | 类型 | 校验 | 默认值 | 说明 |
windowID | Uint8Array | - | - | 预览摄像头画面的窗口 ID,通过 Electron API BrowserWindow.getNativeWindowHandle() 拿到。 |
rect | - | - | 摄像头画面显示在窗口内的位置区域 |
Promise
<void
>import TUIRoomEngine, {TUIDeviceManager} from '@tencentcloud/tuiroom-engine-electron';const deviceManager:TUIDeviceManager = TUIRoomEngine.getDeviceManager();deviceManager.stopCameraDeviceTest();
Promise
<void
>import TUIRoomEngine, {TUIDeviceManager} from '@tencentcloud/tuiroom-engine-electron';const deviceManager:TUIDeviceManager = TUIRoomEngine.getDeviceManager();deviceManager.setCameraTestRenderMirror(true);
参数 | 类型 | 校验 | 默认值 | 说明 |
mirror | boolean | - | - | 是否开启镜像 |
Promise
<void
>import TUIRoomEngine, {TUIDeviceManager} from '@tencentcloud/tuiroom-engine-electron';const deviceManager:TUIDeviceManager = TUIRoomEngine.getDeviceManager();deviceManager.setCameraTestDeviceId('Your camera ID');
参数 | 类型 | 校验 | 默认值 | 说明 |
cameraId | string | - | - | 摄像头设备 ID |
Promise
<void
>import TUIRoomEngine, {TUIDeviceManager} from '@tencentcloud/tuiroom-engine-electron';const deviceManager:TUIDeviceManager = TUIRoomEngine.getDeviceManager();deviceManager.setCameraTestResolution(1920, 1080);
参数 | 类型 | 校验 | 默认值 | 说明 |
width | number | - | - | 采集宽度 |
height | number | - | - | 采集高度 |
Promise
<void
>import TUIRoomEngine, {TUIDeviceManager} from '@tencentcloud/tuiroom-engine-electron';const deviceManager:TUIDeviceManager = TUIRoomEngine.getDeviceManager();deviceManager.setCameraTestVideoPluginPath('Your library path');
参数 | 类型 | 校验 | 默认值 | 说明 |
path | string | - | - | 视频预处理插件库文件路径 |
Promise
<void
>import TUIRoomEngine, {TUIDeviceManager} from '@tencentcloud/tuiroom-engine-electron';const deviceManager:TUIDeviceManager = TUIRoomEngine.getDeviceManager();deviceManager.setCameraTestVideoPluginParameter('{}'); // JSON string
参数 | 类型 | 校验 | 默认值 | 说明 |
params | string | - | - | JSON 字符串 |
Promise
<void
>import TUIRoomEngine, {TUIDeviceManager, TUIMediaDeviceType, TUIMediaDeviceState} from '@tencentcloud/tuiroom-engine-electron';const deviceManager:TUIDeviceManager = TUIRoomEngine.getDeviceManager();const onDeviceChanged = (deviceId: string, type: TUIMediaDeviceType, state: TUIMediaDeviceState) => {// ...}deviceManager.on(TUIMediaDeviceEventType.onDeviceChanged, onDeviceChanged);
参数 | 类型 | 校验 | 默认值 | 说明 |
eventName | - | - | 事件名称 | |
func | (...args: any[]) => void | - | - | 事件回调函数 |
Promise
<void
>import TUIRoomEngine, {TUIDeviceManager, TUIMediaDeviceType, TUIMediaDeviceState} from '@tencentcloud/tuiroom-engine-electron';const deviceManager:TUIDeviceManager = TUIRoomEngine.getDeviceManager();const onDeviceChanged = (deviceId: string, type: TUIMediaDeviceType, state: TUIMediaDeviceState) => {// ...}deviceManager.off(TUIMediaDeviceEventType.onDeviceChanged, onDeviceChanged);
参数 | 类型 | 校验 | 默认值 | 说明 |
eventName | - | - | 事件名称 | |
func | (...args: any[]) => void | - | - | 事件回调函数 |
Promise
<void
>字段 | 类型 | 说明 |
mode | 摄像头采集偏好 | |
width | number | 采集图像宽度 |
height | number | 采集图像高度 |
字段 | 类型 | 说明 |
deviceId | string | 设备 ID |
deviceName | string | 设备名称 |
deviceProperties | Record<string, any> | 设备属性。仅摄像头支持,包含摄像头支持的采集分辨率。 |
字段 | 类型 | 说明 |
left | number | 左边线坐标 |
top | number | 顶边线坐标 |
right | number | 右边线坐标 |
bottom | number | 底边线坐标 |
枚举项 | 类型 | 值 | 说明 |
kCameraResolutionStrategyAuto | number | 0 | 自动调整采集参数。SDK 根据实际的采集设备性能及网络情况,选择合适的摄像头输出参数,在设备性能及视频预览质量之间,维持平衡。 |
kCameraResolutionStrategyPerformance | number | 1 | 优先保证设备性能。SDK 根据用户设置编码器的分辨率和帧率,选择最接近的摄像头输出参数,从而保证设备性能。 |
kCameraResolutionStrategyHighQuality | number | 2 | 优先保证视频预览质量。SDK选择较高的摄像头输出参数,从而提高预览视频的质量。在这种情况下,会消耗更多的 CPU 及内存做视频前处理。 |
kCameraCaptureManual | number | 3 | 允许用户设置本地摄像头采集的视频宽高。 |
枚举项 | 类型 | 值 | 说明 |
string | 'onDeviceChanged' | 设备状态变化事件 |
枚举项 | 类型 | 值 | 说明 |
kMediaDeviceStateAdd | number | 0 | 设备已被插入 |
kMediaDeviceStateRemove | number | 1 | 设备已被移除 |
kMediaDeviceStateActive | number | 2 | 设备已启用 |
kMediaDefaultDeviceChanged | number | 3 | 系统默认设备变更 |
枚举项 | 类型 | 值 | 说明 |
kMediaDeviceTypeUnknown | number | -1 | 未知类型 |
kMediaDeviceTypeAudioInput | number | 0 | 麦克风 |
kMediaDeviceTypeAudioOutput | number | 1 | 扬声器 |
kMediaDeviceTypeVideoCamera | number | 2 | 摄像头 |
参数 | 类型 | 含义 |
deviceID | string | 设备 ID |
type | 设备类型 | |
state | 设备状态 |
本页内容是否解决了您的问题?