我想使用以下代码在两个不同的音频输出媒体设备上播放相同的音频MediaStream:
const audio0 = new Audio('/audio.mp3')
audio0.play()
const stream = audio0.captureStream()
const audio1 = new Audio()
audio1
.setSinkId('552a19eb3a0e0c496c1967d4d503f1fe78f66eb213b3bea48ba5b2f672bb1241')
.then(() => {
console.log('audio1 setSinkId was successful', audio1.sinkId)
})
.catch(err => {
console.log('audio1 setSinkId failed', err.name, err.message)
})
audio1.srcObject = stream
setSinkId调用成功,并且audio1.sinkId
设置为正确的设备ID '[ID]'
(内部扬声器),但是结果是在'default'
设备(已配对)上播放了audio0和audio1蓝牙耳机。)
我希望audio0在默认设备上播放,而audio1应该在由deviceId 'ID'
指定的其他设备上播放。
奇怪的是,如果我setSinkId
音频0在设备'[ID]'
上播放,而只让音频1在默认设备上播放,则可以正常工作,我可以同时在两个设备上听到音频。
const audio0 = new Audio('/audio.mp3')
.setSinkId('552a19eb3a0e0c496c1967d4d503f1fe78f66eb213b3bea48ba5b2f672bb1241')
.then(() => {
console.log('audio0 setSinkId was successful', audio0.sinkId)
})
.catch(err => {
console.log('audio0 setSinkId failed', err.name, err.message)
})
audio0.play()
const stream = audio0.captureStream()
const audio1 = new Audio()
audio1.srcObject = stream