Skip to content

Commit

Permalink
Merge branch 'master' into custom-lg
Browse files Browse the repository at this point in the history
* master:
  Version 1.5.0. Addresses PR fluttercommunity#712.
  Upgraded iOS Example App's Xcode files.
  Added latest dart format changes.
  Fixed app.dart lint issues.
  Added CI fixes due to Dart 3.
  Version 1.4.1. Addresses PR fluttercommunity#719.
  Fix overlay not visible
  Update progress_bar.dart
  again
  fix(ci): deprecated command
  again
  Update progress_bar.dart
  Update progress_bar.dart
  Update chewie_player.dart

# Conflicts:
#	example/ios/Runner.xcodeproj/project.pbxproj
  • Loading branch information
lg8294 committed May 12, 2023
2 parents 225fac7 + f5f3635 commit f17efdc
Show file tree
Hide file tree
Showing 14 changed files with 157 additions and 79 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ on:

jobs:
check-format:
name: Check format using flutter format.
name: Check format using dart format.
runs-on: ubuntu-latest

steps:
Expand All @@ -22,7 +22,7 @@ jobs:
- name: Flutter Action
uses: subosito/flutter-action@v2
- name: Check format
run: flutter format . --set-exit-if-changed
run: dart format . --set-exit-if-changed

lint:
name: Lint
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 1.5.0
* 🛠️ [#712](https://github.com/fluttercommunity/chewie/pull/712): Progress Bars can now be disabled by setting `ChewieController.draggableProgressBar` to `false`. Thanks [shiyiya](https://github.com/shiyiya).
* ⬆️ Increased Dart SDK constraint to cover Dart `3.0.0` and higher.

## 1.4.1
* 🛠️ [#719](https://github.com/fluttercommunity/chewie/pull/719): Fix overlay not visible. Thanks [jaripekkala](https://github.com/jaripekkala).

## 1.4.0
* 🛠️ [#701](https://github.com/fluttercommunity/chewie/pull/701): Added Dart Analysis fixes due to Flutter 3.7. Thanks [diegotori](https://github.com/diegotori).

Expand Down
4 changes: 2 additions & 2 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
include: package:flutter_lints/flutter.yaml

analyzer:
strong-mode:
implicit-dynamic: false
language:
strict-raw-types: true
exclude:
- lib/generated_plugin_registrant.dart
errors:
Expand Down
4 changes: 2 additions & 2 deletions example/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
include: package:flutter_lints/flutter.yaml

analyzer:
strong-mode:
implicit-dynamic: false
language:
strict-raw-types: true
exclude:
- lib/generated_plugin_registrant.dart

Expand Down
2 changes: 1 addition & 1 deletion example/ios/Flutter/AppFrameworkInfo.plist
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
<key>CFBundleVersion</key>
<string>1.0</string>
<key>MinimumOSVersion</key>
<string>9.0</string>
<string>11.0</string>
</dict>
</plist>
2 changes: 2 additions & 0 deletions example/ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,7 @@
<false/>
<key>CADisableMinimumFrameDurationOnPhone</key>
<true/>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>
</dict>
</plist>
4 changes: 2 additions & 2 deletions example/lib/app/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,9 @@ class _ChewieDemoState extends State<ChewieDemo> {
? Chewie(
controller: _chewieController!,
)
: Column(
: const Column(
mainAxisAlignment: MainAxisAlignment.center,
children: const [
children: [
CircularProgressIndicator(),
SizedBox(height: 20),
Text('Loading'),
Expand Down
11 changes: 8 additions & 3 deletions lib/src/chewie_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ class ChewieController extends ChangeNotifier {
this.aspectRatio,
this.autoInitialize = false,
this.autoPlay = false,
this.draggableProgressBar = true,
this.startAt,
this.looping = false,
this.fullScreenByDefault = false,
Expand Down Expand Up @@ -311,6 +312,7 @@ class ChewieController extends ChangeNotifier {
double? aspectRatio,
bool? autoInitialize,
bool? autoPlay,
bool? draggableProgressBar,
Duration? startAt,
bool? looping,
bool? fullScreenByDefault,
Expand Down Expand Up @@ -349,10 +351,10 @@ class ChewieController extends ChangeNotifier {
Animation<double>,
Animation<double>,
ChewieControllerProvider,
)?
routePageBuilder,
)? routePageBuilder,
}) {
return ChewieController(
draggableProgressBar: draggableProgressBar ?? this.draggableProgressBar,
videoPlayerController:
videoPlayerController ?? this.videoPlayerController,
optionsTranslation: optionsTranslation ?? this.optionsTranslation,
Expand Down Expand Up @@ -445,6 +447,9 @@ class ChewieController extends ChangeNotifier {
/// Play the video as soon as it's displayed
final bool autoPlay;

/// Non-Draggable Progress Bar
final bool draggableProgressBar;

/// Start video at a certain position
final Duration? startAt;

Expand Down Expand Up @@ -558,7 +563,7 @@ class ChewieController extends ChangeNotifier {

bool get isPlaying => videoPlayerController.value.isPlaying;

Future _initialize() async {
Future<dynamic> _initialize() async {
await videoPlayerController.setLooping(looping);

if ((autoInitialize || autoPlay) &&
Expand Down
3 changes: 3 additions & 0 deletions lib/src/cupertino/cupertino_controls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,9 @@ class _CupertinoControlsState extends State<CupertinoControls>

_hideTimer?.cancel();
},
onDragUpdate: () {
_hideTimer?.cancel();
},
onDragEnd: () {
setState(() {
_dragging = false;
Expand Down
3 changes: 3 additions & 0 deletions lib/src/material/material_controls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,9 @@ class _MaterialControlsState extends State<MaterialControls>

_hideTimer?.cancel();
},
onDragUpdate: () {
_hideTimer?.cancel();
},
onDragEnd: () {
setState(() {
_dragging = false;
Expand Down
3 changes: 3 additions & 0 deletions lib/src/material/material_desktop_controls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,9 @@ class _MaterialDesktopControlsState extends State<MaterialDesktopControls>

_hideTimer?.cancel();
},
onDragUpdate: () {
_hideTimer?.cancel();
},
onDragEnd: () {
setState(() {
_dragging = false;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/player_with_controls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class PlayerWithControls extends StatelessWidget {
),
child: const DecoratedBox(
decoration: BoxDecoration(color: Colors.black54),
child: SizedBox(),
child: SizedBox.expand(),
),
),
),
Expand Down
183 changes: 119 additions & 64 deletions lib/src/progress_bar.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import 'dart:io';

import 'package:chewie/src/chewie_progress_colors.dart';
import 'package:chewie/chewie.dart';
import 'package:flutter/material.dart';
import 'package:video_player/video_player.dart';

Expand Down Expand Up @@ -43,6 +41,8 @@ class _VideoProgressBarState extends State<VideoProgressBar> {

bool _controllerWasPlaying = false;

Offset? _latestDraggableOffset;

VideoPlayerController get controller => widget.controller;

@override
Expand All @@ -58,70 +58,107 @@ class _VideoProgressBarState extends State<VideoProgressBar> {
}

void _seekToRelativePosition(Offset globalPosition) {
final box = context.findRenderObject()! as RenderBox;
final Offset tapPos = box.globalToLocal(globalPosition);
final double relative = tapPos.dx / box.size.width;
final Duration position = controller.value.duration * relative;
controller.seekTo(position);
controller.seekTo(context.calcRelativePosition(
controller.value.duration,
globalPosition,
));
}

@override
Widget build(BuildContext context) {
return GestureDetector(
onHorizontalDragStart: (DragStartDetails details) {
if (!controller.value.isInitialized) {
return;
}
_controllerWasPlaying = controller.value.isPlaying;
if (_controllerWasPlaying) {
controller.pause();
}

widget.onDragStart?.call();
},
onHorizontalDragUpdate: (DragUpdateDetails details) {
if (!controller.value.isInitialized) {
return;
}
// Should only seek if it's not running on Android, or if it is,
// then the VideoPlayerController cannot be buffering.
// On Android, we need to let the player buffer when scrolling
// in order to let the player buffer. https://github.com/flutter/flutter/issues/101409
final shouldSeekToRelativePosition =
!Platform.isAndroid || !controller.value.isBuffering;
if (shouldSeekToRelativePosition) {
_seekToRelativePosition(details.globalPosition);
}

widget.onDragUpdate?.call();
},
onHorizontalDragEnd: (DragEndDetails details) {
if (_controllerWasPlaying) {
controller.play();
}

widget.onDragEnd?.call();
},
onTapDown: (TapDownDetails details) {
if (!controller.value.isInitialized) {
return;
}
_seekToRelativePosition(details.globalPosition);
},
child: Center(
child: Container(
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
color: Colors.transparent,
child: CustomPaint(
painter: _ProgressBarPainter(
value: controller.value,
colors: widget.colors,
barHeight: widget.barHeight,
handleHeight: widget.handleHeight,
drawShadow: widget.drawShadow,
),
final ChewieController chewieController = ChewieController.of(context);
final child = Center(
child: StaticProgressBar(
value: controller.value,
colors: widget.colors,
barHeight: widget.barHeight,
handleHeight: widget.handleHeight,
drawShadow: widget.drawShadow,
),
);

return chewieController.draggableProgressBar
? GestureDetector(
onHorizontalDragStart: (DragStartDetails details) {
if (!controller.value.isInitialized) {
return;
}
_controllerWasPlaying = controller.value.isPlaying;
if (_controllerWasPlaying) {
controller.pause();
}

widget.onDragStart?.call();
},
onHorizontalDragUpdate: (DragUpdateDetails details) {
if (!controller.value.isInitialized) {
return;
}
_latestDraggableOffset = details.globalPosition;
listener();

widget.onDragUpdate?.call();
},
onHorizontalDragEnd: (DragEndDetails details) {
if (_controllerWasPlaying) {
controller.play();
}

if (_latestDraggableOffset != null) {
_seekToRelativePosition(_latestDraggableOffset!);
_latestDraggableOffset = null;
}

widget.onDragEnd?.call();
},
onTapDown: (TapDownDetails details) {
if (!controller.value.isInitialized) {
return;
}
_seekToRelativePosition(details.globalPosition);
},
child: child,
)
: child;
}
}

class StaticProgressBar extends StatelessWidget {
const StaticProgressBar({
Key? key,
required this.value,
required this.colors,
required this.barHeight,
required this.handleHeight,
required this.drawShadow,
this.latestDraggableOffset,
}) : super(key: key);

final Offset? latestDraggableOffset;
final VideoPlayerValue value;
final ChewieProgressColors colors;

final double barHeight;
final double handleHeight;
final bool drawShadow;

@override
Widget build(BuildContext context) {
return Container(
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
color: Colors.transparent,
child: CustomPaint(
painter: _ProgressBarPainter(
value: value,
draggableValue: context.calcRelativePosition(
value.duration,
latestDraggableOffset,
),
colors: colors,
barHeight: barHeight,
handleHeight: handleHeight,
drawShadow: drawShadow,
),
),
);
Expand All @@ -135,6 +172,7 @@ class _ProgressBarPainter extends CustomPainter {
required this.barHeight,
required this.handleHeight,
required this.drawShadow,
required this.draggableValue,
});

VideoPlayerValue value;
Expand All @@ -143,6 +181,7 @@ class _ProgressBarPainter extends CustomPainter {
final double barHeight;
final double handleHeight;
final bool drawShadow;
final Duration draggableValue;

@override
bool shouldRepaint(CustomPainter painter) {
Expand All @@ -166,8 +205,10 @@ class _ProgressBarPainter extends CustomPainter {
if (!value.isInitialized) {
return;
}
final double playedPartPercent =
value.position.inMilliseconds / value.duration.inMilliseconds;
final double playedPartPercent = (draggableValue != Duration.zero
? draggableValue.inMilliseconds
: value.position.inMilliseconds) /
value.duration.inMilliseconds;
final double playedPart =
playedPartPercent > 1 ? size.width : playedPartPercent * size.width;
for (final DurationRange range in value.buffered) {
Expand Down Expand Up @@ -214,3 +255,17 @@ class _ProgressBarPainter extends CustomPainter {
);
}
}

extension RelativePositionExtensions on BuildContext {
Duration calcRelativePosition(
Duration videoDuration,
Offset? globalPosition,
) {
if (globalPosition == null) return Duration.zero;
final box = findRenderObject()! as RenderBox;
final Offset tapPos = box.globalToLocal(globalPosition);
final double relative = tapPos.dx / box.size.width;
final Duration position = videoDuration * relative;
return position;
}
}
Loading

0 comments on commit f17efdc

Please sign in to comment.