如何使用MVC在Web应用程序中将音频输入从一个设备更改为另一台设备



我们正在构建一个Web应用程序,在该应用程序中,用户可以与其他用户进行视频聊天。我们想给他们一个选择,将PC内部麦克风之间的音频输入切换到其他输入设备。我尝试在互联网上搜索相同的搜索,但没有找到任何潜在客户。

假设您正在使用opentok(因为您使用了opentok标签)。

您可以使用ot.getDevices API列出可用的音频输入设备。然后,您可以在发布时通过设备。类似:

let publisher;
function publish(audioDeviceId) {
  if (publisher) {
    publisher.destroy();
  }
  publisher = OT.initPublisher(null, {
    audioSource: audioDeviceId
  });
}
publish();
OT.getDevices((err, devices) => {
  if (!err) {
    let select = document.querySelector('select');
    devices.filter(device => device.kind === 'audioInput').forEach(device => {
      let option = document.createElement('option');
      option.value = device.deviceId;
      option.innerHTML = device.label;
      select.appendChild(option);
    });
    select.addEventListener('change', () => {
      publish(event.target.value);
    });
  }
});

您可以在https://jsbin.com/qibaba

上看到一个工作的演示

最新更新