From 32ca67e7f1baa9f1e055a0efab679a6569d2a067 Mon Sep 17 00:00:00 2001 From: "h.carnot" Date: Fri, 1 Apr 2022 18:04:36 +0200 Subject: [PATCH 01/13] feat: add a delay before displaying progress indicator --- lib/src/material/material_controls.dart | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/src/material/material_controls.dart b/lib/src/material/material_controls.dart index 4c409e4ca..6961c793c 100644 --- a/lib/src/material/material_controls.dart +++ b/lib/src/material/material_controls.dart @@ -82,7 +82,7 @@ class _MaterialControlsState extends State absorbing: notifier.hideStuff, child: Stack( children: [ - if (_latestValue.isBuffering) + if (displayLoading) const Center( child: CircularProgressIndicator(), ) @@ -550,8 +550,27 @@ class _MaterialControlsState extends State }); } + Timer? timerInstance; + bool displayLoading = false; + + void handleTimeout() { + displayLoading = true; + if (mounted) { + setState(() {}); + } + } + void _updateState() { if (!mounted) return; + + if (controller.value.isBuffering) { + timerInstance ??= Timer(const Duration(milliseconds: 200), handleTimeout); + } else { + timerInstance?.cancel(); + timerInstance = null; + displayLoading = false; + } + setState(() { _latestValue = controller.value; _subtitlesPosition = controller.value.position; From 106a8854ddcfdf26e025167a9b85fad0adac203b Mon Sep 17 00:00:00 2001 From: "h.carnot" Date: Mon, 4 Apr 2022 10:23:15 +0200 Subject: [PATCH 02/13] feat: added example debug --- example/lib/app/app.dart | 6 +++++- pubspec.yaml | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/example/lib/app/app.dart b/example/lib/app/app.dart index 38840241b..789503c56 100644 --- a/example/lib/app/app.dart +++ b/example/lib/app/app.dart @@ -39,6 +39,7 @@ class _ChewieDemoState extends State { } List srcs = [ + "https://upload.wikimedia.org/wikipedia/commons/2/2c/Earth_rotation_during_Galileo_flyby_%28PIA00114%29_%28color-adjusted%29.webm", "https://assets.mixkit.co/videos/preview/mixkit-daytime-city-traffic-aerial-view-56-large.mp4", "https://assets.mixkit.co/videos/preview/mixkit-a-girl-blowing-a-bubble-gum-at-an-amusement-park-1226-large.mp4" ]; @@ -155,7 +156,10 @@ class _ChewieDemoState extends State { Future toggleVideo() async { await _videoPlayerController1.pause(); - currPlayIndex = currPlayIndex == 0 ? 1 : 0; + currPlayIndex += 1; + if (currPlayIndex >= srcs.length) { + currPlayIndex = 0; + } await initializePlayer(); } diff --git a/pubspec.yaml b/pubspec.yaml index 94842e5af..5f5c3b6d0 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -12,7 +12,11 @@ dependencies: flutter: sdk: flutter provider: ^6.0.1 - video_player: ^2.2.7 + video_player: + git: + url: https://github.com/henri2h/plugins.git + ref: henri/enhance-seeking-mechanism-test + path: packages/video_player/video_player wakelock: ^0.6.1+1 dev_dependencies: From 09f3b956eec139332e943e10248f9ee457fa6a3d Mon Sep 17 00:00:00 2001 From: "h.carnot" Date: Mon, 4 Apr 2022 11:26:35 +0200 Subject: [PATCH 03/13] feat: added method to set progress delay --- example/lib/app/app.dart | 79 +++++++++++++++++++++++++ lib/src/chewie_player.dart | 8 ++- lib/src/material/material_controls.dart | 20 +++++-- 3 files changed, 101 insertions(+), 6 deletions(-) diff --git a/example/lib/app/app.dart b/example/lib/app/app.dart index 789503c56..d7effcfb0 100644 --- a/example/lib/app/app.dart +++ b/example/lib/app/app.dart @@ -23,6 +23,7 @@ class _ChewieDemoState extends State { late VideoPlayerController _videoPlayerController1; late VideoPlayerController _videoPlayerController2; ChewieController? _chewieController; + int? bufferDelay; @override void initState() { @@ -111,6 +112,7 @@ class _ChewieDemoState extends State { videoPlayerController: _videoPlayerController1, autoPlay: true, looping: true, + progressIndicatorDelayMS: bufferDelay, additionalOptions: (context) { return [ @@ -306,9 +308,86 @@ class _ChewieDemoState extends State { ), ], ), + ListTile( + title: const Text("Delay"), + subtitle: Column( + children: [ + DelaySlider( + delay: _chewieController?.progressIndicatorDelayMS, + onSave: (delay) async { + if (delay != null) { + if (delay == 0) { + bufferDelay = null; + } else { + bufferDelay = delay; + } + + await initializePlayer(); + } + }, + ), + Text( + _chewieController?.progressIndicatorDelayMS != null + ? "Progress indicator delay ${_chewieController!.progressIndicatorDelayMS.toString()} MS" + : "Set me", + ), + ], + ), + ) ], ), ), ); } } + +class DelaySlider extends StatefulWidget { + const DelaySlider({Key? key, required this.delay, required this.onSave}) + : super(key: key); + + final int? delay; + final void Function(int?) onSave; + @override + State createState() => _DelaySliderState(); +} + +class _DelaySliderState extends State { + int? delay; + bool saved = false; + + @override + void initState() { + super.initState(); + delay = widget.delay; + } + + @override + Widget build(BuildContext context) { + const int max = 1000; + return ListTile( + title: Text( + "Progress indicator delay ${delay != null ? "${delay.toString()} MS" : ""}", + ), + subtitle: Slider( + value: delay != null ? (delay! / max) : 0, + onChanged: (value) async { + delay = (value * max).toInt(); + setState(() { + saved = false; + }); + }, + ), + trailing: IconButton( + icon: const Icon(Icons.save), + onPressed: saved + ? null + : () { + widget.onSave(delay); + setState(() { + saved = true; + }); + }, + ), + ); + } +} diff --git a/lib/src/chewie_player.dart b/lib/src/chewie_player.dart index 71eae87f1..15829cd59 100644 --- a/lib/src/chewie_player.dart +++ b/lib/src/chewie_player.dart @@ -281,6 +281,7 @@ class ChewieController extends ChangeNotifier { this.deviceOrientationsAfterFullScreen = DeviceOrientation.values, this.routePageBuilder, this.hideControlsTimer = defaultHideControlsTimer, + this.progressIndicatorDelayMS, }) : assert( playbackSpeeds.every((speed) => speed > 0), 'The playbackSpeeds values must all be greater than 0', @@ -324,6 +325,7 @@ class ChewieController extends ChangeNotifier { List? deviceOrientationsOnEnterFullScreen, List? systemOverlaysAfterFullScreen, List? deviceOrientationsAfterFullScreen, + int? bufferingProgressIndicatorDisplayDelayMS, Widget Function( BuildContext, Animation, @@ -377,7 +379,8 @@ class ChewieController extends ChangeNotifier { this.deviceOrientationsAfterFullScreen, routePageBuilder: routePageBuilder ?? this.routePageBuilder, hideControlsTimer: hideControlsTimer ?? this.hideControlsTimer, - ); + progressIndicatorDelayMS: bufferingProgressIndicatorDisplayDelayMS ?? + this.progressIndicatorDelayMS); } static const defaultHideControlsTimer = Duration(seconds: 3); @@ -513,6 +516,9 @@ class ChewieController extends ChangeNotifier { /// Defines a custom RoutePageBuilder for the fullscreen final ChewieRoutePageBuilder? routePageBuilder; + /// [Android] Defines a delay in milliseconds between entering buffering state and displaying the loading spinner. Set null (default) to disable it. + final int? progressIndicatorDelayMS; + static ChewieController of(BuildContext context) { final chewieControllerProvider = context.dependOnInheritedWidgetOfExactType()!; diff --git a/lib/src/material/material_controls.dart b/lib/src/material/material_controls.dart index 6961c793c..1dc2aa06b 100644 --- a/lib/src/material/material_controls.dart +++ b/lib/src/material/material_controls.dart @@ -563,12 +563,22 @@ class _MaterialControlsState extends State void _updateState() { if (!mounted) return; - if (controller.value.isBuffering) { - timerInstance ??= Timer(const Duration(milliseconds: 200), handleTimeout); + // display the progress bar indicator only after the buffering delay if it has been set + if (chewieController.progressIndicatorDelayMS != null) { + if (controller.value.isBuffering) { + timerInstance ??= Timer( + Duration( + milliseconds: chewieController.progressIndicatorDelayMS!, + ), + handleTimeout, + ); + } else { + timerInstance?.cancel(); + timerInstance = null; + displayLoading = false; + } } else { - timerInstance?.cancel(); - timerInstance = null; - displayLoading = false; + displayLoading = controller.value.isBuffering; } setState(() { From 4b69e85e83c394d5775f44bd0e68bc3abf6d640a Mon Sep 17 00:00:00 2001 From: "h.carnot" Date: Mon, 4 Apr 2022 11:31:11 +0200 Subject: [PATCH 04/13] fix: lint --- lib/src/chewie_player.dart | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/src/chewie_player.dart b/lib/src/chewie_player.dart index 15829cd59..0d2a3cafa 100644 --- a/lib/src/chewie_player.dart +++ b/lib/src/chewie_player.dart @@ -325,7 +325,7 @@ class ChewieController extends ChangeNotifier { List? deviceOrientationsOnEnterFullScreen, List? systemOverlaysAfterFullScreen, List? deviceOrientationsAfterFullScreen, - int? bufferingProgressIndicatorDisplayDelayMS, + int? progressIndicatorDelayMS, Widget Function( BuildContext, Animation, @@ -379,8 +379,9 @@ class ChewieController extends ChangeNotifier { this.deviceOrientationsAfterFullScreen, routePageBuilder: routePageBuilder ?? this.routePageBuilder, hideControlsTimer: hideControlsTimer ?? this.hideControlsTimer, - progressIndicatorDelayMS: bufferingProgressIndicatorDisplayDelayMS ?? - this.progressIndicatorDelayMS); + progressIndicatorDelayMS: + progressIndicatorDelayMS ?? this.progressIndicatorDelayMS, + ); } static const defaultHideControlsTimer = Duration(seconds: 3); From 26544dd7e5c64e1d9a5b12b5e5ebc55608567ca2 Mon Sep 17 00:00:00 2001 From: "h.carnot" Date: Mon, 4 Apr 2022 11:35:54 +0200 Subject: [PATCH 05/13] fix: removed old code --- example/lib/app/app.dart | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/example/lib/app/app.dart b/example/lib/app/app.dart index d7effcfb0..def7a56d6 100644 --- a/example/lib/app/app.dart +++ b/example/lib/app/app.dart @@ -310,28 +310,19 @@ class _ChewieDemoState extends State { ), ListTile( title: const Text("Delay"), - subtitle: Column( - children: [ - DelaySlider( - delay: _chewieController?.progressIndicatorDelayMS, - onSave: (delay) async { - if (delay != null) { - if (delay == 0) { - bufferDelay = null; - } else { - bufferDelay = delay; - } + subtitle: DelaySlider( + delay: _chewieController?.progressIndicatorDelayMS, + onSave: (delay) async { + if (delay != null) { + if (delay == 0) { + bufferDelay = null; + } else { + bufferDelay = delay; + } - await initializePlayer(); - } - }, - ), - Text( - _chewieController?.progressIndicatorDelayMS != null - ? "Progress indicator delay ${_chewieController!.progressIndicatorDelayMS.toString()} MS" - : "Set me", - ), - ], + await initializePlayer(); + } + }, ), ) ], From 4e99b4ea9cea4e99f4d8b7a444bfe069e764d039 Mon Sep 17 00:00:00 2001 From: "h.carnot" Date: Mon, 11 Apr 2022 11:35:51 +0200 Subject: [PATCH 06/13] fix: let the android player buffer before seeking once more --- example/lib/app/app.dart | 35 +++++++++++++++++++---------------- lib/src/progress_bar.dart | 12 +++++++++++- pubspec.yaml | 6 +----- 3 files changed, 31 insertions(+), 22 deletions(-) diff --git a/example/lib/app/app.dart b/example/lib/app/app.dart index def7a56d6..d9cb06a0c 100644 --- a/example/lib/app/app.dart +++ b/example/lib/app/app.dart @@ -1,3 +1,5 @@ +import 'dart:io'; + import 'package:chewie/chewie.dart'; import 'package:chewie_example/app/theme.dart'; import 'package:flutter/material.dart'; @@ -308,23 +310,24 @@ class _ChewieDemoState extends State { ), ], ), - ListTile( - title: const Text("Delay"), - subtitle: DelaySlider( - delay: _chewieController?.progressIndicatorDelayMS, - onSave: (delay) async { - if (delay != null) { - if (delay == 0) { - bufferDelay = null; - } else { - bufferDelay = delay; - } + if (Platform.isAndroid) + ListTile( + title: const Text("Delay"), + subtitle: DelaySlider( + delay: _chewieController?.progressIndicatorDelayMS, + onSave: (delay) async { + if (delay != null) { + if (delay == 0) { + bufferDelay = null; + } else { + bufferDelay = delay; + } - await initializePlayer(); - } - }, - ), - ) + await initializePlayer(); + } + }, + ), + ) ], ), ), diff --git a/lib/src/progress_bar.dart b/lib/src/progress_bar.dart index 1c6f51981..2e6d9a6b8 100644 --- a/lib/src/progress_bar.dart +++ b/lib/src/progress_bar.dart @@ -1,3 +1,5 @@ +import 'dart:io'; + import 'package:chewie/src/chewie_progress_colors.dart'; import 'package:flutter/material.dart'; import 'package:video_player/video_player.dart'; @@ -81,7 +83,15 @@ class _VideoProgressBarState extends State { if (!controller.value.isInitialized) { return; } - _seekToRelativePosition(details.globalPosition); + if (Platform.isAndroid) { + // 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 + if (!controller.value.isBuffering) { + _seekToRelativePosition(details.globalPosition); + } + } else { + _seekToRelativePosition(details.globalPosition); + } widget.onDragUpdate?.call(); }, diff --git a/pubspec.yaml b/pubspec.yaml index 5f5c3b6d0..94842e5af 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -12,11 +12,7 @@ dependencies: flutter: sdk: flutter provider: ^6.0.1 - video_player: - git: - url: https://github.com/henri2h/plugins.git - ref: henri/enhance-seeking-mechanism-test - path: packages/video_player/video_player + video_player: ^2.2.7 wakelock: ^0.6.1+1 dev_dependencies: From 82d658f48f80c13ac6d9e81ec9d8225fed957eea Mon Sep 17 00:00:00 2001 From: "h.carnot" Date: Tue, 12 Apr 2022 18:31:48 +0200 Subject: [PATCH 07/13] fix: name --- example/lib/app/app.dart | 4 ++-- lib/src/chewie_player.dart | 10 +++++----- lib/src/material/material_controls.dart | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/example/lib/app/app.dart b/example/lib/app/app.dart index d9cb06a0c..42f3626aa 100644 --- a/example/lib/app/app.dart +++ b/example/lib/app/app.dart @@ -114,7 +114,7 @@ class _ChewieDemoState extends State { videoPlayerController: _videoPlayerController1, autoPlay: true, looping: true, - progressIndicatorDelayMS: bufferDelay, + progressIndicatorDelayMs: bufferDelay, additionalOptions: (context) { return [ @@ -314,7 +314,7 @@ class _ChewieDemoState extends State { ListTile( title: const Text("Delay"), subtitle: DelaySlider( - delay: _chewieController?.progressIndicatorDelayMS, + delay: _chewieController?.progressIndicatorDelayMs, onSave: (delay) async { if (delay != null) { if (delay == 0) { diff --git a/lib/src/chewie_player.dart b/lib/src/chewie_player.dart index 0d2a3cafa..4f6bbef78 100644 --- a/lib/src/chewie_player.dart +++ b/lib/src/chewie_player.dart @@ -281,7 +281,7 @@ class ChewieController extends ChangeNotifier { this.deviceOrientationsAfterFullScreen = DeviceOrientation.values, this.routePageBuilder, this.hideControlsTimer = defaultHideControlsTimer, - this.progressIndicatorDelayMS, + this.progressIndicatorDelayMs, }) : assert( playbackSpeeds.every((speed) => speed > 0), 'The playbackSpeeds values must all be greater than 0', @@ -325,7 +325,7 @@ class ChewieController extends ChangeNotifier { List? deviceOrientationsOnEnterFullScreen, List? systemOverlaysAfterFullScreen, List? deviceOrientationsAfterFullScreen, - int? progressIndicatorDelayMS, + int? progressIndicatorDelayMs, Widget Function( BuildContext, Animation, @@ -379,8 +379,8 @@ class ChewieController extends ChangeNotifier { this.deviceOrientationsAfterFullScreen, routePageBuilder: routePageBuilder ?? this.routePageBuilder, hideControlsTimer: hideControlsTimer ?? this.hideControlsTimer, - progressIndicatorDelayMS: - progressIndicatorDelayMS ?? this.progressIndicatorDelayMS, + progressIndicatorDelayMs: + progressIndicatorDelayMs ?? this.progressIndicatorDelayMs, ); } @@ -518,7 +518,7 @@ class ChewieController extends ChangeNotifier { final ChewieRoutePageBuilder? routePageBuilder; /// [Android] Defines a delay in milliseconds between entering buffering state and displaying the loading spinner. Set null (default) to disable it. - final int? progressIndicatorDelayMS; + final int? progressIndicatorDelayMs; static ChewieController of(BuildContext context) { final chewieControllerProvider = diff --git a/lib/src/material/material_controls.dart b/lib/src/material/material_controls.dart index 1dc2aa06b..7ab31b1a5 100644 --- a/lib/src/material/material_controls.dart +++ b/lib/src/material/material_controls.dart @@ -564,11 +564,11 @@ class _MaterialControlsState extends State if (!mounted) return; // display the progress bar indicator only after the buffering delay if it has been set - if (chewieController.progressIndicatorDelayMS != null) { + if (chewieController.progressIndicatorDelayMs != null) { if (controller.value.isBuffering) { timerInstance ??= Timer( Duration( - milliseconds: chewieController.progressIndicatorDelayMS!, + milliseconds: chewieController.progressIndicatorDelayMs!, ), handleTimeout, ); From 63b9756243c61ba6d60d89a73df402d5315df0bb Mon Sep 17 00:00:00 2001 From: "h.carnot" Date: Fri, 13 May 2022 18:10:39 +0200 Subject: [PATCH 08/13] fix: simplify assignation --- example/lib/app/app.dart | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/example/lib/app/app.dart b/example/lib/app/app.dart index 42f3626aa..4d21466d9 100644 --- a/example/lib/app/app.dart +++ b/example/lib/app/app.dart @@ -317,12 +317,7 @@ class _ChewieDemoState extends State { delay: _chewieController?.progressIndicatorDelayMs, onSave: (delay) async { if (delay != null) { - if (delay == 0) { - bufferDelay = null; - } else { - bufferDelay = delay; - } - + bufferDelay = delay == 0 ? null : delay; await initializePlayer(); } }, From a75b67cea53fbca787543c0aef9c171360394099 Mon Sep 17 00:00:00 2001 From: "h.carnot" Date: Mon, 16 May 2022 09:31:47 +0200 Subject: [PATCH 09/13] feat: Make progressIndicatorDelay a Duration --- example/lib/app/app.dart | 6 ++++-- lib/src/chewie_player.dart | 10 ++++++---- lib/src/material/material_controls.dart | 6 ++---- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/example/lib/app/app.dart b/example/lib/app/app.dart index 4d21466d9..c24c18373 100644 --- a/example/lib/app/app.dart +++ b/example/lib/app/app.dart @@ -114,7 +114,8 @@ class _ChewieDemoState extends State { videoPlayerController: _videoPlayerController1, autoPlay: true, looping: true, - progressIndicatorDelayMs: bufferDelay, + progressIndicatorDelay: + bufferDelay != null ? Duration(milliseconds: bufferDelay!) : null, additionalOptions: (context) { return [ @@ -314,7 +315,8 @@ class _ChewieDemoState extends State { ListTile( title: const Text("Delay"), subtitle: DelaySlider( - delay: _chewieController?.progressIndicatorDelayMs, + delay: + _chewieController?.progressIndicatorDelay?.inMilliseconds, onSave: (delay) async { if (delay != null) { bufferDelay = delay == 0 ? null : delay; diff --git a/lib/src/chewie_player.dart b/lib/src/chewie_player.dart index 4f6bbef78..307b59b98 100644 --- a/lib/src/chewie_player.dart +++ b/lib/src/chewie_player.dart @@ -280,6 +280,7 @@ class ChewieController extends ChangeNotifier { this.systemOverlaysAfterFullScreen = SystemUiOverlay.values, this.deviceOrientationsAfterFullScreen = DeviceOrientation.values, this.routePageBuilder, + this.progressIndicatorDelay, this.hideControlsTimer = defaultHideControlsTimer, this.progressIndicatorDelayMs, }) : assert( @@ -325,7 +326,7 @@ class ChewieController extends ChangeNotifier { List? deviceOrientationsOnEnterFullScreen, List? systemOverlaysAfterFullScreen, List? deviceOrientationsAfterFullScreen, - int? progressIndicatorDelayMs, + Duration? progressIndicatorDelay, Widget Function( BuildContext, Animation, @@ -379,8 +380,9 @@ class ChewieController extends ChangeNotifier { this.deviceOrientationsAfterFullScreen, routePageBuilder: routePageBuilder ?? this.routePageBuilder, hideControlsTimer: hideControlsTimer ?? this.hideControlsTimer, - progressIndicatorDelayMs: - progressIndicatorDelayMs ?? this.progressIndicatorDelayMs, + progressIndicatorDelay: + progressIndicatorDelay ?? this.progressIndicatorDelay, + hideControlsTimer: hideControlsTimer ?? this.hideControlsTimer, ); } @@ -518,7 +520,7 @@ class ChewieController extends ChangeNotifier { final ChewieRoutePageBuilder? routePageBuilder; /// [Android] Defines a delay in milliseconds between entering buffering state and displaying the loading spinner. Set null (default) to disable it. - final int? progressIndicatorDelayMs; + final Duration? progressIndicatorDelay; static ChewieController of(BuildContext context) { final chewieControllerProvider = diff --git a/lib/src/material/material_controls.dart b/lib/src/material/material_controls.dart index 7ab31b1a5..709a4ecfc 100644 --- a/lib/src/material/material_controls.dart +++ b/lib/src/material/material_controls.dart @@ -564,12 +564,10 @@ class _MaterialControlsState extends State if (!mounted) return; // display the progress bar indicator only after the buffering delay if it has been set - if (chewieController.progressIndicatorDelayMs != null) { + if (chewieController.progressIndicatorDelay != null) { if (controller.value.isBuffering) { timerInstance ??= Timer( - Duration( - milliseconds: chewieController.progressIndicatorDelayMs!, - ), + chewieController.progressIndicatorDelay!, handleTimeout, ); } else { From 72ef34eb7405c06fbc66954d4f6955b86bf336df Mon Sep 17 00:00:00 2001 From: "h.carnot" Date: Mon, 16 May 2022 09:41:04 +0200 Subject: [PATCH 10/13] feat: added support for apple and desktop version --- lib/src/chewie_player.dart | 2 +- lib/src/cupertino/cupertino_controls.dart | 28 ++++++++++++++++++- lib/src/material/material_controls.dart | 23 ++++++++------- .../material/material_desktop_controls.dart | 28 ++++++++++++++++++- 4 files changed, 66 insertions(+), 15 deletions(-) diff --git a/lib/src/chewie_player.dart b/lib/src/chewie_player.dart index 307b59b98..8ca64d1e9 100644 --- a/lib/src/chewie_player.dart +++ b/lib/src/chewie_player.dart @@ -519,7 +519,7 @@ class ChewieController extends ChangeNotifier { /// Defines a custom RoutePageBuilder for the fullscreen final ChewieRoutePageBuilder? routePageBuilder; - /// [Android] Defines a delay in milliseconds between entering buffering state and displaying the loading spinner. Set null (default) to disable it. + /// Defines a delay in milliseconds between entering buffering state and displaying the loading spinner. Set null (default) to disable it. final Duration? progressIndicatorDelay; static ChewieController of(BuildContext context) { diff --git a/lib/src/cupertino/cupertino_controls.dart b/lib/src/cupertino/cupertino_controls.dart index a4e304ce8..47de2af17 100644 --- a/lib/src/cupertino/cupertino_controls.dart +++ b/lib/src/cupertino/cupertino_controls.dart @@ -47,6 +47,8 @@ class _CupertinoControlsState extends State bool _dragging = false; Duration? _subtitlesPosition; bool _subtitleOn = false; + Timer? _bufferingDisplayTimer; + bool _displayBufferingIndicator = false; late VideoPlayerController controller; @@ -91,7 +93,7 @@ class _CupertinoControlsState extends State absorbing: notifier.hideStuff, child: Stack( children: [ - if (_latestValue.isBuffering) + if (_displayBufferingIndicator) const Center( child: CircularProgressIndicator(), ) @@ -769,8 +771,32 @@ class _CupertinoControlsState extends State }); } + void _bufferingTimerTimeout() { + _displayBufferingIndicator = true; + if (mounted) { + setState(() {}); + } + } + void _updateState() { if (!mounted) return; + + // display the progress bar indicator only after the buffering delay if it has been set + if (chewieController.progressIndicatorDelay != null) { + if (controller.value.isBuffering) { + _bufferingDisplayTimer ??= Timer( + chewieController.progressIndicatorDelay!, + _bufferingTimerTimeout, + ); + } else { + _bufferingDisplayTimer?.cancel(); + _bufferingDisplayTimer = null; + _displayBufferingIndicator = false; + } + } else { + _displayBufferingIndicator = controller.value.isBuffering; + } + setState(() { _latestValue = controller.value; _subtitlesPosition = controller.value.position; diff --git a/lib/src/material/material_controls.dart b/lib/src/material/material_controls.dart index 709a4ecfc..8836a774e 100644 --- a/lib/src/material/material_controls.dart +++ b/lib/src/material/material_controls.dart @@ -40,6 +40,8 @@ class _MaterialControlsState extends State Timer? _showAfterExpandCollapseTimer; bool _dragging = false; bool _displayTapped = false; + Timer? _bufferingDisplayTimer; + bool _displayBufferingIndicator = false; final barHeight = 48.0 * 1.5; final marginSize = 5.0; @@ -82,7 +84,7 @@ class _MaterialControlsState extends State absorbing: notifier.hideStuff, child: Stack( children: [ - if (displayLoading) + if (_displayBufferingIndicator) const Center( child: CircularProgressIndicator(), ) @@ -550,11 +552,8 @@ class _MaterialControlsState extends State }); } - Timer? timerInstance; - bool displayLoading = false; - - void handleTimeout() { - displayLoading = true; + void _bufferingTimerTimeout() { + _displayBufferingIndicator = true; if (mounted) { setState(() {}); } @@ -566,17 +565,17 @@ class _MaterialControlsState extends State // display the progress bar indicator only after the buffering delay if it has been set if (chewieController.progressIndicatorDelay != null) { if (controller.value.isBuffering) { - timerInstance ??= Timer( + _bufferingDisplayTimer ??= Timer( chewieController.progressIndicatorDelay!, - handleTimeout, + _bufferingTimerTimeout, ); } else { - timerInstance?.cancel(); - timerInstance = null; - displayLoading = false; + _bufferingDisplayTimer?.cancel(); + _bufferingDisplayTimer = null; + _displayBufferingIndicator = false; } } else { - displayLoading = controller.value.isBuffering; + _displayBufferingIndicator = controller.value.isBuffering; } setState(() { diff --git a/lib/src/material/material_desktop_controls.dart b/lib/src/material/material_desktop_controls.dart index 2baa7cb22..f90326d11 100644 --- a/lib/src/material/material_desktop_controls.dart +++ b/lib/src/material/material_desktop_controls.dart @@ -41,6 +41,8 @@ class _MaterialDesktopControlsState extends State Timer? _showAfterExpandCollapseTimer; bool _dragging = false; bool _displayTapped = false; + Timer? _bufferingDisplayTimer; + bool _displayBufferingIndicator = false; final barHeight = 48.0 * 1.5; final marginSize = 5.0; @@ -83,7 +85,7 @@ class _MaterialDesktopControlsState extends State absorbing: notifier.hideStuff, child: Stack( children: [ - if (_latestValue.isBuffering) + if (_displayBufferingIndicator) const Center( child: CircularProgressIndicator(), ) @@ -530,8 +532,32 @@ class _MaterialDesktopControlsState extends State }); } + void _bufferingTimerTimeout() { + _displayBufferingIndicator = true; + if (mounted) { + setState(() {}); + } + } + void _updateState() { if (!mounted) return; + + // display the progress bar indicator only after the buffering delay if it has been set + if (chewieController.progressIndicatorDelay != null) { + if (controller.value.isBuffering) { + _bufferingDisplayTimer ??= Timer( + chewieController.progressIndicatorDelay!, + _bufferingTimerTimeout, + ); + } else { + _bufferingDisplayTimer?.cancel(); + _bufferingDisplayTimer = null; + _displayBufferingIndicator = false; + } + } else { + _displayBufferingIndicator = controller.value.isBuffering; + } + setState(() { _latestValue = controller.value; _subtitlesPosition = controller.value.position; From 28d63b2883231e7f9f6547823d2e5e4fbae9790a Mon Sep 17 00:00:00 2001 From: "h.carnot" Date: Wed, 18 May 2022 13:52:48 +0200 Subject: [PATCH 11/13] fix: apply diegotori suggestion --- lib/src/progress_bar.dart | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/src/progress_bar.dart b/lib/src/progress_bar.dart index 2e6d9a6b8..1cab09a2d 100644 --- a/lib/src/progress_bar.dart +++ b/lib/src/progress_bar.dart @@ -83,13 +83,13 @@ class _VideoProgressBarState extends State { if (!controller.value.isInitialized) { return; } - if (Platform.isAndroid) { - // 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 - if (!controller.value.isBuffering) { - _seekToRelativePosition(details.globalPosition); - } - } else { + // 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); } From 79bfde87e01f273ed70df9d13795a26c60304b92 Mon Sep 17 00:00:00 2001 From: "h.carnot" Date: Thu, 19 May 2022 15:19:58 +0200 Subject: [PATCH 12/13] fix: format and migration artifacts --- lib/src/chewie_player.dart | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/src/chewie_player.dart b/lib/src/chewie_player.dart index 8ca64d1e9..99f861738 100644 --- a/lib/src/chewie_player.dart +++ b/lib/src/chewie_player.dart @@ -282,7 +282,6 @@ class ChewieController extends ChangeNotifier { this.routePageBuilder, this.progressIndicatorDelay, this.hideControlsTimer = defaultHideControlsTimer, - this.progressIndicatorDelayMs, }) : assert( playbackSpeeds.every((speed) => speed > 0), 'The playbackSpeeds values must all be greater than 0', @@ -382,7 +381,6 @@ class ChewieController extends ChangeNotifier { hideControlsTimer: hideControlsTimer ?? this.hideControlsTimer, progressIndicatorDelay: progressIndicatorDelay ?? this.progressIndicatorDelay, - hideControlsTimer: hideControlsTimer ?? this.hideControlsTimer, ); } From 491becd4b52ace80055b9c1a73e3f761f32f5be8 Mon Sep 17 00:00:00 2001 From: "h.carnot" Date: Tue, 7 Jun 2022 10:31:14 +0200 Subject: [PATCH 13/13] fix: change video type --- example/lib/app/app.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/lib/app/app.dart b/example/lib/app/app.dart index c24c18373..41175ad78 100644 --- a/example/lib/app/app.dart +++ b/example/lib/app/app.dart @@ -42,7 +42,7 @@ class _ChewieDemoState extends State { } List srcs = [ - "https://upload.wikimedia.org/wikipedia/commons/2/2c/Earth_rotation_during_Galileo_flyby_%28PIA00114%29_%28color-adjusted%29.webm", + "https://assets.mixkit.co/videos/preview/mixkit-spinning-around-the-earth-29351-large.mp4", "https://assets.mixkit.co/videos/preview/mixkit-daytime-city-traffic-aerial-view-56-large.mp4", "https://assets.mixkit.co/videos/preview/mixkit-a-girl-blowing-a-bubble-gum-at-an-amusement-park-1226-large.mp4" ];