我想使用 webRTC 显示来自我的相机的视频并从我的麦克风听到声音,但语音不起作用。你知道为什么我的代码不能正常工作吗?
JS
if(navigator.getUserMedia){
navigator.getUserMedia({
video: true,
audio: true
}, onSuccess, onError);
}else{
console.log('Twoja przegladarka nie obsluguje webRTC - getUserMedia');
}
function onSuccess(stream){
var video = document.getElementById('webcam'),
videoSrc;
//audioContext,
//mediaStreamSource;
if (window.webkitURL) {
videoSource = window.webkitURL.createObjectURL(stream);
} else {
videoSource = stream;
}
video.autoplay = true;
video.src = videoSource;
var audioContext = 'AudioContext' in window ? new AudioContext() :
(('webkitAudioContext' in window) ? new webkitAudioContext() : null);
if (audioContext) {
var mediaStreamSource = audioContext.createMediaStreamSource(stream);
mediaStreamSource.connect(audioContext.destination);
} else {
// ...
}
}