|
4 | 4 | import static io.flutter.plugins.camera.CameraUtils.computeBestPreviewSize; |
5 | 5 |
|
6 | 6 | import android.annotation.SuppressLint; |
| 7 | +import android.annotation.TargetApi; |
7 | 8 | import android.app.Activity; |
8 | 9 | import android.content.Context; |
9 | 10 | import android.graphics.ImageFormat; |
|
16 | 17 | import android.hardware.camera2.CameraMetadata; |
17 | 18 | import android.hardware.camera2.CaptureFailure; |
18 | 19 | import android.hardware.camera2.CaptureRequest; |
| 20 | +import android.hardware.camera2.params.OutputConfiguration; |
| 21 | +import android.hardware.camera2.params.SessionConfiguration; |
19 | 22 | import android.hardware.camera2.params.StreamConfigurationMap; |
20 | 23 | import android.media.CamcorderProfile; |
21 | 24 | import android.media.Image; |
22 | 25 | import android.media.ImageReader; |
23 | 26 | import android.media.MediaRecorder; |
24 | 27 | import android.os.Build; |
| 28 | +import android.os.Build.VERSION; |
| 29 | +import android.os.Build.VERSION_CODES; |
25 | 30 | import android.util.Size; |
26 | 31 | import android.view.OrientationEventListener; |
27 | 32 | import android.view.Surface; |
|
39 | 44 | import java.util.HashMap; |
40 | 45 | import java.util.List; |
41 | 46 | import java.util.Map; |
| 47 | +import java.util.concurrent.Executors; |
42 | 48 |
|
43 | 49 | public class Camera { |
44 | 50 | private final SurfaceTextureEntry flutterTexture; |
@@ -325,12 +331,42 @@ public void onConfigureFailed(@NonNull CameraCaptureSession cameraCaptureSession |
325 | 331 | } |
326 | 332 | }; |
327 | 333 |
|
328 | | - // Collect all surfaces we want to render to. |
329 | | - List<Surface> surfaceList = new ArrayList<>(); |
330 | | - surfaceList.add(flutterSurface); |
331 | | - surfaceList.addAll(remainingSurfaces); |
332 | 334 | // Start the session |
333 | | - cameraDevice.createCaptureSession(surfaceList, callback, null); |
| 335 | + if (VERSION.SDK_INT >= VERSION_CODES.P) { |
| 336 | + // Collect all surfaces we want to render to. |
| 337 | + List<OutputConfiguration> configs = new ArrayList<>(); |
| 338 | + configs.add(new OutputConfiguration(flutterSurface)); |
| 339 | + for (Surface surface : remainingSurfaces) { |
| 340 | + configs.add(new OutputConfiguration(surface)); |
| 341 | + } |
| 342 | + createCaptureSessionWithSessionConfig(configs, callback); |
| 343 | + } else { |
| 344 | + // Collect all surfaces we want to render to. |
| 345 | + List<Surface> surfaceList = new ArrayList<>(); |
| 346 | + surfaceList.add(flutterSurface); |
| 347 | + surfaceList.addAll(remainingSurfaces); |
| 348 | + createCaptureSession(surfaceList, callback); |
| 349 | + } |
| 350 | + } |
| 351 | + |
| 352 | + @TargetApi(VERSION_CODES.P) |
| 353 | + private void createCaptureSessionWithSessionConfig( |
| 354 | + List<OutputConfiguration> outputConfigs, CameraCaptureSession.StateCallback callback) |
| 355 | + throws CameraAccessException { |
| 356 | + cameraDevice.createCaptureSession( |
| 357 | + new SessionConfiguration( |
| 358 | + SessionConfiguration.SESSION_REGULAR, |
| 359 | + outputConfigs, |
| 360 | + Executors.newSingleThreadExecutor(), |
| 361 | + callback)); |
| 362 | + } |
| 363 | + |
| 364 | + @TargetApi(VERSION_CODES.LOLLIPOP) |
| 365 | + @SuppressWarnings("deprecation") |
| 366 | + private void createCaptureSession( |
| 367 | + List<Surface> surfaces, CameraCaptureSession.StateCallback callback) |
| 368 | + throws CameraAccessException { |
| 369 | + cameraDevice.createCaptureSession(surfaces, callback, null); |
334 | 370 | } |
335 | 371 |
|
336 | 372 | public void startVideoRecording(String filePath, Result result) { |
|
0 commit comments