Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Web] fix exit full screen issue #810

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
diegotori marked this conversation as resolved.
Show resolved Hide resolved
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
Loading