Skip to content

Commit

Permalink
Merge pull request #810 from ToddZeil/web_fix_exit_full_screen_issue
Browse files Browse the repository at this point in the history
[Web] fix exit full screen issue
  • Loading branch information
diegotori authored Feb 8, 2024
2 parents f165258 + 44fe634 commit 915e6fa
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 25 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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).

Expand Down
18 changes: 18 additions & 0 deletions lib/src/chewie_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -166,6 +167,11 @@ class ChewieState extends State<Chewie> {
context,
rootNavigator: widget.controller.useRootNavigator,
).push(route);

if (kIsWeb) {
_reInitializeControllers();
}

_isFullScreen = false;
widget.controller.exitFullScreen();

Expand Down Expand Up @@ -232,6 +238,18 @@ class ChewieState extends State<Chewie> {
}
}
}

///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
Expand Down
47 changes: 23 additions & 24 deletions lib/src/material/material_desktop_controls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -485,40 +485,39 @@ class _MaterialDesktopControlsState extends State<MaterialDesktopControls>
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() {
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down

0 comments on commit 915e6fa

Please sign in to comment.