setSinkId 更改多个音频输出 [英] setSinkId change muliple audio ouputs
问题描述
问题来了,
首先,我在 select 元素中列举了所有可用的设备:
First I enumerate all the devices that I have available with in select elements:
navigator.mediaDevices.enumerateDevices()
当我更改一个输出时,它会在我选择的设备中发出声音.
When I change one output, it sounds in the device that I choose.
HTMLMediaElement.setSinkId(deviceId)
如果我播放另一个音频并更改设备输出 (setSinkId),它也会将第一个更改为最后一个 deviceId.所以我在同一个设备上有两种声音.
After if I play another audio and change the device output (setSinkId), it changes also the first one to the last deviceId. So I have both sounds in the same device.
我是否需要使用最新的adapter.js 版本才能正确实现该问题?
Do I need to have the last adapter.js version to implement properly that problem?
********* 编辑 **********
********* EDITED **********
按照上面的评论,它尝试了网络音频,但没有成功.使用 getUserMedia 一切正常.
Following the above comment, it try the web audio, but not success. With getUserMedia everything is fine.
navigator.getUserMedia( { audio: true, video: false },
function (mediaStream) {
// Create an audio context for the audio
var ac = new (window.AudioContext || window.webKitAudioContext)();
// Create a clone of the stream, if not the id of all the stream is default
//var streamClone = stream.clone();
var ss = ac.createMediaStreamSource(mediaStream);
// Create a destination
var sd = ac.createMediaStreamDestination()
ss.connect(sd);
element.srcObject = sd.stream;
// Play the sound
element.play();
element.setSinkId(deviceId).then(function() {
console.log('Set deviceId('+deviceId+') in the selected audio element');
});
},
function (error) {
console.log(error);
}
);
但是使用我的远程流,我听不到任何噪音
But using my remote stream, I cannot get any noise
var ac = new (window.AudioContext || window.webKitAudioContext)();
// Create a clone of the stream, if not the id of all the stream is default
var streamClone = stream.clone();
var ss = ac.createMediaStreamSource(stream);
// Create a destination
var sd = ac.createMediaStreamDestination()
ss.connect(sd);
// Element is my HTMLMediaElement
element.srcObject = sd.stream;
// Play the sound
element.play();
element.setSinkId(deviceId).then(function() {
console.log('Set deviceId('+deviceId+') in the selected audio element');
});
推荐答案
这很可能是由 Chrome 呈现音频的方式引起的.请参阅此处有关还建议使用 webaudio 解决问题的说明.
this is most likely caused by how Chrome renders audio. See here for a description which also suggests using webaudio to workaround the problem.
adapter.js 无法解决这个问题.
adapter.js can not fix this.
这篇关于setSinkId 更改多个音频输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!