camerahtml
<button id="snap">Snap Photo</button>
<canvas id="canvas" width="640" height="480"></canvas>
camerajs
if(navigatormediaDevices && navigatormediaDevicesgetUserMedia) {
// Not adding `{ audio: true }` since we only want video now
navigatormediaDevicesgetUserMedia({ video: true })then(function(stream) {
videosrc = windowURLcreateObjectURL(stream);
videoplay();
});
}else if(navigatorgetUserMedia) { // Standard
navigatorgetUserMedia({ video: true }, function(stream) {
videosrc = stream;
videoplay();
}, errBack);
} else if(navigatorwebkitGetUserMedia) { // WebKit-prefixed
navigatorwebkitGetUserMedia({ video: true }, function(stream){
videosrc = windowwebkitURLcreateObjectURL(stream);
videoplay();
}, errBack);
} else if(navigatormozGetUserMedia) { // Mozilla-prefixed
navigatormozGetUserMedia({ video: true }, function(stream){
videosrc = windowURLcreateObjectURL(stream);
videoplay();
}, errBack);
}
var canvas = documentgetElementById('canvas');
var context = canvasgetContext('2d');
var video = documentgetElementById('video');
documentgetElementById("snap")addEventListener("click", function() {
contextdrawImage(video, 0, 0, 640, 480);
});
注意,这个功能在有些手机浏览器无法开启或正确使用,但是我在电脑上测试是可以的。
<input type="file" accept="video/;capture=camcorder"><input type="file" accept="audio/;capture=microphone">
<input type="file" accept="image/;capture=camera">直接调用相机
<input type="file" accept="image/" />调用相机 或者相册
还是要根据手机的类型来说,有些手机只能调相机,有些手机只能调相册,或者两者都行。
以上,希望能帮助到你。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)