WEBVTT

00:00.080 --> 00:00.840
Welcome back.

00:00.840 --> 00:03.760
We created that camera permission wrapper.

00:04.000 --> 00:07.480
Now let's create the camera preview inside the screens.

00:07.480 --> 00:12.640
Create a new file, name it as camera preview.

00:12.680 --> 00:22.360
Create a new composable function named as camera Preview and pass two parameters modifier.

00:22.680 --> 00:32.280
It's of type modifier and set the modifier equals to the modifier as initial and as a default and on

00:32.280 --> 00:34.280
image analysis.

00:34.480 --> 00:35.880
Image analysis.

00:36.000 --> 00:45.240
And it's a lambda function that takes an image analysis as parameter and returns a unit as a callback.

00:45.240 --> 00:54.560
Okay, so let me start by val context equals to local context dot concurrent.

00:54.560 --> 01:04.790
We are getting the context val life cycle owner equals to the local life cycle owner dot.

01:05.870 --> 01:06.310
Okay.

01:06.350 --> 01:11.070
Those variables, we talked a lot about them in the previous applications.

01:11.110 --> 01:16.190
Val camera provider future equals to remember.

01:16.190 --> 01:23.710
And here we need to process camera provider dot get instance process camera provider.

01:23.830 --> 01:27.230
It's from camera dot lifecycle package.

01:27.230 --> 01:32.310
Here we are starting the usage of camera X okay.

01:32.510 --> 01:41.070
So camera provider future gets the camera provider instance manages the camera lifecycle.

01:41.070 --> 01:42.630
This is a very important note.

01:42.630 --> 01:44.510
You should pay attention to it.

01:44.710 --> 01:52.430
Camera provider future gets the camera provider instance and that manages the camera lifecycle.

01:52.430 --> 01:57.630
Then we need to create another variable called image capture.

01:57.790 --> 02:05.030
So here we need to handle the state state for capturing still photos.

02:05.030 --> 02:10.290
How to create this variable is very simple image capture.

02:10.410 --> 02:17.770
It's of type image capture that is used for capturing still by and the mutable.

02:20.410 --> 02:23.610
We are handling the state of the image.

02:23.610 --> 02:28.530
Capture Alt+ enter to import the by and import the mutable dot get value.

02:28.570 --> 02:36.770
Then we need another variable, the preview state for camera preview display.

02:36.770 --> 02:38.410
Similar to what we've created.

02:38.450 --> 02:49.970
What we've done here var preview by remember mutable state of and it's of type preview.

02:50.010 --> 02:53.450
Import the preview from Android X camera.

02:53.770 --> 02:54.970
And this is good.

02:55.010 --> 02:57.890
Now we need to create the executor.

02:58.010 --> 03:06.810
Val executor equals to the context compat dot get main executor context.

03:06.850 --> 03:15.600
This is the main thread executor for camera callbacks because we need to use it inside the main thread.

03:15.640 --> 03:19.440
The last thing we need to create is the camera provider.

03:19.480 --> 03:27.200
This is the actual camera provider from the future and this is done by val camera provider.

03:27.240 --> 03:31.400
Equals to camera provider dot get.

03:31.440 --> 03:40.080
The purpose of creating executor camera provider preview, image capture and camera provider is to initialize

03:40.080 --> 03:50.360
camera components needed for camera functionality and this uses reactive state so UI updates when camera

03:50.360 --> 03:52.240
components are ready.

03:52.480 --> 03:58.760
Prepares the infrastructure for showing camera preview here.

03:58.920 --> 04:07.800
Taking pictures using the image capture and managing camera lifecycle using the camera provider.

04:07.960 --> 04:14.800
This sets up the foundation for camera operations in a compose friendly way.
