Not*_*ros 3 video fullscreen flutter
我在Flutter项目上使用了名为video_player的插件。我可以正常播放和暂停视频,但我想使其全屏和水平播放。我找不到与此相关的任何内容。
这是我正在使用的基本代码:
playerController = VideoPlayerController.network(
"<VIDEO_URL>")
..addListener(listener)
..setVolume(1.0)
..initialize()
..play();
Run Code Online (Sandbox Code Playgroud)
我可以全屏播放吗?
Nhậ*_*rần 12
我对这个问题有另一种情况,那就是使用Chewie插件,你可以在这里安装它:https : //pub.dev/packages/chewie 这是我实现它的代码:
VideoPlayerController _videoPlayerController;
ChewieController _chewieController;
double _aspectRatio = 16 / 9;
@override
initState() {
super.initState();
print(widget.videoUrl);
_videoPlayerController = VideoPlayerController.network(widget.videoUrl);
_chewieController = ChewieController(
allowedScreenSleep: false,
allowFullScreen: true,
deviceOrientationsAfterFullScreen: [
DeviceOrientation.landscapeRight,
DeviceOrientation.landscapeLeft,
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
],
videoPlayerController: _videoPlayerController,
aspectRatio: _aspectRatio,
autoInitialize: true,
autoPlay: true,
showControls: true,
);
_chewieController.addListener(() {
if (_chewieController.isFullScreen) {
SystemChrome.setPreferredOrientations([
DeviceOrientation.landscapeRight,
DeviceOrientation.landscapeLeft,
]);
} else {
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
]);
}
});
}
Run Code Online (Sandbox Code Playgroud)
记住退出页面后恢复设备的方向:
@override
void dispose() {
_videoPlayerController.dispose();
_chewieController.dispose();
SystemChrome.setPreferredOrientations([
DeviceOrientation.landscapeRight,
DeviceOrientation.landscapeLeft,
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
]);
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Container(
child: Chewie(
controller: _chewieController,
),
),
),
);
}
Run Code Online (Sandbox Code Playgroud)
据我了解,VideoPlayer对它的位置一无所知,而只是将其扩展到最大以适应给定的空间。
我相信您想要做的是使用a RotatedBox作为视频的父级并设置旋转值。根据您的应用程序的工作方式,您可能希望视频播放器从水平和小角度开始,并具有一个全屏按钮,可以切换到横向模式。但是,如果将应用程序本身设置为旋转,则必须将其考虑在内,并且在手机水平旋转后才能取消旋转视频,这可能会导致抖动旋转而导致UI出现丑陋现象,并且您取消旋转视频。
您可能还想使用一个对话框来全屏显示视频,以便您可以将其关闭并返回到原来的屏幕。
我可能会提供更多指导,但这确实取决于您使用哪种方式(将应用程序锁定为纵向模式并手动进行旋转)与使用flutter的内置旋转。
| 归档时间: |
|
| 查看次数: |
2993 次 |
| 最近记录: |