Contenu connexe Similaire à 進撃の火狐裏話 -cameraデバイスは使えません- (6) 進撃の火狐裏話 -cameraデバイスは使えません-11. どういうことか?
Camera API
アプリの許可設定 / App permissions
https://developer.mozilla.org/en-US/docs/WebAPI/Camera
https://developer.mozilla.org/en-US/docs/Web/Apps/App_permissions
23. app.jsをゴリゴリ書く
var storage = navigator.getDeviceStorage('pictures');
var display = document.getElementsByTagName('video')[0];
var cameras = window.navigator.mozCameras;
var options = {
camera: cameras.getListOfCameras()[0]
};
var pictureOptions = {
rotation: 0,
pictureSize: null,
fileFormat: null
};
var captureBtn = document.getElementById('capture-btn');
var cameracontrol = null;
function onStreamReady(stream) {
display.mozSrcObject = stream;
display.play();
};
function onFocusPossible(success) {
if(success){
console.log("The image has been focused");
}else{
console.log("The image has not been focused");
}
};
function onFocusNotPossible(error) {
console.log("The camera is not able to focus anything");
console.log(error);
};
function onSuccess(camera) {
var size = camera.capabilities.previewSizes[0];
cameracontrol = camera;
camera.getPreviewStream(size, onStreamReady);
camera.autoFocus(onFocuesPossible, onFocusNotPossible);
};
function onError(error) {
console.warn(error);
};
function onPictureTaken(blob) {
storage.addNamed(blob, 'test.jpg');
cameracontrol.resumePreview();
};
cameras.getCamera(options, onSuccess, onError);
captureBtn.addEventListener('click', function() {
pictureOptions.pictureSize = cameracontrol.capabilities.pictureSizes[0];
pictureOptions.fileformat = cameracontrol.capabilities.fileFormats[0];
cameracontrol.takePicture(pictureOptions, onPictureTaken);
}
);
29. Camera applicationに潜む罠
KEONとNexus Sで挙動が違う
navigator.mozCameras() の応答
KEON
JavaScript Error: "TypeError: navigator.mozCameras is null"
{file: "app://orecamera.gaiamobile.org/js/app.js" line: 6}
Nexus S
No problem.
navigator.mozCameras()はCameraを使用する場合に最初に呼ぶので
動かないと困る。
ただ、標準のCameraアプリでもCallしているように⾒えるので、
何か手順を踏む必要があるのかも?(未調査)