【发布时间】:2022-08-03 21:20:21
【问题描述】:
我在 openvidu 论坛上没有解决这个问题。我有一个使用 openvidu 构建的用于实时流媒体的网络应用程序,一切都在除 ios 之外的所有设备上完美运行
在我的 iphone 上的 safari 中,如果我更换视频轨道以基本上将摄像头切换到后置摄像头,整个会话都会丢失音频输入。这不会发生在 android 设备或我的网络浏览器上,它只是在 iphone 上。
这是我如何切换相机:
this.OV.getDevices().then((devices)=> {
let videoDevices = null;
if(this.OVCurrentCamera === \'front\'){
videoDevices = devices.filter(device => device.kind === \'videoinput\' && device.label !== \'Snap Camera\' && device.label.toLowerCase().indexOf(\'back\') !== -1);
}else{
videoDevices = devices.filter(device => device.kind === \'videoinput\' && device.label !== \'Snap Camera\' && device.label.toLowerCase().indexOf(\'front\') !== -1);
}
if(videoDevices){
// get new device id
// if we already on front the back device is the last one in the list otherwise the first
let newDeviceId = this.OVCurrentCamera === \'front\' ? videoDevices[videoDevices.length - 1].deviceId : videoDevices[0].deviceId;
this.OV.getUserMedia(<any>{
videoSource: newDeviceId,
}).then((mediaStream) => {
let videoTrack = mediaStream.getVideoTracks()[0];
this.OVPublisher.replaceTrack(videoTrack).then(() => {
this.OVCurrentCamera = this.OVCurrentCamera === \'front\' ? \'back\' : \'front\';
}).catch(() => {
this.toast.error(\'There was a problem switching cameras.\');
})
}).catch((error) => {
console.log(\"USER MEDIA ERROR\",error)
})
}else{
this.toast.error(\'Could Not Load Your Cameras\');
}
})
即使再次点击按钮返回前置摄像头,音频输入也不会返回。