admin管理员组文章数量:1289868
I've been playing around a lot with HTML5, but I can't get the following done. The javascript has to ask permission to access the microphone, and then it has to stream the microphone input to the puter speakers. This is the javascript I had:
navigator.getUserMedia = ( navigator.getUserMedia || navigator.webkitGetUserMedia ||
navigator.mozGetUserMedia ||navigator.msGetUserMedia);
var aCtx;
var analyser;
var microphone;
if (navigator.getUserMedia) {
navigator.getUserMedia({audio: true}, function(stream) {
aCtx = new webkitAudioContext();
analyser = aCtx.createAnalyser();
microphone = aCtx.createMediaStreamSource(stream);
microphone.connect(analyser);
analyser.connect(aCtx.destination);
});
};
But Chrome (and Opera) say
Uncaught TypeError: Failed to execute 'webkitGetUserMedia' on 'Navigator': 3 arguments required, but only 2 present.
Why would it need more arguments? Can anyone please help me with the javascript for this?
Thanks.
I've been playing around a lot with HTML5, but I can't get the following done. The javascript has to ask permission to access the microphone, and then it has to stream the microphone input to the puter speakers. This is the javascript I had:
navigator.getUserMedia = ( navigator.getUserMedia || navigator.webkitGetUserMedia ||
navigator.mozGetUserMedia ||navigator.msGetUserMedia);
var aCtx;
var analyser;
var microphone;
if (navigator.getUserMedia) {
navigator.getUserMedia({audio: true}, function(stream) {
aCtx = new webkitAudioContext();
analyser = aCtx.createAnalyser();
microphone = aCtx.createMediaStreamSource(stream);
microphone.connect(analyser);
analyser.connect(aCtx.destination);
});
};
But Chrome (and Opera) say
Uncaught TypeError: Failed to execute 'webkitGetUserMedia' on 'Navigator': 3 arguments required, but only 2 present.
Why would it need more arguments? Can anyone please help me with the javascript for this?
Thanks.
Share Improve this question edited Jun 21, 2014 at 11:11 notthetup 1,1379 silver badges17 bronze badges asked Jun 21, 2014 at 10:08 eds1999eds1999 1,0582 gold badges12 silver badges27 bronze badges 2-
1
errorcallback if im correct.
Selecting a media source
@ ~50%: html5rocks./en/tutorials/getusermedia/intro – Martijn Commented Jun 21, 2014 at 11:14 -
1
Google
MDN getUserMedia
->navigator.getUserMedia ( constraints, successCallback, errorCallback );
– Andreas Louv Commented Jun 21, 2014 at 11:19
1 Answer
Reset to default 10The API for getUserMedia requires 3 arguments.
Let constraints be the method's first argument.
Let successCallback be the callback indicated by the method's second argument.
Let errorCallback be the callback indicated by the method's third argument.
Refer to the mediacapture-stream spec
So all you need to do is add a 3rd argument which is an error callback. Something like this would work.
navigator.getUserMedia = ( navigator.getUserMedia || navigator.webkitGetUserMedia ||
navigator.mozGetUserMedia ||navigator.msGetUserMedia);
var aCtx;
var analyser;
var microphone;
if (navigator.getUserMedia) {
navigator.getUserMedia({audio: true}, function(stream) {
aCtx = new webkitAudioContext();
analyser = aCtx.createAnalyser();
microphone = aCtx.createMediaStreamSource(stream);
microphone.connect(analyser);
analyser.connect(aCtx.destination);
}, function (){console.warn("Error getting audio stream from getUserMedia")});
};
You can look at this piece of code which does something similar for reference.
本文标签: javascriptMicrophone to speaker stream (JS)Stack Overflow
版权声明:本文标题:javascript - Microphone to speaker stream (JS) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741481383a2381193.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论