WEBVTT

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

00:00.920 --> 00:03.160
We created this image analyzer.

00:03.360 --> 00:06.240
Now let's set up the image capture.

00:06.480 --> 00:08.040
Scroll down here.

00:08.080 --> 00:11.520
Don't worry about the red lines.

00:11.520 --> 00:14.240
We're going to use the returning statement.

00:14.280 --> 00:17.160
So this is just a missing the returning statement.

00:17.560 --> 00:23.280
Image capture equals to image capture dot build set target rotation.

00:23.480 --> 00:32.600
And instead of using surface dot rotation we're going to use the preview view preview view dot display

00:33.040 --> 00:34.840
dot rotation.

00:35.040 --> 00:38.040
Then we're going to use the build function.

00:38.080 --> 00:45.680
Here we are assigning the image capture state variable for use throughout the app.

00:45.920 --> 00:52.080
So here the image capture equals to image capture dot builder.

00:52.120 --> 00:58.680
Image capture dot builder creates a builder for capturing still photos.

00:58.840 --> 01:01.080
Set target rotation.

01:01.080 --> 01:11.190
Sets the target rotation for the image capture use cases and build function builds the image capture

01:11.390 --> 01:12.190
instance.

01:12.350 --> 01:21.270
This is a professional way to configure a use case specifically for taking high quality still photos.

01:21.550 --> 01:31.870
Target rotations ensures captured images have the correct orientation based on how the device is held

01:31.870 --> 01:34.390
and the preview dot display.

01:34.430 --> 01:40.630
Dot rotation automatically handles device rotation changes.

01:40.750 --> 01:49.030
This is very important for setting up the camera to capture properly oriented photos that match what

01:49.030 --> 01:51.390
the user sees in the preview.

01:51.430 --> 01:58.150
Let's continue configuring our camera and under the camera capture and the image capture.

01:58.190 --> 02:02.150
Sorry, we need to create the camera selector.

02:02.190 --> 02:07.470
Val camera selector equals to camera selector.

02:07.630 --> 02:10.030
Dot default back camera.

02:10.070 --> 02:15.900
We are setting and using the back camera camera provider that we created before.

02:16.300 --> 02:27.740
Dot and bind all this unbind all function Unbinds all previously bound use cases cleans up existing

02:27.740 --> 02:29.060
camera sessions.

02:29.260 --> 02:33.300
Then we need to bind to life cycle.

02:33.300 --> 02:38.740
So camera provider dot bind to life cycle.

02:38.860 --> 02:48.380
And we need to pass five parameters lifecycle, camera selector, image preview or image capture preview

02:48.380 --> 02:49.980
and analyzer.

02:50.220 --> 02:56.900
Here we need to switch the is because lifecycle camera selector.

02:57.020 --> 03:00.820
If we go to the bind here we have lifecycle owner.

03:00.860 --> 03:02.700
That's the first variable.

03:02.900 --> 03:11.580
The first variable is uh is the lifecycle owner ties the camera to component lifecycle automatically

03:11.580 --> 03:22.730
starts and stop camera selector chooses which camera front or back The image capture, preview and analyzer.

03:22.970 --> 03:25.210
The use cases to bind.

03:25.410 --> 03:31.650
This is a clean setup and binds all sessions before starting new ones.

03:31.850 --> 03:39.570
Camera automatically poses resumes with life cycle, so I'm attaching it to the life cycle.

03:39.610 --> 03:46.890
Multiple use cases like image capture, preview and image analysis binds preview, capture and analysis

03:46.890 --> 03:49.930
together so they work simultaneously.

03:49.930 --> 03:58.970
This is a camera start up when life cycle becomes active, all bound use cases receive camera frames.

03:59.010 --> 04:05.770
Camera stops when life cycle is destroyed because it's attached to life cycle owner and no manual camera

04:05.770 --> 04:08.010
resource management needed.

04:08.210 --> 04:13.930
This is the standard pattern for setting up camera Ex with multiple functionalities.

04:13.930 --> 04:22.490
But here I need to switch the preview with camera with the image capture, making it the third and the

04:22.490 --> 04:24.240
fourth Parameter.

04:24.520 --> 04:30.360
And here we need to close this.

04:30.400 --> 04:33.040
And this is the listener.

04:33.200 --> 04:40.120
And outside the listener we need to pass the executor as the second parameter.

04:40.280 --> 04:42.480
And here we go okay.

04:42.760 --> 04:52.600
Now let me set the preview equals to preview dot builder dot dot also and set the set it to surface

04:52.640 --> 04:53.480
Provider.

04:53.600 --> 05:02.360
You can set the surface provider like this or like this equals to preview view dot surface provider

05:02.400 --> 05:02.960
okay.

05:03.240 --> 05:07.880
Now what we need to return is the preview view okay.

05:08.040 --> 05:16.200
What we've done here the Preview Builder build creates a preview use case with default settings.

05:16.440 --> 05:25.840
Also immediately configures the preview after building it, and it's surface provider connects the preview

05:25.840 --> 05:27.840
to the UI surface.

05:28.000 --> 05:33.070
This creates the camera preview that shows what the camera sees.

05:33.310 --> 05:36.150
Links the camera output to the preview view.

05:36.230 --> 05:43.990
Typically a preview view composable XML and the service provider handles rendering camera frames onto

05:43.990 --> 05:44.870
the display.

05:45.110 --> 05:52.030
How it works camera frames are streamed to the preview view via the service provider.

05:52.190 --> 05:56.270
Users see a live camera preview in the UI.

05:56.670 --> 06:02.870
This is essential for camera apps so users can frame their shots.

06:02.990 --> 06:10.390
The result is the camera feed becomes visible in your app's UI through the camera preview, and this

06:10.390 --> 06:17.790
is the returning type of this function and the returning type of this Android view.

06:17.830 --> 06:20.750
Okay, so congratulations guys.

06:20.750 --> 06:29.590
We set it correctly the camera, and we used our variables in order to control the settings and make

06:29.630 --> 06:33.310
sure that the camera runs perfectly.
