Camposer: Jetpack Compose camera library for Android
Tired to use a camera library with interoperability using Jetpack Compose? so Camposer was made for you, a camera library only using Jetpack Compose.
This story will guide you on how to implement Camposer into your project, so let’s start!
Setup
First, you need to add a dependency, with the latest version, to your build.gradle (module):
dependencies {
implementation("io.github.ujizin:camposer:<version>")
}
How it works
Let’s begin using CameraPreview to display on UI.
CameraPreview
is the composable function to display the camera preview.CameraState
is not required for preview, but it’s necessary for action as taking a picture, recording videos, and for internal states (flash & image analyzer)
Switch Cameras
To switch cameras, use CamSelector.Back
or CamSelector.Front
, and it can be used with a state like the below example:
Taking pictures
for this, you’ll just need to use CameraState
and call takePicture
method from it, like the example below:
Recording Video
It’s very similar to taking pictures. For this, you need to change the capture mode for CaptureMode.Video
and call toggleRecording
twice times for stop recording.
ps: you can use startRecording
and stopRecording
separately.
Other Configurations
There are a lot of other configurations on Camposer, if you want to use some of them check out the Camposer Wiki for more information!
And that’s all folks!
Check out the sample projects (including this from the story).
Have a fun code()
!