admin管理员组文章数量:1406951
I am making audio chat website using WebRTC. I have one problem.
When receiving remote audio from peer. This doesn't work (I can't hear any audio)
var audioContext = new AudioContext();
var audioStream = audioContext.createMediaStreamSource(e.stream);
audioStream.connect(audioContext.destination);
While this works
var audio2 = document.querySelector('audio#audio2');
audio2.srcObject = e.stream;
The reason I need to do it is because I need to be able to control the audio (effects, volume), and as I know, AudioContext provides that. But for some reason, it doesn't work. Any suggestions?
Thank you!
I am making audio chat website using WebRTC. I have one problem.
When receiving remote audio from peer. This doesn't work (I can't hear any audio)
var audioContext = new AudioContext();
var audioStream = audioContext.createMediaStreamSource(e.stream);
audioStream.connect(audioContext.destination);
While this works
var audio2 = document.querySelector('audio#audio2');
audio2.srcObject = e.stream;
The reason I need to do it is because I need to be able to control the audio (effects, volume), and as I know, AudioContext provides that. But for some reason, it doesn't work. Any suggestions?
Thank you!
Share Improve this question edited Jan 21, 2017 at 20:35 De Kirvis asked Jan 21, 2017 at 20:30 De KirvisDe Kirvis 1171 silver badge9 bronze badges 4- Can you describe "doesn't work"? – guest271314 Commented Jan 21, 2017 at 20:35
- I can't hear any audio. – De Kirvis Commented Jan 21, 2017 at 20:35
-
1
Use
.createMediaStreamDestination()
– guest271314 Commented Jan 21, 2017 at 20:38 - 1 var audioContext = new AudioContext(); var destination = audioContext.createMediaStreamDestination(); var audioStream = audioContext.createMediaStreamSource(e.stream); audioStream.connect(destination); Doesn't do anything. – De Kirvis Commented Jan 21, 2017 at 20:41
1 Answer
Reset to default 6Use .createMediaStreamSource()
with .createGain()
var ctx = new AudioContext();
var source = ctx.createMediaStreamSource(stream);
var gainNode = ctx.createGain();
gainNode.gain.value = .5;
source.connect(gainNode);
source.connect(ctx.destination);
jsfiddle https://jsfiddle/tkw13bfg/2
Alternatively, create an AudioNode
, use .createGain()
var ctx = new AudioContext();
var audio = new Audio();
audio.srcObject = stream;
var gainNode = ctx.createGain();
gainNode.gain.value = .5;
audio.onloadedmetadata = function() {
var source = ctx.createMediaStreamSource(audio.srcObject);
audio.play();
audio.muted = true;
source.connect(gainNode);
gainNode.connect(ctx.destination);
}
本文标签: javascriptWebRTC doesn39t work with AudioContextStack Overflow
版权声明:本文标题:javascript - WebRTC doesn't work with AudioContext - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745051461a2639682.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论