I want to play the same audio MediaStream on two different audio output media devices with the following code:
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
The setSinkId call is successful and audio1.sinkId is set to the right device id '[ID]' (internal speakers), however, the result is both audio0 and audio1 play on 'default' device (paired bluetooth headphones).
I would expect audio0 play on the default device, while audio1 should play on the other, specified by deviceId 'ID'.
Curiously, if I setSinkId audio0 to play on device '[ID]' and just let audio1 play on the default, it works, I get to hear the audio on both devices simultaneously.
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