mar*_*mar 7 flutter flutter-dependencies flutter-layout
我正在尝试为我的应用程序创建背景视频启动屏幕。目前,我通过运行此代码实现了空白屏幕。
void main() => runApp(WalkThrough());
class WalkThrough extends StatefulWidget {
@override
_WalkThroughState createState() => _WalkThroughState();
}
class _WalkThroughState extends State<WalkThrough> {
VideoPlayerController _controller;
@override
void initState() {
super.initState();
// Pointing the video controller to our local asset.
_controller = VideoPlayerController.asset('assets/video.mp4')
..initialize().then((_) {
// Once the video has been loaded we play the video and set looping to true.
_controller.play();
_controller.setLooping(true);
_controller.setVolume(0.0);
_controller.play();
// Ensure the first frame is shown after the video is initialized.
setState(() {});
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Stack(
children: <Widget>[
Run Code Online (Sandbox Code Playgroud)
我怀疑问题可能就在这里,并且我的研究基于Flutter on Login 中的全屏视频背景,因为我正在尝试实现类似的结果。
SizedBox.expand(
child: FittedBox(
// If your background video doesn't look right, try changing the BoxFit property.
// BoxFit.fill created the look I was going for.
fit: BoxFit.fill,
child: SizedBox(
width: _controller.value.size?.width ?? 0,
height: _controller.value.size?.height ?? 0,
child: VideoPlayer(_controller),
),
),
),
Run Code Online (Sandbox Code Playgroud)
我认为视频播放器包在 Ios 模拟器中显示视频时存在问题。我也遇到了同样的问题,在 Github 上搜索并找到了这个问题。到目前为止,这个问题还没有解决。我在真实设备上测试了视频播放器,没有任何问题。
| 归档时间: |
|
| 查看次数: |
6718 次 |
| 最近记录: |