Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
2971c85
Pause/resume video recording for Android
huulbaek Mar 21, 2019
3e87cac
Specify type
bparrishMines Aug 1, 2019
d99f9d0
Merge branch 'master' of github.com:flutter/plugins into huulbaek/pau…
bparrishMines Aug 1, 2019
474604d
Merge branch 'master' of github.com:flutter/plugins into huulbaek/pau…
bparrishMines Aug 5, 2019
423adcd
Add pausing and resuming to example app
bparrishMines Aug 6, 2019
0214093
iOS side of pausing/resuming
bparrishMines Aug 6, 2019
7216d4a
Merge branch 'master' of github.com:flutter/plugins into huulbaek/pau…
bparrishMines Aug 7, 2019
113cd55
More documentation
bparrishMines Aug 7, 2019
5664547
Version bump
bparrishMines Aug 7, 2019
9210c26
Merge branch 'master' of github.com:flutter/plugins into huulbaek/pau…
bparrishMines Aug 12, 2019
3f47c60
Add video pausing and resuming
bparrishMines Aug 14, 2019
5baee78
get pausing and recording to work for no audio
bparrishMines Aug 15, 2019
da26df1
It works
bparrishMines Aug 16, 2019
b56d1fb
Merge branch 'pauseresume' of github.com:huulbaek/plugins into huulba…
bparrishMines Aug 16, 2019
542ee3d
Formatting
bparrishMines Aug 16, 2019
5023773
Add test for pausing and resuming
bparrishMines Aug 19, 2019
6dbbf8d
Merge branch 'master' into pauseresume
bparrishMines Aug 19, 2019
ca47f38
Call success outside try catch block
bparrishMines Aug 19, 2019
c758b26
formatting
bparrishMines Aug 19, 2019
70e1b13
Merge branch 'pauseresume' of github.com:huulbaek/plugins into huulba…
bparrishMines Aug 19, 2019
8ff306f
Disable audio in test and call result on iOS
bparrishMines Aug 19, 2019
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
Prev Previous commit
Next Next commit
Add pausing and resuming to example app
  • Loading branch information
bparrishMines committed Aug 6, 2019
commit 423adcd7f3999c075866cefed4c15e8ac54f83fc
53 changes: 53 additions & 0 deletions packages/camera/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,19 @@ class _CameraExampleHomeState extends State<CameraExampleHome>
? onVideoRecordButtonPressed
: null,
),
IconButton(
icon: controller != null && controller.value.isRecordingPaused
? Icon(Icons.play_arrow)
: Icon(Icons.pause),
color: Colors.blue,
onPressed: controller != null &&
controller.value.isInitialized &&
controller.value.isRecordingVideo
? (controller != null && controller.value.isRecordingPaused
? onResumeButtonPressed
: onPauseButtonPressed)
: null,
),
IconButton(
icon: const Icon(Icons.stop),
color: Colors.red,
Expand Down Expand Up @@ -308,6 +321,20 @@ class _CameraExampleHomeState extends State<CameraExampleHome>
});
}

void onPauseButtonPressed() {
pauseVideoRecording().then((_) {
if (mounted) setState(() {});
showInSnackBar('Video recording paused');
});
}

void onResumeButtonPressed() {
resumeVideoRecording().then((_) {
if (mounted) setState(() {});
showInSnackBar('Video recording resumed');
});
}

Future<String> startVideoRecording() async {
if (!controller.value.isInitialized) {
showInSnackBar('Error: select a camera first.');
Expand Down Expand Up @@ -349,6 +376,32 @@ class _CameraExampleHomeState extends State<CameraExampleHome>
await _startVideoPlayer();
}

Future<void> pauseVideoRecording() async {
if (!controller.value.isRecordingVideo) {
return null;
}

try {
await controller.pauseVideoRecording();
} on CameraException catch (e) {
_showCameraException(e);
return null;
}
}

Future<void> resumeVideoRecording() async {
if (!controller.value.isRecordingVideo) {
return null;
}

try {
await controller.resumeVideoRecording();
} on CameraException catch (e) {
_showCameraException(e);
return null;
}
}

Future<void> _startVideoPlayer() async {
final VideoPlayerController vcontroller =
VideoPlayerController.file(File(videoPath));
Expand Down
36 changes: 20 additions & 16 deletions packages/camera/lib/camera.dart
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,17 @@ class CameraValue {
this.isRecordingVideo,
this.isTakingPicture,
this.isStreamingImages,
});
bool isRecordingPaused,
}) : _isRecordingPaused = isRecordingPaused;

const CameraValue.uninitialized()
: this(
isInitialized: false,
isRecordingVideo: false,
isTakingPicture: false,
isStreamingImages: false);
isInitialized: false,
isRecordingVideo: false,
isTakingPicture: false,
isStreamingImages: false,
isRecordingPaused: false,
);

/// True after [CameraController.initialize] has completed successfully.
final bool isInitialized;
Expand All @@ -151,6 +154,11 @@ class CameraValue {
/// True when images from the camera are being streamed.
final bool isStreamingImages;

final bool _isRecordingPaused;

/// True when camera [isRecordingVideo] and recording is paused.
bool get isRecordingPaused => isRecordingVideo && _isRecordingPaused;

final String errorDescription;

/// The size of the preview in pixels.
Expand All @@ -172,6 +180,7 @@ class CameraValue {
bool isStreamingImages,
String errorDescription,
Size previewSize,
bool isRecordingPaused,
}) {
return CameraValue(
isInitialized: isInitialized ?? this.isInitialized,
Expand All @@ -180,6 +189,7 @@ class CameraValue {
isRecordingVideo: isRecordingVideo ?? this.isRecordingVideo,
isTakingPicture: isTakingPicture ?? this.isTakingPicture,
isStreamingImages: isStreamingImages ?? this.isStreamingImages,
isRecordingPaused: isRecordingPaused ?? _isRecordingPaused,
);
}

Expand Down Expand Up @@ -446,7 +456,7 @@ class CameraController extends ValueNotifier<CameraValue> {
'startVideoRecording',
<String, dynamic>{'textureId': _textureId, 'filePath': filePath},
);
value = value.copyWith(isRecordingVideo: true);
value = value.copyWith(isRecordingVideo: true, isRecordingPaused: false);
} on PlatformException catch (e) {
throw CameraException(e.code, e.message);
}
Expand Down Expand Up @@ -492,11 +502,8 @@ class CameraController extends ValueNotifier<CameraValue> {
);
}
try {
// value = value.copyWith(isRecordingVideo: false);
// TODO(amirh): remove this on when the invokeMethod update makes it to stable Flutter.
// https://github.com/flutter/flutter/issues/26431
// ignore: strong_mode_implicit_dynamic_method
await _channel.invokeMethod(
value = value.copyWith(isRecordingPaused: true);
await _channel.invokeMethod<void>(
'pauseVideoRecording',
<String, dynamic>{'textureId': _textureId},
);
Expand All @@ -520,11 +527,8 @@ class CameraController extends ValueNotifier<CameraValue> {
);
}
try {
// value = value.copyWith(isRecordingVideo: false);
// TODO(amirh): remove this on when the invokeMethod update makes it to stable Flutter.
// https://github.com/flutter/flutter/issues/26431
// ignore: strong_mode_implicit_dynamic_method
await _channel.invokeMethod(
value = value.copyWith(isRecordingPaused: false);
await _channel.invokeMethod<void>(
'resumeVideoRecording',
<String, dynamic>{'textureId': _textureId},
);
Expand Down