# Class CameraSession

java.lang.Object
com.codename1.camera.CameraSession

All Implemented Interfaces:
  `AutoCloseable`

public final class CameraSession extends java.lang.Object implements AutoCloseable

Active camera session. Obtained from `Camera#open(CameraInfo, CameraSessionOptions)`.

Only one `CameraSession` may be open at a time; opening a second throws `IllegalStateException`. Closing the session releases the camera hardware and invalidates any `CameraView` returned by `#createView()`.

Sessions may be paused (releasing hardware while keeping the session object) and resumed; this is the right pattern when the app temporarily uses the classic `com.codename1.capture.Capture` API while a session is open, since the OS-level camera device is single-tenant.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `addFrameListener(FrameListener l)`
  Backwards-compatible alias for `#setFrameListener(FrameListener)`.
  `void`
  `close()`
  Release the session.
  `CameraView`
  `createView()`
  Create the live preview component.
  `void`
  `focus(float xNorm, float yNorm)`
  Request a focus operation at the normalized preview coordinate (`0.0` top-left, `1.0` bottom-right).
  `CameraInfo`
  `getInfo()`
  The `CameraInfo` for the physical camera this session is attached to.
  `CameraSessionOptions`
  `getOptions()`
  The options the session was opened with.
  `boolean`
  `isClosed()`
  True once `#close()` has been called on this session.
  `void`
  `pause()`
  Release the hardware but keep this session object alive.
  `void`
  `removeFrameListener(FrameListener l)`
  `void`
  `resume()`
  Re-acquire the hardware after `#pause()`.
  `void`
  `setFlashMode(FlashMode m)`
  Set the flash / torch behavior.
  `void`
  `setFrameListener(FrameListener l)`
  Install a frame listener.
  `void`
  `setZoom(float ratio)`
  Set the zoom ratio where `1.0` is no zoom and values above `1.0` zoom in.
  `VideoRecording`
  `startVideoRecording(String filePath)`
  Begin recording video to the given FileSystemStorage path.
  `AsyncResource<CapturedPhoto>`
  `takePhoto()`
  Capture a still photo with default options.
  `AsyncResource<CapturedPhoto>`
  `takePhoto(PhotoCaptureOptions opts)`
  Capture a still photo using the given options (size, quality, file path).

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Method Details

  - ### createView

    public CameraView createView()
    Create the live preview component. Each session owns one view; subsequent calls return the same instance.

  - ### takePhoto

    public AsyncResource<CapturedPhoto> takePhoto()
    Capture a still photo with default options.

  - ### takePhoto

    public AsyncResource<CapturedPhoto> takePhoto(PhotoCaptureOptions opts)
    Capture a still photo using the given options (size, quality, file path). The returned `AsyncResource` resolves on the EDT with the captured photo, or fires its error callback if capture fails.

  - ### startVideoRecording

    public VideoRecording startVideoRecording(String filePath)
    Begin recording video to the given FileSystemStorage path. The returned `VideoRecording` is the handle used to stop the recording.

  - ### setFrameListener

    public void setFrameListener(FrameListener l)
    Install a frame listener. At most one frame listener may be active per session; installing a second replaces the first. Pass `null` to remove.

  - ### addFrameListener

    public void addFrameListener(FrameListener l)
    Backwards-compatible alias for `#setFrameListener(FrameListener)`.

  - ### removeFrameListener

    public void removeFrameListener(FrameListener l)

  - ### setFlashMode

    public void setFlashMode(FlashMode m)
    Set the flash / torch behavior. No-op on cameras whose `CameraInfo#hasFlash()` is false.

  - ### setZoom

    public void setZoom(float ratio)
    Set the zoom ratio where `1.0` is no zoom and values above `1.0` zoom in. The platform implementation clamps to the supported range.

  - ### focus

    public void focus(float xNorm, float yNorm)
    Request a focus operation at the normalized preview coordinate (`0.0` top-left, `1.0` bottom-right).

  - ### getInfo

    public CameraInfo getInfo()
    The `CameraInfo` for the physical camera this session is attached to.

  - ### getOptions

    public CameraSessionOptions getOptions()
    The options the session was opened with. Read-only snapshot; mutating it after `Camera#open(CameraInfo, CameraSessionOptions)` has no effect.

  - ### pause

    public void pause()
    Release the hardware but keep this session object alive. Pair with `#resume()`.

  - ### resume

    public void resume()
    Re-acquire the hardware after `#pause()`. No-op if the session is already running.

  - ### close

    public void close()
    Release the session. Idempotent.
    Specified by:
      `close` in interface `AutoCloseable`

  - ### isClosed

    public boolean isClosed()
    True once `#close()` has been called on this session.