大家好,我需要你的帮助。我有个问题。我只想在横向模式下实现全屏播放器。
并将视频播放器页面留在后退按钮或离开全屏。没有 fullScreenByDefault: true 一切似乎都很好。我可以按后退按钮并返回上一个屏幕。
但是,如果它设置为 true,就会出现问题。按下后退按钮或最小化按钮会进入纵向模式 1 秒钟,然后返回横向,接下来是纵向模式。Next 终于关闭了这个页面。我希望在第一个后退按钮后关闭页面或离开全屏。而且我不知道出了什么问题。提前感谢您的帮助。
VideoPlayer({this.title, this.url, this.isLive = false});
final String title;
final String url;
final bool isLive;
@override
State<StatefulWidget> createState() {
return _VideoPlayerState();
}
}
class _VideoPlayerState extends State<VideoPlayer> {
VideoPlayerController _videoPlayerController1;
ChewieController _chewieController;
@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: _videoPlayerController1.value.aspectRatio,
autoPlay: true,
looping: true,
fullScreenByDefault: true,
isLive: widget.isLive,
allowedScreenSleep: false,
deviceOrientationsAfterFullScreen: [
DeviceOrientation.landscapeRight,
DeviceOrientation.landscapeLeft,
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
]
}
@override
Widget build(BuildContext context) {
SystemChrome.setPreferredOrientations([
DeviceOrientation.landscapeRight,
DeviceOrientation.landscapeLeft,
]);
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: SafeArea(
child: Expanded(
child: Chewie(
controller: _chewieController,
),
),
),
);
}
@override
void dispose() {
_chewieController.dispose();
_videoPlayerController1.dispose();
SystemChrome.setPreferredOrientations([
DeviceOrientation.landscapeRight,
DeviceOrientation.landscapeLeft,
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
]);
super.dispose();
}
}