Skip to content

Commit 915e6fa

Browse files
authored
Merge pull request #810 from ToddZeil/web_fix_exit_full_screen_issue
[Web] fix exit full screen issue
2 parents f165258 + 44fe634 commit 915e6fa

File tree

4 files changed

+45
-25
lines changed

4 files changed

+45
-25
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 1.7.5
2+
* 🛠️ [#810](https://github.com/fluttercommunity/chewie/pull/810): Fixed : Web full screen issue (#790 #688). Thanks [ToddZeil](https://github.com/ToddZeil).
3+
14
## 1.7.4
25
* 🛠️ [#774](https://github.com/fluttercommunity/chewie/pull/774): Fixed : Playback speed reset on forwarding video. Thanks [Kronos-2701](https://github.com/Kronos-2701).
36

lib/src/chewie_player.dart

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import 'package:chewie/src/models/options_translation.dart';
66
import 'package:chewie/src/models/subtitle_model.dart';
77
import 'package:chewie/src/notifiers/player_notifier.dart';
88
import 'package:chewie/src/player_with_controls.dart';
9+
import 'package:flutter/foundation.dart';
910
import 'package:flutter/material.dart';
1011
import 'package:flutter/services.dart';
1112
import 'package:provider/provider.dart';
@@ -166,6 +167,11 @@ class ChewieState extends State<Chewie> {
166167
context,
167168
rootNavigator: widget.controller.useRootNavigator,
168169
).push(route);
170+
171+
if (kIsWeb) {
172+
_reInitializeControllers();
173+
}
174+
169175
_isFullScreen = false;
170176
widget.controller.exitFullScreen();
171177

@@ -232,6 +238,18 @@ class ChewieState extends State<Chewie> {
232238
}
233239
}
234240
}
241+
242+
///When viewing full screen on web, returning from full screen causes original video to lose the picture.
243+
///We re initialise controllers for web only when returning from full screen
244+
void _reInitializeControllers() {
245+
final prevPosition = widget.controller.videoPlayerController.value.position;
246+
widget.controller.videoPlayerController.initialize().then((_) async {
247+
widget.controller._initialize();
248+
widget.controller.videoPlayerController.seekTo(prevPosition);
249+
await widget.controller.videoPlayerController.play();
250+
widget.controller.videoPlayerController.pause();
251+
});
252+
}
235253
}
236254

237255
/// The ChewieController is used to configure and drive the Chewie Player

lib/src/material/material_desktop_controls.dart

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -485,40 +485,39 @@ class _MaterialDesktopControlsState extends State<MaterialDesktopControls>
485485
void _onExpandCollapse() {
486486
setState(() {
487487
notifier.hideStuff = true;
488+
});
488489

489-
chewieController.toggleFullScreen();
490-
_showAfterExpandCollapseTimer =
491-
Timer(const Duration(milliseconds: 300), () {
492-
setState(() {
493-
_cancelAndRestartTimer();
494-
});
490+
chewieController.toggleFullScreen();
491+
492+
_showAfterExpandCollapseTimer =
493+
Timer(const Duration(milliseconds: 300), () {
494+
setState(() {
495+
_cancelAndRestartTimer();
495496
});
496497
});
497498
}
498499

499500
void _playPause() {
500-
final isFinished = _latestValue.position >= _latestValue.duration;
501-
502-
setState(() {
503-
if (controller.value.isPlaying) {
501+
if (controller.value.isPlaying) {
502+
setState(() {
504503
notifier.hideStuff = false;
505-
_hideTimer?.cancel();
506-
controller.pause();
507-
} else {
508-
_cancelAndRestartTimer();
504+
});
509505

510-
if (!controller.value.isInitialized) {
511-
controller.initialize().then((_) {
512-
controller.play();
513-
});
514-
} else {
515-
if (isFinished) {
516-
controller.seekTo(Duration.zero);
517-
}
506+
_hideTimer?.cancel();
507+
controller.pause();
508+
} else {
509+
_cancelAndRestartTimer();
510+
511+
if (!controller.value.isInitialized) {
512+
controller.initialize().then((_) {
513+
//[VideoPlayerController.play] If the video is at the end, this method starts playing from the beginning
518514
controller.play();
519-
}
515+
});
516+
} else {
517+
//[VideoPlayerController.play] If the video is at the end, this method starts playing from the beginning
518+
controller.play();
520519
}
521-
});
520+
}
522521
}
523522

524523
void _startHideTimer() {

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: chewie
22
description: A video player for Flutter with Cupertino and Material play controls
3-
version: 1.7.4
3+
version: 1.7.5
44
homepage: http://github.com/fluttercommunity/chewie
55

66
environment:

0 commit comments

Comments
 (0)