Skip to content

Commit

Permalink
Merge pull request fluttercommunity#547 from shiyiya/master
Browse files Browse the repository at this point in the history
Fix full screen listener fluttercommunity#266
  • Loading branch information
Ahmadre authored Nov 25, 2021
2 parents 6daf1fa + d2aa99f commit 439fa44
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 12 deletions.
32 changes: 26 additions & 6 deletions example/lib/app/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,16 @@ class _ChewieDemoState extends State<ChewieDemo> {
super.dispose();
}

List<String> srcs = [
"https://assets.mixkit.co/videos/preview/mixkit-daytime-city-traffic-aerial-view-56-large.mp4",
"https://assets.mixkit.co/videos/preview/mixkit-a-girl-blowing-a-bubble-gum-at-an-amusement-park-1226-large.mp4"
];

Future<void> initializePlayer() async {
_videoPlayerController1 = VideoPlayerController.network(
'https://assets.mixkit.co/videos/preview/mixkit-daytime-city-traffic-aerial-view-56-large.mp4',
);
_videoPlayerController2 = VideoPlayerController.network(
'https://assets.mixkit.co/videos/preview/mixkit-a-girl-blowing-a-bubble-gum-at-an-amusement-park-1226-large.mp4',
);
_videoPlayerController1 =
VideoPlayerController.network(srcs[currPlayIndex]);
_videoPlayerController2 =
VideoPlayerController.network(srcs[currPlayIndex]);
await Future.wait([
_videoPlayerController1.initialize(),
_videoPlayerController2.initialize()
Expand Down Expand Up @@ -108,6 +111,15 @@ class _ChewieDemoState extends State<ChewieDemo> {
autoPlay: true,
looping: true,

additionalOptions: (context) {
return <OptionItem>[
OptionItem(
onTap: toggleVideo,
iconData: Icons.live_tv_sharp,
title: 'Toggle Video Src',
),
];
},
subtitle: Subtitles(subtitles),
subtitleBuilder: (context, dynamic subtitle) => Container(
padding: const EdgeInsets.all(10.0),
Expand Down Expand Up @@ -137,6 +149,14 @@ class _ChewieDemoState extends State<ChewieDemo> {
);
}

int currPlayIndex = 0;

Future<void> toggleVideo() async {
await _videoPlayerController1.pause();
currPlayIndex = currPlayIndex == 0 ? 1 : 0;
await initializePlayer();
}

@override
Widget build(BuildContext context) {
return MaterialApp(
Expand Down
19 changes: 13 additions & 6 deletions lib/src/chewie_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ class Chewie extends StatefulWidget {
}

class ChewieState extends State<Chewie> {
bool _isFullScreen = false;
bool _isFullScreen = false;

bool get isControllerFullScreen => widget.controller.isFullScreen;
late PlayerNotifier notifier;

@override
Expand All @@ -62,15 +64,20 @@ class ChewieState extends State<Chewie> {
widget.controller.addListener(listener);
}
super.didUpdateWidget(oldWidget);
if (_isFullScreen != isControllerFullScreen) {
widget.controller._isFullScreen = _isFullScreen;
}
}

Future<void> listener() async {
if (widget.controller.isFullScreen && !_isFullScreen) {
_isFullScreen = true;
if (isControllerFullScreen && !_isFullScreen) {
_isFullScreen = isControllerFullScreen;
await _pushFullScreenWidget(context);
} else if (_isFullScreen) {
Navigator.of(context, rootNavigator: true).pop();
_isFullScreen = false;
} else if (!isControllerFullScreen && _isFullScreen) {
if (Navigator.of(context).canPop()) {
Navigator.of(context, rootNavigator: true).pop();
_isFullScreen = isControllerFullScreen;
}
}
}

Expand Down

0 comments on commit 439fa44

Please sign in to comment.