Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

fix android crash when pausing or resuming video on APIs lower than 24. #2029

Merged
merged 1 commit into from
Aug 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/camera/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.5.4+1

* Fix Android pause and resume video crash when executing in APIs below 24.

## 0.5.4

* Add feature to pause and resume video recording.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import android.media.Image;
import android.media.ImageReader;
import android.media.MediaRecorder;
import android.os.Build;
import android.util.Size;
import android.view.OrientationEventListener;
import android.view.Surface;
Expand Down Expand Up @@ -395,7 +396,12 @@ public void pauseVideoRecording(@NonNull final Result result) {
}

try {
mediaRecorder.pause();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
mediaRecorder.pause();
} else {
result.error("videoRecordingFailed", "pauseVideoRecording requires Android API +24.", null);
return;
}
} catch (IllegalStateException e) {
result.error("videoRecordingFailed", e.getMessage(), null);
return;
Expand All @@ -411,7 +417,13 @@ public void resumeVideoRecording(@NonNull final Result result) {
}

try {
mediaRecorder.resume();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
mediaRecorder.resume();
} else {
result.error(
"videoRecordingFailed", "resumeVideoRecording requires Android API +24.", null);
return;
}
} catch (IllegalStateException e) {
result.error("videoRecordingFailed", e.getMessage(), null);
return;
Expand Down
5 changes: 3 additions & 2 deletions packages/camera/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ class _CameraExampleHomeState extends State<CameraExampleHome>
await controller.pauseVideoRecording();
} on CameraException catch (e) {
_showCameraException(e);
return null;
rethrow;
}
}

Expand All @@ -406,7 +406,7 @@ class _CameraExampleHomeState extends State<CameraExampleHome>
await controller.resumeVideoRecording();
} on CameraException catch (e) {
_showCameraException(e);
return null;
rethrow;
}
}

Expand Down Expand Up @@ -477,6 +477,7 @@ List<CameraDescription> cameras;
Future<void> main() async {
// Fetch the available cameras before initializing the app.
try {
WidgetsFlutterBinding.ensureInitialized();
cameras = await availableCameras();
} on CameraException catch (e) {
logError(e.code, e.description);
Expand Down
2 changes: 1 addition & 1 deletion packages/camera/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: camera
description: A Flutter plugin for getting information about and controlling the
camera on Android and iOS. Supports previewing the camera feed, capturing images, capturing video,
and streaming image buffers to dart.
version: 0.5.4
version: 0.5.4+1

authors:
- Flutter Team <flutter-dev@googlegroups.com>
Expand Down