cameraViewEx / com.priyankvasa.android.cameraviewex / CameraView

CameraView

class CameraView

Types

SavedState

data class SavedState

Constructors

<init>

CameraView(context: <ERROR CLASS>, attrs: <ERROR CLASS>? = null, defStyleAttr: Int = 0)

Properties

adjustViewBounds

var adjustViewBounds: Boolean

True when this CameraView is adjusting its bounds to preserve the aspect ratio of camera.

aspectRatio

var aspectRatio: AspectRatio

Current aspect ratio of camera. Valid format is "height:width" eg. "4:3".

autoFocus

var autoFocus: Boolean

true if the continuous auto-focus mode is enabled. false if it is disabled, or if it is not supported by the current camera.

awb

var awb: Int

Current auto white balance mode. Supported values Modes.AutoWhiteBalance.

cameraMode

var cameraMode: Int

The mode in which camera starts. Supported values Modes.CameraMode.

facing

var facing: Int

Direction that the current camera faces. Supported values are Modes.Facing.FACING_BACK and Modes.Facing.FACING_FRONT.

flash

var flash: Int

Current flash mode. Supported values Modes.Flash.

isCameraOpened

val isCameraOpened: Boolean

true if the camera is opened false otherwise.

noiseReduction

var noiseReduction: Int

Current noise reduction mode. Supported values Modes.NoiseReduction.

opticalStabilization

var opticalStabilization: Boolean

Current optical stabilization mode

outputFormat

var outputFormat: Int

Format of the output of image data produced from the camera. Supported values Modes.OutputFormat.

shutter

var shutter: Int

Current shutter time in milliseconds. Supported values Modes.Shutter.

supportedAspectRatios

val supportedAspectRatios: Set<AspectRatio>

Gets all the aspect ratios supported by the current camera.

zsl

var zsl: Boolean

Zero shutter lag mode capture.

Functions

addCameraClosedListener

fun addCameraClosedListener(listener: () -> Unit): CameraView

Add a new camera closed listener.

addCameraErrorListener

fun addCameraErrorListener(listener: (t: Throwable) -> Unit): CameraView

Add a new camera error listener.

addCameraOpenedListener

fun addCameraOpenedListener(listener: () -> Unit): CameraView

Add a new camera opened listener.

addPictureTakenListener

fun addPictureTakenListener(listener: (imageData: ByteArray) -> Unit): CameraView

Add a new picture taken listener.

capture

fun capture(): Unit

Take a picture. The result will be returned to listeners added by addPictureTakenListener.

onAttachedToWindow

fun onAttachedToWindow(): Unit

onDetachedFromWindow

fun onDetachedFromWindow(): Unit

onMeasure

fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int): Unit

onRestoreInstanceState

fun onRestoreInstanceState(state: <ERROR CLASS>?): Unit

onSaveInstanceState

fun onSaveInstanceState(): <ERROR CLASS>?

pauseVideoRecording

fun pauseVideoRecording(): Boolean

Pause video recording

removeAllListeners

fun removeAllListeners(): Unit

Remove all listeners previously set.

removeCameraClosedListener

fun removeCameraClosedListener(listener: () -> Unit): CameraView

Remove camera closed listener.

removeCameraErrorListener

fun removeCameraErrorListener(listener: (Throwable) -> Unit): CameraView

Remove camera error listener.

removeCameraOpenedListener

fun removeCameraOpenedListener(listener: () -> Unit): CameraView

Remove camera opened listener.

removePictureTakenListener

fun removePictureTakenListener(listener: (ByteArray) -> Unit): CameraView

Remove picture taken listener.

removePreviewFrameListener

fun removePreviewFrameListener(): CameraView

Remove preview frame listener.

resumeVideoRecording

fun resumeVideoRecording(): Boolean

Resume video recording

setPreviewFrameListener

fun setPreviewFrameListener(listener: (<ERROR CLASS>) -> Unit): CameraView

Set preview frame listener. Be careful while using this listener as it is invoked on each frame, which could be 60 times per second if frame rate is 60 fps. Ideally you should only process next frame once you are done processing previous frame. Don't continuously launch background tasks for each frame, it is not memory efficient, the device will run out of memory very quickly and force close the app.

start

fun start(): Unit

Open a camera device and start showing camera preview. This is typically called from Activity.onResume.

startVideoRecording

fun startVideoRecording(outputFile: File): Unit

Start capturing video.

stop

fun stop(removeAllListeners: Boolean = false): Unit

Stop camera preview and close the device. This is typically called from Activity.onPause.

stopVideoRecording

fun stopVideoRecording(): Boolean

Stop video recording