Packages
mob
0.6.0
0.7.20
0.7.19
0.7.18
0.7.17
0.7.16
0.7.15
0.7.14
0.7.13
0.7.12
0.7.11
0.7.10
0.7.9
0.7.8
0.7.7
0.7.6
0.7.5
0.7.4
0.7.3
0.7.2
0.7.1
0.7.0
0.6.26
0.6.25
0.6.24
0.6.23
0.6.22
0.6.21
0.6.20
0.6.19
0.6.18
0.6.17
0.6.16
0.6.15
0.6.14
0.6.13
0.6.12
0.6.11
0.6.10
0.6.9
0.6.8
0.6.7
0.6.6
0.6.5
0.6.2
0.6.1
0.6.0
0.5.18
0.5.17
0.5.16
0.5.15
0.5.14
0.5.11
0.5.10
0.5.7
0.5.6
0.5.5
0.5.4
0.5.3
0.5.2
0.5.1
0.5.0
0.4.0
0.3.10
0.3.9
0.3.8
0.3.7
0.3.6
0.3.5
0.3.4
0.3.3
0.3.2
0.3.1
0.3.0
0.2.0
0.1.0
BEAM-on-device mobile framework for Elixir
Current section
Files
Jump to
Current section
Files
lib/mob/camera.ex
defmodule Mob.Camera do
@moduledoc """
Native camera capture for photos and videos.
Requires `:camera` permission (and `:microphone` for video).
Opens the native OS camera UI. Results arrive as:
handle_info({:camera, :photo, %{path: path, width: w, height: h}}, socket)
handle_info({:camera, :video, %{path: path, duration: seconds}}, socket)
handle_info({:camera, :cancelled}, socket)
The `path` is a local temp file. Copy it elsewhere before the next capture.
iOS: `UIImagePickerController`. Android: `TakePicture` / `CaptureVideo` activity contracts.
"""
@doc """
Open the camera to capture a photo.
Options:
- `quality: :high | :medium | :low` (default `:high`) — JPEG compression level
"""
@spec capture_photo(Mob.Socket.t(), keyword()) :: Mob.Socket.t()
def capture_photo(socket, opts \\ []) do
quality = Keyword.get(opts, :quality, :high)
:mob_nif.camera_capture_photo(quality)
socket
end
@doc """
Open the camera to record a video.
Options:
- `max_duration: integer` — maximum clip length in seconds (default `60`)
"""
@spec capture_video(Mob.Socket.t(), keyword()) :: Mob.Socket.t()
def capture_video(socket, opts \\ []) do
max_duration = Keyword.get(opts, :max_duration, 60)
:mob_nif.camera_capture_video(max_duration)
socket
end
@doc """
Start a live camera preview session. Pair with a `:camera_preview` component
in your render tree to display the feed.
Options:
- `facing: :back | :front` (default `:back`)
"""
@spec start_preview(Mob.Socket.t(), keyword()) :: Mob.Socket.t()
def start_preview(socket, opts \\ []) do
facing = Keyword.get(opts, :facing, :back) |> Atom.to_string()
:mob_nif.camera_start_preview(:json.encode(%{"facing" => facing}))
socket
end
@doc "Stop the active camera preview session."
@spec stop_preview(Mob.Socket.t()) :: Mob.Socket.t()
def stop_preview(socket) do
:mob_nif.camera_stop_preview()
socket
end
end