<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>GetUserMedia 实例 </title>
</head>
<body>
<video id="video" autoplay><ideo>
</body>
<script type="text/javascript">
function isMediaAvailable(){return new Promise(function(resolve, reject){if (navigator.mediaDevices.getUserMedia) {console.log('[mediaDevices]');
navigator.mediaDevices.getUserMedia({
video: true,
audio: true
}).then(function(localMediaStream) {resolve('1');
var video = document.getElementById('video');
video.srcObject = localMediaStream;
// video.src = window.URL.createObjectURL(localMediaStream)
video.onloadedmetadata = function(e) {console.log("Label:" + localMediaStream.label);
console.log("AudioTracks" , localMediaStream.getAudioTracks());
console.log("VideoTracks" , localMediaStream.getVideoTracks());
};
}).catch(function(err) {reject('0');
// console.log(err.name + ":" + err.message);
})
} else if (navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia) {var getUserMedia = (navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia);
getUserMedia.call(navigator, {
video: true,
audio: true
}, function(localMediaStream) {resolve('1')
var video = document.getElementById('video');
video.srcObject = localMediaStream;
// video.src = window.URL.createObjectURL(localMediaStream)
video.onloadedmetadata = function(e) {console.log("Label:" + localMediaStream.label);
console.log("AudioTracks" , localMediaStream.getAudioTracks());
console.log("VideoTracks" , localMediaStream.getVideoTracks());
};
}, function(err) {reject('0');
// console.log(err);
// console.log(err.name + ":" + err.message);
});
}
});
};
isMediaAvailable().then(function (para) {console.log('[para]',para);
}).catch(function(para){console.log('[e]',para);
})
// isMediaAvailable()
</script>
<html>