【问题标题】:Agora can not switch the camera getting : Cannot read properties of undefined (reading 'deviceId')Agora 无法切换相机获取:无法读取未定义的属性(读取 'deviceId')
【发布时间】:2022-01-02 19:54:59
【问题描述】:

我正在尝试使用 Agora.io。一切正常。直到我添加相机之间的切换。由于下面的代码,我正在尝试在相机之间切换。但问题是我得到了这个错误:Uncaught TypeError: Cannot read properties of undefined (reading 'deviceId')

错误行在changeStreamSource():

deviceId = devices.cameras[deviceIndex].deviceId;

你能指导我吗?

function changeStreamSource (deviceIndex, deviceType) {
  console.log('Switching stream sources for: ' + deviceType); 
  var deviceId;
  var existingStream = false; 
  if (deviceType === "video") {    
    deviceId = devices.cameras[deviceIndex].deviceId; 
  }  
   
  localStreams.camera.stream.switchDevice(deviceType, deviceId, function(){  
    console.log('successfully switched to new device with id: ' + JSON.stringify(deviceId));
    // set the active device ids
    if(deviceType === "audio") {
      localStreams.camera.micId = deviceId;
    } else if (deviceType === "video") {
      localStreams.camera.camId = deviceId;
    } else {
      console.log("unable to determine deviceType: " + deviceType);
    }
  }, function(){
    console.log('failed to switch to new device with id: ' + JSON.stringify(deviceId));
  });
}

【问题讨论】:

    标签: javascript jquery agora.io


    【解决方案1】:

    devices 未在您的代码中定义。您可以使用AgoraRTC.getDevices 方法获取设备列表。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-02-14
      • 2014-08-29
      • 2023-03-11
      • 2022-01-15
      • 2021-12-31
      • 2021-12-13
      • 2021-11-28
      相关资源
      最近更新 更多