Skip to content

Commit d4bbc33

Browse files
authored
shouldAutoPreviewVideo (#59)
1 parent e62dd3b commit d4bbc33

File tree

4 files changed

+29
-2
lines changed

4 files changed

+29
-2
lines changed

README-ZH.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ Flutter SDK:`>=2.0.0` 。
6969
| enablePinchToZoom | `bool` | 用户是否可以在界面上双指缩放相机对焦 | `true` |
7070
| enablePullToZoomInRecord | `bool` | 用户是否可以在录制视频时上拉缩放 | `true` |
7171
| shouldDeletePreviewFile | `bool` | 返回页面时是否删除预览文件 | `false` |
72+
| shouldAutoPreviewVideo | `bool` | 在预览时是否直接播放视频 | `false` |
7273
| maximumRecordingDuration | `Duration` | 录制视频最长时长 | `const Duration(seconds: 15)` |
7374
| theme | `ThemeData?` | 选择器的主题 | `CameraPicker.themeData(C.themeColor)` |
7475
| textDelegate | `CameraPickerTextDelegate?` | 控制部件中的文字实现 | `DefaultCameraPickerTextDelegate` |

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ Flutter SDK: `>=2.0.0` .
7070
| enablePinchToZoom | `bool` | Whether users can zoom the camera by pinch. | `true` |
7171
| enablePullToZoomInRecord | `bool` | Whether users can zoom by pulling up when recording video. | `true` |
7272
| shouldDeletePreviewFile | `bool` | Whether the preview file will be delete when pop. | `false` |
73+
| shouldAutoPreviewVideo | `bool` | Whether the video should be played instantly in the preview. | `false` |
7374
| maximumRecordingDuration | `Duration` | The maximum duration of the video recording process. | `const Duration(seconds: 15)` |
7475
| theme | `ThemeData?` | Theme data for the picker. | `CameraPicker.themeData(C.themeColor)` |
7576
| textDelegate | `CameraPickerTextDelegate?` | Text delegate that controls text in widgets. | `DefaultCameraPickerTextDelegate` |

lib/src/widgets/camera_picker.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class CameraPicker extends StatefulWidget {
4343
this.enablePinchToZoom = true,
4444
this.enablePullToZoomInRecord = true,
4545
this.shouldDeletePreviewFile = false,
46+
this.shouldAutoPreviewVideo = false,
4647
this.maximumRecordingDuration = const Duration(seconds: 15),
4748
this.theme,
4849
this.resolutionPreset = ResolutionPreset.max,
@@ -113,10 +114,18 @@ class CameraPicker extends StatefulWidget {
113114
/// 用户是否可以在录制视频时上拉缩放
114115
final bool enablePullToZoomInRecord;
115116

117+
/// {@template wechat_camera_picker.shouldDeletePreviewFile}
116118
/// Whether the preview file will be delete when pop.
117119
/// 返回页面时是否删除预览文件
120+
/// {@endtemplate}
118121
final bool shouldDeletePreviewFile;
119122

123+
/// {@template wechat_camera_picker.shouldAutoPreviewVideo}
124+
/// Whether the video should be played instantly in the preview.
125+
/// 在预览时是否直接播放视频
126+
/// {@endtemplate}
127+
final bool shouldAutoPreviewVideo;
128+
120129
/// The maximum duration of the video recording process.
121130
/// 录制视频最长时长
122131
///
@@ -164,6 +173,7 @@ class CameraPicker extends StatefulWidget {
164173
bool enablePinchToZoom = true,
165174
bool enablePullToZoomInRecord = true,
166175
bool shouldDeletePreviewFile = false,
176+
bool shouldAutoPreviewVideo = false,
167177
Duration maximumRecordingDuration = const Duration(seconds: 15),
168178
ThemeData? theme,
169179
int cameraQuarterTurns = 0,
@@ -194,6 +204,7 @@ class CameraPicker extends StatefulWidget {
194204
enablePinchToZoom: enablePinchToZoom,
195205
enablePullToZoomInRecord: enablePullToZoomInRecord,
196206
shouldDeletePreviewFile: shouldDeletePreviewFile,
207+
shouldAutoPreviewVideo: shouldAutoPreviewVideo,
197208
maximumRecordingDuration: maximumRecordingDuration,
198209
theme: theme,
199210
cameraQuarterTurns: cameraQuarterTurns,
@@ -386,6 +397,8 @@ class CameraPickerState extends State<CameraPicker>
386397

387398
bool get shouldDeletePreviewFile => widget.shouldDeletePreviewFile;
388399

400+
bool get shouldAutoPreviewVideo => widget.shouldAutoPreviewVideo;
401+
389402
Duration? get maximumRecordingDuration => widget.maximumRecordingDuration;
390403

391404
/// Whether the recording restricted to a specific duration.
@@ -769,6 +782,7 @@ class CameraPickerState extends State<CameraPicker>
769782
previewXFile: _file,
770783
theme: theme,
771784
shouldDeletePreviewFile: shouldDeletePreviewFile,
785+
shouldAutoPreviewVideo: shouldAutoPreviewVideo,
772786
onEntitySaving: widget.onEntitySaving,
773787
);
774788
if (entity != null) {
@@ -862,6 +876,7 @@ class CameraPickerState extends State<CameraPicker>
862876
previewXFile: file,
863877
theme: theme,
864878
shouldDeletePreviewFile: shouldDeletePreviewFile,
879+
shouldAutoPreviewVideo: shouldAutoPreviewVideo,
865880
);
866881
if (entity != null) {
867882
Navigator.of(context).pop(entity);

lib/src/widgets/camera_picker_viewer.dart

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class CameraPickerViewer extends StatefulWidget {
2727
required this.previewXFile,
2828
required this.theme,
2929
this.shouldDeletePreviewFile = false,
30+
this.shouldAutoPreviewVideo = false,
3031
this.onEntitySaving,
3132
this.onError,
3233
}) : super(key: key);
@@ -47,10 +48,12 @@ class CameraPickerViewer extends StatefulWidget {
4748
/// 选择器使用的主题
4849
final ThemeData theme;
4950

50-
/// Whether the preview file will be delete when pop.
51-
/// 返回页面时是否删除预览文件
51+
/// {@macro wechat_camera_picker.shouldDeletePreviewFile}
5252
final bool shouldDeletePreviewFile;
5353

54+
/// {@macro wechat_camera_picker.shouldAutoPreviewVideo}
55+
final bool shouldAutoPreviewVideo;
56+
5457
/// {@macro wechat_camera_picker.EntitySaveCallback}
5558
final EntitySaveCallback? onEntitySaving;
5659

@@ -66,6 +69,7 @@ class CameraPickerViewer extends StatefulWidget {
6669
required XFile previewXFile,
6770
required ThemeData theme,
6871
bool shouldDeletePreviewFile = false,
72+
bool shouldAutoPreviewVideo = false,
6973
EntitySaveCallback? onEntitySaving,
7074
CameraErrorHandler? onError,
7175
}) {
@@ -77,6 +81,7 @@ class CameraPickerViewer extends StatefulWidget {
7781
previewXFile: previewXFile,
7882
theme: theme,
7983
shouldDeletePreviewFile: shouldDeletePreviewFile,
84+
shouldAutoPreviewVideo: shouldAutoPreviewVideo,
8085
onEntitySaving: onEntitySaving,
8186
onError: onError,
8287
),
@@ -132,6 +137,8 @@ class _CameraPickerViewerState extends State<CameraPickerViewer> {
132137

133138
bool get shouldDeletePreviewFile => widget.shouldDeletePreviewFile;
134139

140+
bool get shouldAutoPreviewVideo => widget.shouldAutoPreviewVideo;
141+
135142
@override
136143
void initState() {
137144
super.initState();
@@ -158,6 +165,9 @@ class _CameraPickerViewerState extends State<CameraPickerViewer> {
158165
await videoController.initialize();
159166
videoController.addListener(videoPlayerListener);
160167
hasLoaded = true;
168+
if (shouldAutoPreviewVideo) {
169+
videoController.play();
170+
}
161171
} catch (e) {
162172
hasErrorWhenInitializing = true;
163173
realDebugPrint('Error when initializing video controller: $e');

0 commit comments

Comments
 (0)