【发布时间】:2020-10-04 17:31:11
【问题描述】:
如何在 RTCMulticonnection 中切换摄像头
我获取设备列表及其ID
var videoDevices = document.getElementById('video-devices');
var audioDevices = document.getElementById('audio-devices');
connection.DetectRTC.load(function() {
connection.DetectRTC.audioInputDevices.forEach(function(device) {
var option = document.createElement('option');
option.innerHTML = device.label;
option.value = device.id;
document.querySelector('select').appendChild(option);
});
connection.DetectRTC.videoInputDevices.forEach(function(device) {
var option = document.createElement('option');
option.innerHTML = device.label;
option.value = device.id;
videoDevices.appendChild(option);
});
});
并尝试通过以下方式更改相机。取自GitHub issue
document.getElementById('switch-camera').onclick = function() {
var videoSourceId = videoDevices.value;
connection.codecs.video = 'VP8';
connection.bandwidth = { // all values in kbits/per/seconds
audio: 192,
video: 512,
screen: 512
};
connection.stopMediaAccess();
setTimeout(() => {
connection.mediaConstraints.video.optional = [{
sourceId: videoSourceId
}];
connection.addStream({audio: true, video: true});
},2000);
};
但不使用相机根本不会改变 我尝试了很多方法,但都失败了
这是codepen上的一个例子
来自WebRTC samples 的这个例子可能有助于它做我想做的事,但对与 RTCMulticoonection 的集成感到困惑。
【问题讨论】:
-
您能提供一个minimal reproducible example 吗?谢谢
-
@DanieleRicci 感谢您的宝贵回复。我添加了一个指向 codpen 的链接
-
@DanieleRicci 我更新了问题,请您检查一下。可能是有用的参考
标签: javascript camera webrtc rtcmulticonnection