我有一个奇怪的问题,代码可以在Chrome中运行,但不适用于Firefox。无论出于何种原因,它表示变量(成功)是未定义的,即使它在调用函数之前已经明确定义。看看:
createRoom.addEventListener('click',function(e){
e.preventDefault();
var success = function(myStream){
ownVideo.src = URL.createObjectURL(myStream);
// create a room
WebRTC.createRoom();
};
navigator.getUserMedia({audio: true, video: true}, gotStream, gotError);
});
定义成功后,我运行getUserMedia,运行成功后将运行gotStream,然后运行成功。为什么Firefox不接受成功的定义? HALP。
答案 0 :(得分:0)
根据mozila,
// you code should be
navigator.getUserMedia({audio: true, video: true}, success, gotError);
可能是,函数gotStream正在为chrome运行。
这是来自Mozila参考页面的运行样本:
navigator.getUserMedia = ( navigator.getUserMedia ||
navigator.webkitGetUserMedia ||
navigator.mozGetUserMedia ||
navigator.msGetUserMedia);
if (navigator.getUserMedia) {
navigator.getUserMedia (
// constraints
{
video: true,
audio: true
},
// successCallback
function(localMediaStream) {
var video = document.querySelector('video');
video.src = window.URL.createObjectURL(localMediaStream);
// Do something with the video here, e.g. video.play()
},
// errorCallback
function(err) {
console.log("The following error occured: " + err);
}
);
} else {
console.log("getUserMedia not supported");
}