-
Notifications
You must be signed in to change notification settings - Fork 0
/
video_config.dart
363 lines (299 loc) · 9.71 KB
/
video_config.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'controls/news/news_controls.dart';
import 'controls/normal/normal_controls.dart';
import 'video_view.dart';
/// @Describe: The config of VideoView.
///
/// @Author: LiWeNHuI
/// @Date: 2023/3/1
/// Types of controls.
enum ControlsType {
/// Universal
normal,
/// News
news,
}
/// Extension of [ControlsType].
extension ControlsTypeExtension on ControlsType {
/// Widget
Widget get child =>
<Widget>[const NormalControls(), const NewsControls()].elementAt(index);
}
/// Widgets in various initialized states.
typedef PlaceholderBuilder = Widget? Function(VideoValue value);
/// Play button in the middle.
typedef CenterPlayButtonBuilder = Widget Function(VoidCallback onPlayOrPause);
/// Widgets on the middle left.
typedef CenterActionsBuilder = List<Widget> Function(
BuildContext context,
bool isFullScreen,
bool isLock,
Widget lockButton,
);
/// It is used to define the control buttons at the bottom and the layout of
/// the display content.
typedef BottomBuilder = Widget? Function(
BuildContext context,
bool isFullScreen,
Widget playPauseButton,
Widget progressBar,
Widget muteButton,
Widget speedButton,
Widget fullScreenButton,
);
/// Different widgets are displayed depending on whether they are full screen or
/// not.
typedef FullScreenBuilder<T> = T Function(
BuildContext context,
bool isFullScreen,
);
/// The config of VideoView.
class VideoConfig {
/// Overall configuration for the video view. Including [width], [height],
/// [useSafe], [backgroundColor] etc.
VideoConfig({
this.width,
this.height,
this.backgroundColor = Colors.black,
this.tooltipBackgroundColor = Colors.black54,
this.foregroundColor = Colors.white,
this.textSize = 14,
this.iconSize = 16,
this.useSafe = true,
this.maxScale = 2.5,
this.minScale = 0.8,
this.panEnabled = false,
this.scaleEnabled = false,
this.aspectRatio,
this.allowedScreenSleep = true,
this.autoInitialize = false,
this.autoPlay = false,
this.startAt,
this.volume = 1.0,
this.looping = false,
this.overlay,
this.placeholderBuilder,
this.fullScreenByDefault = false,
this.useRootNavigator = true,
this.deviceOrientationsEnterFullScreen,
this.systemOverlaysExitFullScreen = SystemUiOverlay.values,
this.deviceOrientationsExitFullScreen = DeviceOrientation.values,
this.showControlsOnInitialize = true,
this.showControls,
this.hideControlsTimer = const Duration(seconds: 3),
this.controlsType = ControlsType.normal,
this.showBuffering = true,
this.bufferingBuilder,
this.finishBuilder,
this.controlsBackgroundColor = const <Color>[
Color.fromRGBO(0, 0, 0, .7),
Color.fromRGBO(0, 0, 0, .3),
Color.fromRGBO(0, 0, 0, 0),
],
this.showCenterPlay = true,
this.centerPlayButtonBuilder,
this.canLongPress = true,
this.canChangeVolumeOrBrightness = true,
this.canChangeProgress = true,
this.canBack = true,
this.title,
this.titleTextStyle,
this.topActionsBuilder,
this.showLock = false,
this.centerLeftActionsBuilder,
this.centerRightActionsBuilder,
this.bottomBuilder,
this.onTextPosition,
this.onProgressBarGap,
this.videoProgressBarColors,
this.maxPreviewTime,
this.maxPreviewTimeBuilder,
}) : assert(
maxScale > 0,
'The maxScale must be greater than zero and greater than minScale.',
),
assert(
minScale > 0,
'The minScale must be a finite number greater than zero and less '
'than maxScale.',
),
assert(
!hideControlsTimer.isNegative,
'The duration of the controller disappear must be greater than zero.',
);
/// The width of video.
final double? width;
/// The height of video.
final double? height;
/// The background color of video.
///
/// Defaults to black.
final Color backgroundColor;
/// The background color of a widget that displays information about volume,
/// brightness, speed, playback progress, and so on.
///
/// Defaults to black54.
final Color tooltipBackgroundColor;
/// The color for the video's Button` and `Text` widget descendants.
///
/// Defaults to white.
final Color foregroundColor;
/// Size of all texts.
///
/// Defaults to 14.
final double textSize;
/// Size of all icons.
///
/// Defaults to 16.
final double iconSize;
/// Whether to maintain a safe distance from the top.
///
/// Defaults to true.
final bool useSafe;
/// The maximum allowed scale.
///
/// Defaults to 2.5.
final double maxScale;
/// The minimum allowed scale.
///
/// Defaults to 0.8.
final double minScale;
/// Whether or not to allow panning.
///
/// Defaults to false.
final bool panEnabled;
/// Whether or not to allow zooming.
///
/// Defaults to false.
final bool scaleEnabled;
/// The Aspect Ratio of the Video.
final double? aspectRatio;
/// Defines if the player will sleep in fullscreen or not.
///
/// Defaults to true.
final bool allowedScreenSleep;
/// Initialize the Video on Startup. This will prep the video for playback.
///
/// Defaults to false.
final bool autoInitialize;
/// Play the video as soon as it's displayed.
///
/// Defaults to false.
final bool autoPlay;
/// Where does the video start playing when it first plays.
///
/// Defaults to zero.
final Duration? startAt;
/// The volume of the video, not the device volume.
final double volume;
/// Whether the video is looped.
///
/// Defaults to false.
final bool looping;
/// A widget which is placed between the video and the controls.
final PlaceholderBuilder? overlay;
/// Widgets in various initialized states.
final PlaceholderBuilder? placeholderBuilder;
/// Whether to play full screen when auto play is enabled.
/// Valid only if [autoPlay] is true.
///
/// Defaults to false.
final bool fullScreenByDefault;
/// Defines if push/pop navigations use the rootNavigator.
///
/// Defaults to true.
final bool useRootNavigator;
/// Defines the set of allowed device orientations on entering fullscreen.
final List<DeviceOrientation>? deviceOrientationsEnterFullScreen;
/// Defines the system overlays visible after exiting fullscreen.
final List<SystemUiOverlay> systemOverlaysExitFullScreen;
/// Defines the set of allowed device orientations after exiting fullscreen.
final List<DeviceOrientation> deviceOrientationsExitFullScreen;
/// Whether controls are displayed when initializing the widget.
///
/// Defaults to true.
final bool showControlsOnInitialize;
/// Whether to display controls.
///
/// Defaults to true.
final FullScreenBuilder<bool>? showControls;
/// Defines the [Duration] before the video controls are hidden.
///
/// Defaults to three seconds.
final Duration hideControlsTimer;
/// Types of controls.
final ControlsType controlsType;
/// Whether to show placeholders in the buffer.
///
/// Defaults to true.
final bool showBuffering;
/// Widget to display when buffered is overlaid above the video.
final Widget? bufferingBuilder;
/// Widget to display when video playback is complete.
final FullScreenBuilder<Widget>? finishBuilder;
/// The background color of the controller.
final List<Color> controlsBackgroundColor;
/// Whether to show the play button in the middle.
///
/// Defaults to true.
final bool showCenterPlay;
/// Play button in the middle.
final CenterPlayButtonBuilder? centerPlayButtonBuilder;
/// Whether the video can be played at double speed by long pressing.
///
/// Defaults to true.
final bool canLongPress;
/// Whether the volume or brightness can be adjusted.
///
/// Defaults to true.
final bool canChangeVolumeOrBrightness;
/// Whether the video progress can be adjusted.
///
/// Defaults to true.
final bool canChangeProgress;
/// Whether to show [BackButton].
///
/// Defaults to true.
final bool canBack;
/// The title of video.
final String? title;
/// The textStyle of [title].
final TextStyle? titleTextStyle;
/// Widgets placed at the top right.
final FullScreenBuilder<List<Widget>>? topActionsBuilder;
/// Whether the lockable button is displayed.
final bool showLock;
/// Widgets on the middle left.
///
/// `lockButton` is the lockable button, which is used to decide where put it.
final CenterActionsBuilder? centerLeftActionsBuilder;
/// Widgets on the middle right.
///
/// `lockButton` is the lockable button, which is used to decide where put it.
final CenterActionsBuilder? centerRightActionsBuilder;
/// It is used to define the control buttons at the bottom and the layout of
/// the display content.
final BottomBuilder? bottomBuilder;
/// Enumeration value where the progress information is located on
/// the progress bar.
///
/// Defaults to TextPosition.ltl.
final FullScreenBuilder<VideoTextPosition>? onTextPosition;
/// The interval width of the progress bar and time information widget.
final FullScreenBuilder<double>? onProgressBarGap;
/// The default colors used throughout the indicator.
///
/// See [VideoProgressBarColors] for default values.
final VideoProgressBarColors? videoProgressBarColors;
/// Maximum preview duration.
///
/// If the set duration exceeds the maximum duration of the video,
/// it is deemed that the entire video can be watched.
final Duration? maxPreviewTime;
/// The widget displayed when the maximum preview duration is reached.
final FullScreenBuilder<Widget>? maxPreviewTimeBuilder;
/// The style of all text.
TextStyle get defaultStyle =>
TextStyle(fontSize: textSize, color: foregroundColor);
}