共计 1738 个字符,预计需要花费 5 分钟才能阅读完成。
<!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>
正文完
发表至: javascript
2019-05-10