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/lib/src/chewie_player.dart b/lib/src/chewie_player.dart index c149741ba..f35d4b521 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,11 @@ class ChewieState extends State { context, rootNavigator: widget.controller.useRootNavigator, ).push(route); + + if (kIsWeb) { + _reInitializeControllers(); + } + _isFullScreen = false; widget.controller.exitFullScreen(); @@ -232,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 diff --git a/lib/src/material/material_desktop_controls.dart b/lib/src/material/material_desktop_controls.dart index 404031653..2e1a92d9c 100644 --- a/lib/src/material/material_desktop_controls.dart +++ b/lib/src/material/material_desktop_controls.dart @@ -485,40 +485,39 @@ 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((_) { + //[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(); } - }); + } } void _startHideTimer() { 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: