我正在使用OpenTok构建一个简单的WebRTC应用程序。我需要能够选择相机、音频输入和音频输出。目前这似乎不太可能。
https://github.com/opentok/opentok-hardware-setup.js/issues/18
我正在我的文件中加载OpenTokindex.html和opentok-hardware-setup.js.
一切看起来都很棒,我可以选择麦克风和摄像头,但不能选择扬声器audiooutput。
<script src="https://static.opentok.com/v2/js/opentok.min.js"></script>
Run Code Online (Sandbox Code Playgroud)
从控制台,我试过
OT.getDevices((err, devices) => { console.debug(devices)});
Run Code Online (Sandbox Code Playgroud)
并观察到你无法得到 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)
Run Code Online (Sandbox Code Playgroud)
而你可以让他们使用 navigator.mediaDevices.enumerateDevices()
任何指针?
披露,我是 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');
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1484 次 |
| 最近记录: |