I'm implementing a WebRTC Audio chat. I have everything working, and was initially using <audio>
elements to output the audio, which worked fine.
But then I wanted to implement a "Speaking indicator" feature, and decided to go with AudioContext.
It works, in Safari + Firefox, but no Chrome. I just don't get any output.
This is my code:
const audioContext = new AudioContext();
// Create an audio source node from the stream received by the
// RTCPeerConnection with peerConnection.ontrack()
const audioSourceNode = audioContext.createMediaStreamSource(stream);
// Connect the audio source to the destination
audioSourceNode.connect(audioContext.destination);
Am I missing something? Do I need to somehow use an <audio>
element to get sound on Chrome?
It's an old known bug in Chrome that wasn't fixed so far.
A common workaround is to create a muted <audio>
element to make the audio flowing (it can be deleted after). See this answer for an example.