Flutter-全屏video_player [英] Flutter - video_player fullscreen
问题描述
我在Flutter项目上使用了名为 video_player 的插件.我可以正常播放和暂停视频,但我想使其全屏和水平播放.我找不到与此相关的任何内容.
I'm using a plugin called video_player on my Flutter project. I'm able to play and pause videos without a problem, but I want to make it fullscreen and horizontal. I couldn't find anything related to this.
这是我正在使用的基本代码:
This is the basic code I'm using:
playerController = VideoPlayerController.network(
"<VIDEO_URL>")
..addListener(listener)
..setVolume(1.0)
..initialize()
..play();
我可以全屏显示吗?
推荐答案
据我了解,VideoPlayer对它的位置一无所知,而只是将其扩展到最大以适应给定的空间.
As far as I understand, the VideoPlayer doesn't know anything about where it is, but rather just expands to fit within the given space the best it can.
我相信您要使用的是 RotatedBox
作为视频的父级,并设置旋转值.根据您的应用程序的工作方式,您可能希望视频播放器水平和小尺寸启动,并具有一个全屏按钮,可以切换到横向模式.但是,如果将应用程序本身设置为旋转,则必须将其考虑在内,并且在手机水平旋转后才取消旋转视频,这可能会导致抖动旋转而导致UI出现丑陋现象,并且您取消旋转视频.
I believe what you want to do is use a RotatedBox
as a parent of the video and set the rotation value. Depending on how exactly your app works, you may want to have the video player start horizontal and small, and have a full screen button that switches to landscape mode. However, if the app itself is set up to rotate you'll have to take that into account and un-rotate the video once the phone has been rotated horizontally, which will probably result in uglyness in the UI as the flutter rotation happens and you un-rotate the video.
您可能还希望使用对话框将视频全屏显示,以便您可以将其关闭并返回到原来的屏幕.
You probably also want to use a dialog to show the video full-screen so that you can dismiss it and get back to the screen you were at.
我可能会提供更多指导,但这要取决于您使用哪种方式(将应用程序锁定为纵向模式并手动旋转)还是使用flutter的内置旋转方式.
I could probably provide a bit more guidance but it does depend on which way you go with that (either locking the app to portrait mode and doing the rotation manually) vs using flutter's built-in rotation.
这篇关于Flutter-全屏video_player的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!