如何html5在浏览器里访问手机后置摄像头

如何html5在浏览器里访问手机后置摄像头,第1张

camerahtml

<video id="video" width="640" height="480" autoplay></video>
<button id="snap">Snap Photo</button>
<canvas id="canvas" width="640" height="480"></canvas>

camerajs

var video = documentgetElementById('video');
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/" />调用相机 或者相册
还是要根据手机的类型来说,有些手机只能调相机,有些手机只能调相册,或者两者都行。
以上,希望能帮助到你。


欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/yw/13333046.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-07-16
下一篇 2023-07-16

发表评论

登录后才能评论

评论列表(0条)

保存