Sitemap

Camposer: Jetpack Compose camera library for Android

2 min readNov 25, 2022
Photo by Pixabay from Pexels

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!

camera preview recording video
https://github.com/ujizin/Camposer/tree/main/camposer

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.

Camera preview
  • 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:

Switch camera

Taking pictures

for this, you’ll just need to use CameraState and call takePicture method from it, like the example below:

CaptureMode Image

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.

CaptureMode video

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!

--

--

No responses yet