Agora 无法切换相机获取:无法读取未定义的属性(读取"deviceId")



我正在尝试使用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));
});
}

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

相关内容

  • 没有找到相关文章

最新更新