From 4406b0e09e983f2a5ee62da301d441774c974494 Mon Sep 17 00:00:00 2001 From: toddZeil Date: Thu, 18 Jan 2024 17:34:48 +1300 Subject: [PATCH 1/5] Add fix for returning from full screen web --- lib/src/chewie_player.dart | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/src/chewie_player.dart b/lib/src/chewie_player.dart index c149741ba..b790460a8 100644 --- a/lib/src/chewie_player.dart +++ b/lib/src/chewie_player.dart @@ -6,6 +6,7 @@ import 'package:chewie/src/models/options_translation.dart'; import 'package:chewie/src/models/subtitle_model.dart'; import 'package:chewie/src/notifiers/player_notifier.dart'; import 'package:chewie/src/player_with_controls.dart'; +import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:provider/provider.dart'; @@ -166,6 +167,18 @@ class ChewieState extends State { context, rootNavigator: widget.controller.useRootNavigator, ).push(route); + + if (kIsWeb) { + final prevPosition = + widget.controller.videoPlayerController.value.position; + widget.controller.videoPlayerController.initialize().then((_) async { + widget.controller._initialize(); + widget.controller.videoPlayerController.seekTo(prevPosition); + await widget.controller.videoPlayerController.play(); + widget.controller.videoPlayerController.pause(); + }); + } + _isFullScreen = false; widget.controller.exitFullScreen(); From d58b737c50be0ba0d2502d97eadde1f793050b91 Mon Sep 17 00:00:00 2001 From: toddZeil Date: Thu, 18 Jan 2024 17:37:13 +1300 Subject: [PATCH 2/5] Refactor un needed set states, refactor play if finished( as video player restarts if finished) --- .../material/material_desktop_controls.dart | 45 +++++++++---------- 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/lib/src/material/material_desktop_controls.dart b/lib/src/material/material_desktop_controls.dart index 404031653..e271b2665 100644 --- a/lib/src/material/material_desktop_controls.dart +++ b/lib/src/material/material_desktop_controls.dart @@ -485,40 +485,37 @@ class _MaterialDesktopControlsState extends State void _onExpandCollapse() { setState(() { notifier.hideStuff = true; + }); - chewieController.toggleFullScreen(); - _showAfterExpandCollapseTimer = - Timer(const Duration(milliseconds: 300), () { - setState(() { - _cancelAndRestartTimer(); - }); + chewieController.toggleFullScreen(); + + _showAfterExpandCollapseTimer = + Timer(const Duration(milliseconds: 300), () { + setState(() { + _cancelAndRestartTimer(); }); }); } void _playPause() { - final isFinished = _latestValue.position >= _latestValue.duration; - - setState(() { - if (controller.value.isPlaying) { + if (controller.value.isPlaying) { + setState(() { notifier.hideStuff = false; - _hideTimer?.cancel(); - controller.pause(); - } else { - _cancelAndRestartTimer(); + }); - if (!controller.value.isInitialized) { - controller.initialize().then((_) { - controller.play(); - }); - } else { - if (isFinished) { - controller.seekTo(Duration.zero); - } + _hideTimer?.cancel(); + controller.pause(); + } else { + _cancelAndRestartTimer(); + + if (!controller.value.isInitialized) { + controller.initialize().then((_) { controller.play(); - } + }); + } else { + controller.play(); } - }); + } } void _startHideTimer() { From 827f58f651a4488e96ef3f8bffcf195ffb3773d7 Mon Sep 17 00:00:00 2001 From: toddZeil Date: Thu, 18 Jan 2024 17:43:30 +1300 Subject: [PATCH 3/5] Add documentation --- lib/src/chewie_player.dart | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/lib/src/chewie_player.dart b/lib/src/chewie_player.dart index b790460a8..f35d4b521 100644 --- a/lib/src/chewie_player.dart +++ b/lib/src/chewie_player.dart @@ -169,14 +169,7 @@ class ChewieState extends State { ).push(route); if (kIsWeb) { - final prevPosition = - widget.controller.videoPlayerController.value.position; - widget.controller.videoPlayerController.initialize().then((_) async { - widget.controller._initialize(); - widget.controller.videoPlayerController.seekTo(prevPosition); - await widget.controller.videoPlayerController.play(); - widget.controller.videoPlayerController.pause(); - }); + _reInitializeControllers(); } _isFullScreen = false; @@ -245,6 +238,18 @@ class ChewieState extends State { } } } + + ///When viewing full screen on web, returning from full screen causes original video to lose the picture. + ///We re initialise controllers for web only when returning from full screen + void _reInitializeControllers() { + final prevPosition = widget.controller.videoPlayerController.value.position; + widget.controller.videoPlayerController.initialize().then((_) async { + widget.controller._initialize(); + widget.controller.videoPlayerController.seekTo(prevPosition); + await widget.controller.videoPlayerController.play(); + widget.controller.videoPlayerController.pause(); + }); + } } /// The ChewieController is used to configure and drive the Chewie Player From c682c2adf1fc1a2ce74edaad6818f4b255644716 Mon Sep 17 00:00:00 2001 From: toddZeil Date: Thu, 18 Jan 2024 17:51:07 +1300 Subject: [PATCH 4/5] update version and changelog --- CHANGELOG.md | 3 +++ pubspec.yaml | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fa40e61bb..bdbce6475 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 1.7.5 +* 🛠️ [#810](https://github.com/fluttercommunity/chewie/pull/810): Fixed : Web full screen issue (#790 #688). Thanks [ToddZeil](https://github.com/ToddZeil). + ## 1.7.4 * 🛠️ [#774](https://github.com/fluttercommunity/chewie/pull/774): Fixed : Playback speed reset on forwarding video. Thanks [Kronos-2701](https://github.com/Kronos-2701). diff --git a/pubspec.yaml b/pubspec.yaml index 120c91f40..cbd1057f6 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: chewie description: A video player for Flutter with Cupertino and Material play controls -version: 1.7.4 +version: 1.7.5 homepage: http://github.com/fluttercommunity/chewie environment: From 44fe634343824f52c669c4f293d5e5ddeba4bcbd Mon Sep 17 00:00:00 2001 From: toddZeil Date: Mon, 22 Jan 2024 14:25:04 +1300 Subject: [PATCH 5/5] Add documentation to the play function --- lib/src/material/material_desktop_controls.dart | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/src/material/material_desktop_controls.dart b/lib/src/material/material_desktop_controls.dart index e271b2665..2e1a92d9c 100644 --- a/lib/src/material/material_desktop_controls.dart +++ b/lib/src/material/material_desktop_controls.dart @@ -510,9 +510,11 @@ class _MaterialDesktopControlsState extends State if (!controller.value.isInitialized) { controller.initialize().then((_) { + //[VideoPlayerController.play] If the video is at the end, this method starts playing from the beginning controller.play(); }); } else { + //[VideoPlayerController.play] If the video is at the end, this method starts playing from the beginning controller.play(); } }