切换摄像头和麦克风

切换摄像头和麦克风

本文主要介绍在音视频通话过程中如何切换摄像头和麦克风。

切换摄像头

获取摄像头设备列表

let cameras = null;
TRTC.getCameras().then(devices => {
  cameras = devices;
  devices.forEach(dev => {
    console.log('camera label: ' + dev.label + ' deviceId: ' + dev.deviceId);
  });
});

切换摄像头

// 假设本地流 localStream 已经被发布
// 切换到第二个摄像头
let cameraId = cameras[1].deviceId;
localStream.switchDevice('video', cameraId).then(() => {
  console.log('switch camera success');
});

切换麦克风

获取麦克风设备列表

let microphones = null;
TRTC.getMicrophones().then(devices => {
  microphones = devices;
  devices.forEach(dev => {
    console.log('microphone label: ' + dev.label + ' deviceId: ' + dev.deviceId);
  });
});

切换麦克风

// 假设本地流 localStream 已经被发布
// 切换到第二个麦克风
let micId = microphones[1];
localStream.switchDevice('audio', micId).then(() => {
  console.log('switch microphone success');
});