我想使用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 {
// ...
}
}发布于 2013-03-22 00:06:05
默认情况下,27.0.1436.1之前的Chrome版本会为与LocalMediaStreams关联的视频元素设置“muted”属性。设置video.muted = false应启用本地音频播放。
有关详细信息,请参阅this post和this example。
https://stackoverflow.com/questions/15541620
复制相似问题