Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Camera APIで何か

flatbird
November 15, 2014

Camera APIで何か

FxOSコードリーディングミートアップ#11 2014/11/15

flatbird

November 15, 2014
Tweet

Other Decks in Programming

Transcript

  1. アプリの権限 web (通常) • ホスト型アプリ。 • または、特権なしパッケージ型アプリ。 privileged (特権) •

    パッケージ型アプリのみ。 • Marketplace での審査が必要。 certified (認定) • プレインストールアプリ(パッケージ型)。 • 一般開発者は使えない。 権限によって使える API が異なる。
  2. 昔見たときのパーミッション FxOS 1.1 くらい? web alarms, fmradio, geolocation, storage, desktop-

    notification privileged browser, contacts, systemXHR, tcp-socket, device- storage:music, device-storage:videos, device-storage: pictures, device-storage:sdcard certified backgroundservice, bluetooth, camera, mobileconnection, power, settings, sms, systemclock, telephony, webapps-manage, wifi-manage
  3. FxOS 1.1 くらい? web alarms, fmradio, geolocation, storage, desktop- notification

    privileged browser, contacts, systemXHR, tcp-socket, device- storage:music, device-storage:videos, device-storage: pictures, device-storage:sdcard certified backgroundservice, bluetooth, camera, mobileconnection, power, settings, sms, systemclock, telephony, webapps-manage, wifi-manage カメラも使えないのか、、、という衝撃 昔見たときのパーミッション
  4. Camera API を使わずカメラを使う • 写真が欲しい場合 ◦ Web Activities • リアルタイムのカメラ画像

    (ビデオスト リーム) が欲しい場合 ◦ getUserMedia() ◦ Firefox OS 1.4 以降 "video-capture" が 使えるように
  5. Web Activities var activity = new MozActivity({ // Ask for

    the "pick" activity name: "pick", // Provide the data required by the filters of the activity data: { type: "image/jpeg" } }); activity.onsuccess = function() { var blob = this.result.blob; var img = document.querySelector('img'); img.src = window.URL.createObjectURL(blob); }; activity.onerror = function() { console.log(this.error); };
  6. getUserMedia navigator.getUserMedia = (navigator.getUserMedia || navigator.mozGetUserMedia); navigator.getUserMedia( // constraints {

    video: true, audio: false }, // successCallback function(stream) { var video = document.querySelector('video'); video.src = window.URL.createObjectURL(stream); video.play(); }, // errorCallback function(err) { console.log("The following error occured: " + err); } );
  7. Camera API を使う時 カメラアプリを作る時 Note: Except if you are implementing

    a replacement for the default Camera application, you shouldn't use this API. Instead, if you want to use the camera in your device, you should use the Web Activities API. https://developer.mozilla.org/docs/Web/API/Camera_API
  8. Camera API で出来ること • 写真撮影 … takePicture() • プレビュー …

    getPreviewStream() • 動画撮影 … startRecording() • フォーカス … autoFocus(), focusAreas, etc. • ズーム … zoom • ホワイトバランス … whiteBalanceMode • シーン … sceneMode • フラッシュ … flashMode • エフェクト … effect
  9. CameraControl • 写真撮影 … takePicture() • プレビュー … getPreviewStream() •

    動画撮影 … startRecording() • フォーカス … autoFocus(), focusAreas, etc. • ズーム … zoom • ホワイトバランス … whiteBalanceMode • シーン … sceneMode • フラッシュ … flashMode • エフェクト … effect
  10. previewSizes: {"height":720,"width":1280},{"height":480,"width":864},{"height": 480,"width":800},{"height":432,"width":768},{"height":480,"width":720},{"height": 480,"width":640},{"height":432,"width":576},{"height":320,"width":480},{"height": 288,"width":384},{"height":288,"width":352},{"height":240,"width":320},{"height": 160,"width":240},{"height":144,"width":176},{"height":176,"width":144} pictureSizes: {"height":1944,"width":2592},{"height":1536,"width":2048},{"height": 1080,"width":1920},{"height":1200,"width":1600},{"height":768,"width":1280}, {"height":720,"width":1280},{"height":768,"width":1024},{"height":600,"width":

    800},{"height":480,"width":800},{"height":480,"width":720},{"height":480,"width": 640},{"height":288,"width":352},{"height":240,"width":320},{"height":144,"width": 176} thumbnailSizes: {"height":480,"width":640},{"height":288,"width":512},{"height": 288,"width":480},{"height":154,"width":256},{"height":288,"width":432},{"height": 240,"width":320},{"height":144,"width":176},{"height":0,"width":0} videoSizes: {"height":720,"width":1280},{"height":480,"width":864},{"height":480," width":800},{"height":480,"width":720},{"height":480,"width":640},{"height":320," width":480},{"height":288,"width":352},{"height":240,"width":320},{"height":144," width":176}
  11. recorderProfiles: low:{"format":"3gp","video":{"codec":"h264","bitrate":192000,"framerate":30," width":176,"height":144},"audio":{"codec":"amrnb","bitrate":12200,"samplerate": 8000,"channels":1}}, high:{"format":"mp4","video":{"codec":"h264","bitrate":14000000,"framerate":30," width":1280,"height":720},"audio":{"codec":"aac","bitrate":156000,"samplerate": 48000,"channels":2}}, qcif:{"format":"3gp","video":{"codec":"h264","bitrate":192000,"framerate":30," width":176,"height":144},"audio":{"codec":"amrnb","bitrate":12200,"samplerate": 8000,"channels":1}},

    cif:{"format":"3gp","video":{"codec":"h264","bitrate":720000,"framerate":30," width":352,"height":288},"audio":{"codec":"amrnb","bitrate":12200,"samplerate": 8000,"channels":1}}, 480p:{"format":"mp4","video":{"codec":"h264","bitrate":2000000,"framerate":30," width":720,"height":480},"audio":{"codec":"aac","bitrate":156000,"samplerate": 48000,"channels":2}}, 720p:{"format":"mp4","video":{"codec":"h264","bitrate":14000000,"framerate":30," width":1280,"height":720},"audio":{"codec":"aac","bitrate":156000,"samplerate": 48000,"channels":2}}, isoModes: "auto","hjr","100","200","400","800","1600"
  12. back front previewSizes 最大 720x1280 最大 480x640 pictureSizes 最大 1194x2592

    最大 1200x1600 videoSizes 最大 720x1280 最大 480x640 fileFormats jpeg,bayer-mipi-10bggr,bayer-ideal-qcom-10bggr, bayer-qcom-10bggr,yuv422sp jpeg,yuv422sp sceneModes auto,asd,landscape,snow,beach,sunset,night, portrait,backlight,sports,steadyphoto,flowers, candlelight,fireworks,party,night-portrait,theatre, action,AR,hdr なし effects none,mono,negative,solarize,sepia,posterize, whiteboard,blackboard,aqua なし flashModes off,auto,on,torch なし focusModes auto,infinity,macro,continuous-video,continuous- picture fixed maxFocusAreas 1 0 recorderProfiles low(3gp),high(mp4),qcif(3gp),cif(3gp),480p (mp4),720p(mp4) low(3gp),qcif(3gp), cif(3gp)
  13. おまけ1 mozCamera? mozCameras? • MDN のドキュメントは mozCamera と書いてあ るけど実際に取れるのは mozCameras

    • mozCameras のほうには mozCamera に変 わったのでそっちを見ろと書いてある。 https://developer.mozilla.org/en-US/docs/Web/API/Navigator.mozCameras
  14. おまけ2 フラッシュライトはできるのか? Bug 968119 - Need a privileged (not certified)

    API for accessing the camera's flash https://bugzilla.mozilla.org/show_bug.cgi?id=968119
  15. できた var mode = flashON ? 'torch' : 'off'; var

    capabilities = mainCamera.capabilities; if (capabilities.flashModes.indexOf(mode) > -1) { mainCamera.flashMode = mode; console.log('flashMode=' + mainCamera.flashMode); }