我想使用cordova创建Android / iOS / Windows应用。
我有问题访问相机。我用getUserMedia
但是这样我无法访问平板电脑的相机。访问它的另一种方法是什么?我只能使用后置摄像头。非常感谢!
getUserMedia
代码:
navigator.getUserMedia = navigator.getUserMedia ||navigator.webkitGetUserMedia
|| navigator.mozGetUserMedia || navigator.msGetUserMedia;
var cam_video_id = "camsource"
window.addEventListener('DOMContentLoaded', function() {
// Assign the <video> element to a variable
var video = document.getElementById(cam_video_id);
var options = {
"audio": false,
"video": true
};
// Replace the source of the video element with the stream from the camera
if (navigator.getUserMedia) {
navigator.getUserMedia(options, function(stream) {
video.src = (window.URL && window.URL.createObjectURL(stream)) || stream;
}, function(error) {
console.log(error)
});
// Below is the latest syntax. Using the old syntax for the time being for backwards compatibility.
// navigator.getUserMedia({video: true}, successCallback, errorCallback);
} else {
$("#qr-value").text('Sorry, native web camera streaming (getUserMedia) is not supported by this browser...')
return;
}
}, false);
答案 0 :(得分:0)
你显然应该使用Cordova的Camera plugin。文档可在链接上获得,您可以通过传递
设置使用后置摄像头cameraDirection: Camera.Direction.BACK
打开相机时的选项(来自文档)
navigator.camera.getPicture(onSuccess, onFail, {
quality: 50,
destinationType: Camera.DestinationType.FILE_URI,
cameraDirection: Camera.Direction.FRONT
});
function onSuccess(imageURI) {
var image = document.getElementById('myImage');
image.src = imageURI;
}
function onFail(message) {
alert('Failed because: ' + message);
}
答案 1 :(得分:-1)
你可以尝试离子(基于cordova),它具有qr阅读功能