gpt4 book ai didi

webrtc - 如何使用 OpenTok 选择音频输出

转载 作者:行者123 更新时间:2023-12-04 14:55:35 27 4
gpt4 key购买 nike

我正在 build 一个简单的 WebRTC 应用程序 OpenTok .
我需要能够选择相机、音频输入和音频输出。
目前这似乎不太可能。

opentok-hardware-setup

https://github.com/opentok/opentok-hardware-setup.js/issues/18



我正在加载 OpenTok 在我的 index.html文件
opentok-hardware-setup.js .

一切看起来都很棒,我可以选择麦克风和摄像头,但不能选择扬声器,也就是 audiooutput .
<script src="https://static.opentok.com/v2/js/opentok.min.js"></script>

从控制台,我试过
OT.getDevices((err, devices) => { console.debug(devices)});

并观察到您无法获得 audioOutput
(4) [{…}, {…}, {…}, {…}]
0: {deviceId: "default", label: "Default - Built-in Microphone", kind: "audioInput"}
1: {deviceId: "b183634b059298f3692aa7e5871e6a463127701e21e320742c48bda99acdf925", label: "Built-in Microphone", kind: "audioInput"}
2: {deviceId: "4b441035a4db3c858c65c30eabe043ae1967407b3cc934ccfb332f0f6e33a029", label: "Built-in Output", kind: "audioInput"}
3: {deviceId: "05415e116b36584f848faeef039cd06e5290dde2e55db6895c19c8be3b880d91", label: "FaceTime HD Camera", kind: "videoInput"}
length
:4 __proto__:Array(0)

而您可以使用 navigator.mediaDevices.enumerateDevices() 获得它们

enter image description here

任何指针?

最佳答案

披露,我是 TokBox 的一名员工 :)。 OpenTok 当前不提供指定音频输出设备的方法。这仍然是一个实验性的 API,仅适用于 Chrome。当 API 标准化并拥有更广泛的浏览器支持时,我们将使其更容易。

同时,使用原生 WebRTC 很容易做到这一点。在 https://webrtc.github.io/samples/src/content/devices/multi/ 上有一个很好的样本。源代码可以在 https://github.com/webrtc/samples/blob/gh-pages/src/content/devices/multi/js/main.js 找到

总之你使用enumerateDevices你发现的方法。然后你使用 setSinkId()视频元素的方法 https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/setSinkId

您可以访问 videoElement通过聆听 videoElementCreated订阅者上的事件,如下所示:

subscriber.on('videoElementCreated', (event) => {
if (typeof event.element.sinkId !== 'undefined') {
event.element.setSinkId(deviceId)
.then(() => {
console.log('successfully set the audio output device');
})
.catch((err) => {
console.error('Failed to set the audio output device ', err);
});
} else {
console.warn('device does not support setting the audio output');
}
});

关于webrtc - 如何使用 OpenTok 选择音频输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50645017/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com