diff --git a/packages/camera/camera/CHANGELOG.md b/packages/camera/camera/CHANGELOG.md index 901548e9b6d5..82d2e82c35e2 100644 --- a/packages/camera/camera/CHANGELOG.md +++ b/packages/camera/camera/CHANGELOG.md @@ -1,3 +1,10 @@ +## 0.11.0 + +* **Breaking Change** Changes the Android implementation of the camera plugin from `camera_android` + to `camera_android_camerax`, which has better support for a wider range of devices. The CameraX + implementation full feature parity with `camera_android` except for the limitations listed in + `README.md`. To continue using `camera_android`, follow [these instructions](https://pub.dev/packages/camera_android#usage). + ## 0.10.6 * Adds support to control video fps and bitrate. See `CameraController` constructor. diff --git a/packages/camera/camera/README.md b/packages/camera/camera/README.md index 5458b926c499..c5493160ab9a 100644 --- a/packages/camera/camera/README.md +++ b/packages/camera/camera/README.md @@ -45,7 +45,10 @@ Change the minimum Android sdk version to 21 (or higher) in your `android/app/bu minSdkVersion 21 ``` -It's important to note that the `MediaRecorder` class is not working properly on emulators, as stated in the documentation: https://developer.android.com/reference/android/media/MediaRecorder. Specifically, when recording a video with sound enabled and trying to play it back, the duration won't be correct and you will only see the first frame. +The endorsed [`camera_android_camerax`][2] implementation of the camera plugin built with CameraX has +better support for more devices than `camera_android`, but has some limitations; please see [this list][3] +for more details. If you wish to use the [`camera_android`][4] implementation of the camera plugin +built with Camera2 that lacks these limitations, please follow [these instructions][5]. ### Web integration @@ -167,3 +170,7 @@ class _CameraAppState extends State { For a more elaborate usage example see [here](https://github.com/flutter/packages/tree/main/packages/camera/camera/example). [1]: https://pub.dev/packages/camera_web#limitations-on-the-web-platform +[2]: https://pub.dev/packages/camera_android_camerax +[3]: https://pub.dev/packages/camera_android_camerax#limitations +[4]: https://pub.dev/packages/camera_android +[5]: https://pub.dev/packages/camera_android#usage diff --git a/packages/camera/camera/example/integration_test/camera_test.dart b/packages/camera/camera/example/integration_test/camera_test.dart index 1985d1793c66..e1fe14a6132e 100644 --- a/packages/camera/camera/example/integration_test/camera_test.dart +++ b/packages/camera/camera/example/integration_test/camera_test.dart @@ -145,6 +145,40 @@ void main() { skip: true, ); + testWidgets('Video capture records valid video', (WidgetTester tester) async { + final List cameras = await availableCameras(); + if (cameras.isEmpty) { + return; + } + + final CameraController controller = CameraController( + cameras[0], + ResolutionPreset.low, + enableAudio: false, + ); + await controller.initialize(); + await controller.prepareForVideoRecording(); + + await controller.startVideoRecording(); + final int recordingStart = DateTime.now().millisecondsSinceEpoch; + + sleep(const Duration(seconds: 2)); + + final XFile file = await controller.stopVideoRecording(); + final int recordingTime = + DateTime.now().millisecondsSinceEpoch - recordingStart; + + final File videoFile = File(file.path); + final VideoPlayerController videoController = VideoPlayerController.file( + videoFile, + ); + await videoController.initialize(); + final int duration = videoController.value.duration.inMilliseconds; + await videoController.dispose(); + + expect(duration, lessThan(recordingTime)); + }); + testWidgets('Pause and resume video recording', (WidgetTester tester) async { final List cameras = await availableCameras(); if (cameras.isEmpty) { @@ -162,26 +196,21 @@ void main() { int startPause; int timePaused = 0; + const int pauseIterations = 2; await controller.startVideoRecording(); final int recordingStart = DateTime.now().millisecondsSinceEpoch; sleep(const Duration(milliseconds: 500)); - await controller.pauseVideoRecording(); - startPause = DateTime.now().millisecondsSinceEpoch; - sleep(const Duration(milliseconds: 500)); - await controller.resumeVideoRecording(); - timePaused += DateTime.now().millisecondsSinceEpoch - startPause; - - sleep(const Duration(milliseconds: 500)); - - await controller.pauseVideoRecording(); - startPause = DateTime.now().millisecondsSinceEpoch; - sleep(const Duration(milliseconds: 500)); - await controller.resumeVideoRecording(); - timePaused += DateTime.now().millisecondsSinceEpoch - startPause; + for (int i = 0; i < pauseIterations; i++) { + await controller.pauseVideoRecording(); + startPause = DateTime.now().millisecondsSinceEpoch; + sleep(const Duration(milliseconds: 500)); + await controller.resumeVideoRecording(); + timePaused += DateTime.now().millisecondsSinceEpoch - startPause; - sleep(const Duration(milliseconds: 500)); + sleep(const Duration(milliseconds: 500)); + } final XFile file = await controller.stopVideoRecording(); final int recordingTime = diff --git a/packages/camera/camera/pubspec.yaml b/packages/camera/camera/pubspec.yaml index 10533970c7ea..4ef3147fbd62 100644 --- a/packages/camera/camera/pubspec.yaml +++ b/packages/camera/camera/pubspec.yaml @@ -4,7 +4,7 @@ description: A Flutter plugin for controlling the camera. Supports previewing Dart. repository: https://github.com/flutter/packages/tree/main/packages/camera/camera issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+camera%22 -version: 0.10.6 +version: 0.11.0 environment: sdk: ^3.2.3 @@ -14,14 +14,14 @@ flutter: plugin: platforms: android: - default_package: camera_android + default_package: camera_android_camerax ios: default_package: camera_avfoundation web: default_package: camera_web dependencies: - camera_android: ^0.10.9 + camera_android_camerax: ^0.6.5 camera_avfoundation: ^0.9.15 camera_platform_interface: ^2.6.0 camera_web: ^0.3.3 diff --git a/packages/camera/camera_android/CHANGELOG.md b/packages/camera/camera_android/CHANGELOG.md index 66cd2dc329ef..9e915b751d65 100644 --- a/packages/camera/camera_android/CHANGELOG.md +++ b/packages/camera/camera_android/CHANGELOG.md @@ -1,3 +1,8 @@ +## 0.10.9+2 + +* Updates `README.md` to reflect the fact that the `camera_android_camerax` camera plugin implementation + is the endorsed Android implementation for `camera: ^0.11.0`. + ## 0.10.9+1 * Changes the visibility of a number of fields to `@VisibleForTesting` in order simplify testing. diff --git a/packages/camera/camera_android/README.md b/packages/camera/camera_android/README.md index 31f2d66ae4e4..486db6743284 100644 --- a/packages/camera/camera_android/README.md +++ b/packages/camera/camera_android/README.md @@ -1,24 +1,23 @@ # camera\_android -The Android implementation of [`camera`][1]. - -*Note*: [`camera_android_camerax`][3] will become the default implementation of -`camera` on Android by May 2024, so **we strongly encourage you to opt into it** -by using [these instructions][4]. If any [limitations][5] of `camera_android_camerax` -prevent you from using it or if you run into any problems, please report these -issues under [`flutter/flutter`][5] with `[camerax]` in the title. +An Android implementation of [`camera`][1] built with the [Camera2 library][4]. ## Usage -This package is [endorsed][2], which means you can simply use `camera` -normally. This package will be automatically included in your app when you do, -so you do not need to add it to your `pubspec.yaml`. +As of `camera: ^0.11.0`, to use this plugin instead of [`camera_android_camerax`][3], +run + +```sh +$ flutter pub add camera_android +``` -However, if you `import` this package to use any of its APIs directly, you -should add it to your `pubspec.yaml` as usual. +## Limitation of testing video recording on emulators +`MediaRecorder` does not work properly on emulators, as stated in [the documentation][5]. Specifically, +when recording a video with sound enabled and trying to play it back, the duration won't be correct and +you will only see the first frame. [1]: https://pub.dev/packages/camera [2]: https://flutter.dev/docs/development/packages-and-plugins/developing-packages#endorsed-federated-plugin [3]: https://pub.dev/packages/camera_android_camerax -[4]: https://pub.dev/packages/camera_android_camerax#usage -[5]: https://pub.dev/packages/camera_android_camerax#limitations +[4]: https://developer.android.com/media/camera/camera2 +[5]: https://developer.android.com/reference/android/media/MediaRecorder diff --git a/packages/camera/camera_android/pubspec.yaml b/packages/camera/camera_android/pubspec.yaml index 06958bbd322a..1edc7e14908c 100644 --- a/packages/camera/camera_android/pubspec.yaml +++ b/packages/camera/camera_android/pubspec.yaml @@ -3,7 +3,7 @@ description: Android implementation of the camera plugin. repository: https://github.com/flutter/packages/tree/main/packages/camera/camera_android issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+camera%22 -version: 0.10.9+1 +version: 0.10.9+2 environment: sdk: ^3.1.0 diff --git a/packages/camera/camera_android_camerax/CHANGELOG.md b/packages/camera/camera_android_camerax/CHANGELOG.md index cfc8400a712f..f26d83f17594 100644 --- a/packages/camera/camera_android_camerax/CHANGELOG.md +++ b/packages/camera/camera_android_camerax/CHANGELOG.md @@ -1,3 +1,8 @@ +## 0.6.5+1 + +* Updates `README.md` to reflect the fact that the `camera_android_camerax` camera plugin implementation + is the endorsed Android implementation for `camera: ^0.11.0`. + ## 0.6.5 * Modifies `stopVideoRecording` to ensure that the method only returns when CameraX reports that the diff --git a/packages/camera/camera_android_camerax/README.md b/packages/camera/camera_android_camerax/README.md index d68537ef1607..795118d83f38 100644 --- a/packages/camera/camera_android_camerax/README.md +++ b/packages/camera/camera_android_camerax/README.md @@ -1,23 +1,20 @@ # camera\_android\_camerax -An Android implementation of [`camera`][1] that uses the [CameraX library][2]. +The Android implementation of [`camera`][1] built with the [CameraX library][2]. -*Note*: This implementation will become the default implementation of `camera` -on Android by May 2024, so **we strongly encourage you to opt into it** -by using [the instructions](#usage) below. If any of [the limitations](#limitations) -prevent you from using `camera_android_camerax` or if you run into any problems, -please report these issues under [`flutter/flutter`][5] with `[camerax]` in -the title. +*Note*: If any of [the limitations](#limitations) prevent you from using +using `camera_android_camerax` or if you run into any problems, please report +report these issues under [`flutter/flutter`][5] with `[camerax]` in the title. +You may also opt back into the [`camera_android`][9] implementation if you need. ## Usage -To use this plugin instead of [`camera_android`][4], run +As of `camera: ^0.11.0`, this package is [endorsed][3], which means you can +simply use `camera` normally. This package will be automatically be included +in your app when you do, so you do not need to add it to your `pubspec.yaml`. -```sh -$ flutter pub add camera_android_camerax -``` - -from your project's root directory. +However, if you `import` this package to use any of its APIs directly, you +should add it to your `pubspec.yaml` as usual. ## Limitations @@ -43,9 +40,9 @@ due to this not currently being supported by CameraX. ### 240p resolution configuration for video recording -240p resolution configuration for video recording is unsupported by CameraX, -and thus, the plugin will fall back to 480p if configured with a -`ResolutionPreset`. +240p resolution configuration for video recording is unsupported by CameraX, and thus, +the plugin will fall back to target 480p (`ResolutionPreset.medium`) if configured with +`ResolutionPreset.low`. ### Setting maximum duration and stream options for video capture @@ -62,10 +59,11 @@ For more information on contributing to this plugin, see [`CONTRIBUTING.md`](CON [1]: https://pub.dev/packages/camera [2]: https://developer.android.com/training/camerax -[3]: https://docs.flutter.dev/packages-and-plugins/developing-packages#non-endorsed-federated-plugin +[3]: https://flutter.dev/docs/development/packages-and-plugins/developing-packages#endorsed-federated-plugin [4]: https://pub.dev/packages/camera_android [5]: https://github.com/flutter/flutter/issues/new/choose [6]: https://developer.android.com/media/camera/camerax/architecture#combine-use-cases [7]: https://developer.android.com/reference/android/hardware/camera2/CameraMetadata#INFO_SUPPORTED_HARDWARE_LEVEL_3 [8]: https://developer.android.com/reference/android/hardware/camera2/CameraMetadata#INFO_SUPPORTED_HARDWARE_LEVEL_LIMITED +[9]: https://pub.dev/packages/camera_android#usage [148013]: https://github.com/flutter/flutter/issues/148013 diff --git a/packages/camera/camera_android_camerax/pubspec.yaml b/packages/camera/camera_android_camerax/pubspec.yaml index 9d4191b98b2e..fec57ac97194 100644 --- a/packages/camera/camera_android_camerax/pubspec.yaml +++ b/packages/camera/camera_android_camerax/pubspec.yaml @@ -2,7 +2,7 @@ name: camera_android_camerax description: Android implementation of the camera plugin using the CameraX library. repository: https://github.com/flutter/packages/tree/main/packages/camera/camera_android_camerax issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+camera%22 -version: 0.6.5 +version: 0.6.5+1 environment: sdk: ^3.1.0