Chrome won't play WebAudio getUserMedia via WebRTC/Peer.js

流过昼夜 提交于 2019-12-01 10:48:41

In Chrome, it is a known bug currently where remote audio streams gathered from a peer connection are not accessible through the AudioAPI.

Latest comment on the bug:

We are working really hard towards the feature. The reason why this takes long time is that we need to move the APM to chrome first, implement a render mixer to get the unmixed data from WebRtc, then we can hook up the remote audio stream to webaudio.

It was recently patched in Firefox as I remember this being an issue on there as well in the past.

I was unable to play the stream using web audio but I did manage to play it uses a basic audio element:

 var audio = new Audio();                                                  
 audio.src = (URL || webkitURL || mozURL).createObjectURL(remoteStream);
 audio.play();

This still appears to be an issue even in Chrome 73.

The solution that saved me for now is to also connect the media stream to a muted HTML audio element. This seems to make the stream work and audio starts flowing into the WebAudio nodes.

This would look something like:

let a = new Audio();
a.muted = true;
a.srcObject = stream;
a.addEventListener('canplaythrough', () => {
    a = null;
});

let audioStream = audioContext.createMediaStreamSource(stream);
audioStream.connect(audioContext.destination);

JSFiddle: https://jsfiddle.net/jmcker/4naq5ozc/


Original Chrome issue and workaround: https://bugs.chromium.org/p/chromium/issues/detail?id=121673#c121

New Chrome issue: https://bugs.chromium.org/p/chromium/issues/detail?id=687574

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!