Chewie: "autoFullScreenOnLandscape" + "autoLandscapeOnFullScreen"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:async'; | |
import 'package:flutter/cupertino.dart'; | |
import 'package:flutter/material.dart'; | |
import 'package:flutter/services.dart'; | |
import 'package:video_player/video_player.dart'; | |
import 'package:orientation/orientation.dart'; | |
import 'package:chewie/chewie.dart'; | |
import 'package:chewie/src/chewie_player.dart'; | |
void main() { | |
runApp( | |
ChewieDemo(), | |
); | |
} | |
class ChewieDemo extends StatefulWidget { | |
ChewieDemo({this.title = 'Chewie Demo'}); | |
final String title; | |
@override | |
State<StatefulWidget> createState() { | |
return _ChewieDemoState(); | |
} | |
} | |
class _ChewieDemoState extends State<ChewieDemo> { | |
TargetPlatform _platform; | |
VideoPlayerController _videoPlayerController1; | |
ChewieController _chewieController; | |
ChewieFullscreenToggler _toggler; | |
@override | |
void initState() { | |
super.initState(); | |
_videoPlayerController1 = VideoPlayerController.network( | |
'https://flutter.github.io/assets-for-api-docs/assets/videos/butterfly.mp4'); | |
_chewieController = ChewieController( | |
videoPlayerController: _videoPlayerController1, | |
aspectRatio: 3 / 2, | |
autoPlay: true, | |
looping: true, | |
deviceOrientationsAfterFullScreen: [], | |
routePageBuilder: (BuildContext context, Animation<double> animation, Animation<double> secondAnimation, provider) { | |
return AnimatedBuilder( | |
animation: animation, | |
builder: (BuildContext context, Widget child) { | |
return Scaffold( | |
resizeToAvoidBottomInset: false, | |
body: Container( | |
alignment: Alignment.center, | |
color: Colors.black, | |
child: provider, | |
), | |
); | |
}, | |
); | |
}, | |
); | |
_toggler = ChewieFullscreenToggler(_chewieController); | |
WidgetsBinding.instance.addObserver(_toggler); | |
_chewieController.addListener(() { | |
if (_chewieController.isFullScreen && isPortrait) { | |
scheduleMicrotask(() { | |
OrientationPlugin.forceOrientation(DeviceOrientation.landscapeRight); | |
}); | |
} else if (!_chewieController.isFullScreen && !isPortrait) { | |
scheduleMicrotask(() { | |
OrientationPlugin.forceOrientation(DeviceOrientation.portraitUp); | |
}); | |
} | |
}); | |
} | |
@override | |
void dispose() { | |
WidgetsBinding.instance.removeObserver(_toggler); | |
_videoPlayerController1.dispose(); | |
_chewieController.dispose(); | |
super.dispose(); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: widget.title, | |
theme: ThemeData.light().copyWith( | |
platform: _platform ?? Theme.of(context).platform, | |
), | |
home: Scaffold( | |
appBar: AppBar( | |
title: Text(widget.title), | |
), | |
body: Column( | |
children: <Widget>[ | |
Expanded( | |
child: Center( | |
child: Chewie( | |
controller: _chewieController, | |
), | |
), | |
), | |
], | |
), | |
) | |
); | |
} | |
} | |
class ChewieFullscreenToggler extends WidgetsBindingObserver { | |
ChewieFullscreenToggler(this.chewieController) : | |
assert(chewieController != null); | |
final ChewieController chewieController; | |
var _wasPortrait = false; | |
@override | |
void didChangeMetrics() { | |
var _isPortrait = isPortrait; | |
if (_isPortrait == _wasPortrait) { | |
return; | |
} | |
_wasPortrait = _isPortrait; | |
if (!_isPortrait && !chewieController.isFullScreen) { | |
chewieController.enterFullScreen(); | |
} else if (_isPortrait && chewieController.isFullScreen) { | |
chewieController.exitFullScreen(); | |
} | |
} | |
} | |
bool get isPortrait { | |
var size = WidgetsBinding.instance.window.physicalSize; | |
return size.width < size.height; | |
} |
Sorry, I ended up not using Chewie at all, nor I ever had a chance to run this code on Android.
Thanks for your response. What library did you end of using?
I extracted some pieces of Chewie code (primary for the drawing of playback
controls) and currently just using plain video_player with bunch of my
custom code on top of it 🤷♂️
…On Wed, 4 Nov 2020 at 01:43, AliRezaeian ***@***.***> wrote:
***@***.**** commented on this gist.
------------------------------
Thanks for your response. What library did you end of using?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<https://gist.github.com/0a353a8de649b648b3ceff0d8e97f1d7#gistcomment-3515125>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AA47MJ6N2D54U3OLYXGTVC3SOCBPNANCNFSM4SVWD2JA>
.
would you please share the code that you finally used? please
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
Looks like this has a bug in Android. When I landscape the phone it will be fullscreen but when I portrait it does not exit from fullscreen. Is there any way that I can fix it?
Thanks