Skip to content

Commit 4f335a5

Browse files
committed
Merge commit 'c7665a379343679beba9d480a8989df6f2e0499c' into github/custom-lg
* commit 'c7665a379343679beba9d480a8989df6f2e0499c': chewie, version 1.8.5. Addresses Issue fluttercommunity#615. Fixed a stray lint issue due to recent PR. chore: pass draggableProgressBar from chewieController. chore: make progress bar independent on chewie controller. chore: add barHeight and handleHeight properties. chore: export MaterialVideoProgressBar widget. Adding Material Seek Control button size and fade duration config Adding Seek buttons for Android
2 parents 981cd13 + c7665a3 commit 4f335a5

11 files changed

+163
-13
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## [1.8.5]
2+
* ⬆️ [#703](https://github.com/fluttercommunity/chewie/pull/703): Adding Seek buttons for Android. Thanks [GyanendroKh](https://github.com/GyanendroKh).
3+
* Upgraded `wakelock_plus` to version `1.2.8`, which uses `web` version `1.0.0`. Thanks [diegotori](https://github.com/diegotori).
4+
15
## [1.8.4]
26
* 🛠️ [#838](https://github.com/fluttercommunity/chewie/pull/838): Add bufferingBuilder. Thanks [daniellampl](https://github.com/daniellampl).
37

lib/chewie.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ export 'src/chewie_player.dart';
44
export 'src/chewie_progress_colors.dart';
55
export 'src/cupertino/cupertino_controls.dart';
66
export 'src/material/material_controls.dart';
7+
export 'src/material/material_progress_bar.dart';
78
export 'src/material/material_desktop_controls.dart';
89
export 'src/models/index.dart';

lib/src/center_seek_button.dart

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import 'package:flutter/material.dart';
2+
3+
class CenterSeekButton extends StatelessWidget {
4+
const CenterSeekButton({
5+
super.key,
6+
required this.iconData,
7+
required this.backgroundColor,
8+
this.iconColor,
9+
required this.show,
10+
this.fadeDuration = const Duration(milliseconds: 300),
11+
this.iconSize = 26,
12+
this.onPressed,
13+
});
14+
15+
final IconData iconData;
16+
final Color backgroundColor;
17+
final Color? iconColor;
18+
final bool show;
19+
final VoidCallback? onPressed;
20+
final Duration fadeDuration;
21+
final double iconSize;
22+
23+
@override
24+
Widget build(BuildContext context) {
25+
return ColoredBox(
26+
color: Colors.transparent,
27+
child: Center(
28+
child: UnconstrainedBox(
29+
child: AnimatedOpacity(
30+
opacity: show ? 1.0 : 0.0,
31+
duration: fadeDuration,
32+
child: DecoratedBox(
33+
decoration: BoxDecoration(
34+
color: backgroundColor,
35+
shape: BoxShape.circle,
36+
),
37+
// Always set the iconSize on the IconButton, not on the Icon itself:
38+
// https://github.com/flutter/flutter/issues/52980
39+
child: IconButton(
40+
iconSize: iconSize,
41+
padding: const EdgeInsets.all(8.0),
42+
icon: Icon(iconData, color: iconColor),
43+
onPressed: onPressed,
44+
),
45+
),
46+
),
47+
),
48+
),
49+
);
50+
}
51+
}

lib/src/chewie_player.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,8 @@ class ChewieController extends ChangeNotifier {
289289
this.fullScreenByDefault = false,
290290
this.cupertinoProgressColors,
291291
this.materialProgressColors,
292+
this.materialSeekButtonFadeDuration = const Duration(milliseconds: 300),
293+
this.materialSeekButtonSize = 26,
292294
this.placeholder,
293295
this.overlay,
294296
this.showControlsOnInitialize = true,
@@ -338,6 +340,8 @@ class ChewieController extends ChangeNotifier {
338340
bool? fullScreenByDefault,
339341
ChewieProgressColors? cupertinoProgressColors,
340342
ChewieProgressColors? materialProgressColors,
343+
Duration? materialSeekButtonFadeDuration,
344+
double? materialSeekButtonSize,
341345
Widget? placeholder,
342346
Widget? overlay,
343347
bool? showControlsOnInitialize,
@@ -390,6 +394,10 @@ class ChewieController extends ChangeNotifier {
390394
cupertinoProgressColors ?? this.cupertinoProgressColors,
391395
materialProgressColors:
392396
materialProgressColors ?? this.materialProgressColors,
397+
materialSeekButtonFadeDuration:
398+
materialSeekButtonFadeDuration ?? this.materialSeekButtonFadeDuration,
399+
materialSeekButtonSize:
400+
materialSeekButtonSize ?? this.materialSeekButtonSize,
393401
placeholder: placeholder ?? this.placeholder,
394402
overlay: overlay ?? this.overlay,
395403
showControlsOnInitialize:
@@ -520,6 +528,12 @@ class ChewieController extends ChangeNotifier {
520528
/// player uses the colors from your Theme.
521529
final ChewieProgressColors? materialProgressColors;
522530

531+
// The duration of the fade animation for the seek button (Material Player only)
532+
final Duration materialSeekButtonFadeDuration;
533+
534+
// The size of the seek button for the Material Player only
535+
final double materialSeekButtonSize;
536+
523537
/// The placeholder is displayed underneath the Video before it is initialized
524538
/// or played.
525539
final Widget? placeholder;

lib/src/cupertino/cupertino_controls.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,7 @@ class _CupertinoControlsState extends State<CupertinoControls>
722722
255,
723723
),
724724
),
725+
draggableProgressBar: chewieController.draggableProgressBar,
725726
),
726727
),
727728
);

lib/src/cupertino/cupertino_progress_bar.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ class CupertinoVideoProgressBar extends StatelessWidget {
1212
this.onDragStart,
1313
this.onDragUpdate,
1414
super.key,
15+
this.draggableProgressBar = true,
1516
}) : colors = colors ?? ChewieProgressColors();
1617

1718
final VideoPlayerController controller;
1819
final ChewieProgressColors colors;
1920
final Function()? onDragStart;
2021
final Function()? onDragEnd;
2122
final Function()? onDragUpdate;
23+
final bool draggableProgressBar;
2224

2325
@override
2426
Widget build(BuildContext context) {
@@ -31,6 +33,7 @@ class CupertinoVideoProgressBar extends StatelessWidget {
3133
onDragEnd: onDragEnd,
3234
onDragStart: onDragStart,
3335
onDragUpdate: onDragUpdate,
36+
draggableProgressBar: draggableProgressBar,
3437
);
3538
}
3639
}

lib/src/material/material_controls.dart

Lines changed: 74 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'dart:async';
22

33
import 'package:chewie/src/center_play_button.dart';
4+
import 'package:chewie/src/center_seek_button.dart';
45
import 'package:chewie/src/chewie_player.dart';
56
import 'package:chewie/src/chewie_progress_colors.dart';
67
import 'package:chewie/src/helpers/utils.dart';
@@ -388,13 +389,48 @@ class _MaterialControlsState extends State<MaterialControls>
388389
});
389390
}
390391
},
391-
child: CenterPlayButton(
392-
backgroundColor: Colors.black54,
393-
iconColor: Colors.white,
394-
isFinished: isFinished,
395-
isPlaying: controller.value.isPlaying,
396-
show: showPlayButton,
397-
onPressed: _playPause,
392+
child: Container(
393+
alignment: Alignment.center,
394+
color: Colors
395+
.transparent, // The Gesture Detector doesn't expand to the full size of the container without this; Not sure why!
396+
child: Row(
397+
mainAxisAlignment: MainAxisAlignment.center,
398+
children: [
399+
if (!isFinished && !chewieController.isLive)
400+
CenterSeekButton(
401+
iconData: Icons.replay_10,
402+
backgroundColor: Colors.black54,
403+
iconColor: Colors.white,
404+
show: showPlayButton,
405+
fadeDuration: chewieController.materialSeekButtonFadeDuration,
406+
iconSize: chewieController.materialSeekButtonSize,
407+
onPressed: _seekBackward,
408+
),
409+
Container(
410+
margin: EdgeInsets.symmetric(
411+
horizontal: marginSize,
412+
),
413+
child: CenterPlayButton(
414+
backgroundColor: Colors.black54,
415+
iconColor: Colors.white,
416+
isFinished: isFinished,
417+
isPlaying: controller.value.isPlaying,
418+
show: showPlayButton,
419+
onPressed: _playPause,
420+
),
421+
),
422+
if (!isFinished && !chewieController.isLive)
423+
CenterSeekButton(
424+
iconData: Icons.forward_10,
425+
backgroundColor: Colors.black54,
426+
iconColor: Colors.white,
427+
show: showPlayButton,
428+
fadeDuration: chewieController.materialSeekButtonFadeDuration,
429+
iconSize: chewieController.materialSeekButtonSize,
430+
onPressed: _seekForward,
431+
),
432+
],
433+
),
398434
),
399435
);
400436
}
@@ -546,6 +582,36 @@ class _MaterialControlsState extends State<MaterialControls>
546582
});
547583
}
548584

585+
void _seekRelative(Duration relativeSeek) {
586+
_cancelAndRestartTimer();
587+
final position = _latestValue.position + relativeSeek;
588+
final duration = _latestValue.duration;
589+
590+
if (position < Duration.zero) {
591+
controller.seekTo(Duration.zero);
592+
} else if (position > duration) {
593+
controller.seekTo(duration);
594+
} else {
595+
controller.seekTo(position);
596+
}
597+
}
598+
599+
void _seekBackward() {
600+
_seekRelative(
601+
const Duration(
602+
seconds: -10,
603+
),
604+
);
605+
}
606+
607+
void _seekForward() {
608+
_seekRelative(
609+
const Duration(
610+
seconds: 10,
611+
),
612+
);
613+
}
614+
549615
void _startHideTimer() {
550616
final hideControlsTimer = chewieController.hideControlsTimer.isNegative
551617
? ChewieController.defaultHideControlsTimer
@@ -618,6 +684,7 @@ class _MaterialControlsState extends State<MaterialControls>
618684
Theme.of(context).colorScheme.surface.withOpacity(0.5),
619685
backgroundColor: Theme.of(context).disabledColor.withOpacity(.5),
620686
),
687+
draggableProgressBar: chewieController.draggableProgressBar,
621688
),
622689
);
623690
}

lib/src/material/material_desktop_controls.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,7 @@ class _MaterialDesktopControlsState extends State<MaterialDesktopControls>
594594
Theme.of(context).colorScheme.surface.withOpacity(0.5),
595595
backgroundColor: Theme.of(context).disabledColor.withOpacity(.5),
596596
),
597+
draggableProgressBar: chewieController.draggableProgressBar,
597598
),
598599
);
599600
}

lib/src/material/material_progress_bar.dart

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,38 @@ class MaterialVideoProgressBar extends StatelessWidget {
77
MaterialVideoProgressBar(
88
this.controller, {
99
this.height = kToolbarHeight,
10+
this.barHeight = 10,
11+
this.handleHeight = 6,
1012
ChewieProgressColors? colors,
1113
this.onDragEnd,
1214
this.onDragStart,
1315
this.onDragUpdate,
1416
super.key,
17+
this.draggableProgressBar = true,
1518
}) : colors = colors ?? ChewieProgressColors();
1619

1720
final double height;
21+
final double barHeight;
22+
final double handleHeight;
1823
final VideoPlayerController controller;
1924
final ChewieProgressColors colors;
2025
final Function()? onDragStart;
2126
final Function()? onDragEnd;
2227
final Function()? onDragUpdate;
28+
final bool draggableProgressBar;
2329

2430
@override
2531
Widget build(BuildContext context) {
2632
return VideoProgressBar(
2733
controller,
28-
barHeight: 10,
29-
handleHeight: 6,
34+
barHeight: barHeight,
35+
handleHeight: handleHeight,
3036
drawShadow: true,
3137
colors: colors,
3238
onDragEnd: onDragEnd,
3339
onDragStart: onDragStart,
3440
onDragUpdate: onDragUpdate,
41+
draggableProgressBar: draggableProgressBar,
3542
);
3643
}
3744
}

lib/src/progress_bar.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class VideoProgressBar extends StatefulWidget {
99
this.onDragEnd,
1010
this.onDragStart,
1111
this.onDragUpdate,
12+
this.draggableProgressBar = true,
1213
super.key,
1314
required this.barHeight,
1415
required this.handleHeight,
@@ -24,6 +25,7 @@ class VideoProgressBar extends StatefulWidget {
2425
final double barHeight;
2526
final double handleHeight;
2627
final bool drawShadow;
28+
final bool draggableProgressBar;
2729

2830
@override
2931
// ignore: library_private_types_in_public_api
@@ -65,7 +67,6 @@ class _VideoProgressBarState extends State<VideoProgressBar> {
6567

6668
@override
6769
Widget build(BuildContext context) {
68-
final ChewieController chewieController = ChewieController.of(context);
6970
final child = Center(
7071
child: StaticProgressBar(
7172
value: controller.value,
@@ -77,7 +78,7 @@ class _VideoProgressBarState extends State<VideoProgressBar> {
7778
),
7879
);
7980

80-
return chewieController.draggableProgressBar
81+
return widget.draggableProgressBar
8182
? GestureDetector(
8283
onHorizontalDragStart: (DragStartDetails details) {
8384
if (!controller.value.isInitialized) {

0 commit comments

Comments
 (0)