为什么 VideoPlayer 中的视频不是全屏的?
Why the Video is not fullscreen in VideoPlayer in flutter?
我复制粘贴了VideoPlayer package的例子,但是网页上不是全屏,请问如何解决。
示例代码
import 'package:video_player/video_player.dart';
import 'package:flutter/material.dart';
class HomeScreen extends StatefulWidget {
const HomeScreen({Key? key}) : super(key: key);
@override
_HomeScreenState createState() => _HomeScreenState();
}
class _HomeScreenState extends State<HomeScreen> {
late VideoPlayerController _controller;
@override
void initState() {
super.initState();
_controller = VideoPlayerController.network(
'https://assets.mixkit.co/videos/preview/mixkit-womans-hands-decorating-a-handmade-soap-2803-large.mp4')
..initialize().then((_) {
// Ensure the first frame is shown after the video is initialized, even before the play button has been pressed.
setState(() {});
})
..play()
..setLooping(true);
}
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Video Demo',
home: Scaffold(
body: _controller.value.isInitialized
? AspectRatio(
aspectRatio: _controller.value.aspectRatio,
child: VideoPlayer(_controller),
)
: Container(),
),
);
}
@override
void dispose() {
super.dispose();
_controller.dispose();
}
}
OutPut
如果您勾选 _controller.value.aspectRatio,
,value
来自视频。
视频根据其 aspectRatio
而非屏幕的纵横比播放。
我用LayoutBuilder
获取屏幕尺寸,你也用MediaQuery
。
在这种情况下 homme:
就像
home: Scaffold(
body: LayoutBuilder(
builder: (context, constraints) => _controller.value.isInitialized
? AspectRatio(
aspectRatio: constraints.maxWidth / constraints.maxHeight,
// _controller.value.aspectRatio,
child: VideoPlayer(_controller),
)
: Container(),
),
),
结果
is you are thinking about Top and bottom spaces here, is empty because of it is beyond video aspectRatio.
我为此使用了堆栈,它非常适合我。
基于此视频:
我复制粘贴了VideoPlayer package的例子,但是网页上不是全屏,请问如何解决。
示例代码
import 'package:video_player/video_player.dart';
import 'package:flutter/material.dart';
class HomeScreen extends StatefulWidget {
const HomeScreen({Key? key}) : super(key: key);
@override
_HomeScreenState createState() => _HomeScreenState();
}
class _HomeScreenState extends State<HomeScreen> {
late VideoPlayerController _controller;
@override
void initState() {
super.initState();
_controller = VideoPlayerController.network(
'https://assets.mixkit.co/videos/preview/mixkit-womans-hands-decorating-a-handmade-soap-2803-large.mp4')
..initialize().then((_) {
// Ensure the first frame is shown after the video is initialized, even before the play button has been pressed.
setState(() {});
})
..play()
..setLooping(true);
}
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Video Demo',
home: Scaffold(
body: _controller.value.isInitialized
? AspectRatio(
aspectRatio: _controller.value.aspectRatio,
child: VideoPlayer(_controller),
)
: Container(),
),
);
}
@override
void dispose() {
super.dispose();
_controller.dispose();
}
}
OutPut
如果您勾选 _controller.value.aspectRatio,
,value
来自视频。
视频根据其 aspectRatio
而非屏幕的纵横比播放。
我用LayoutBuilder
获取屏幕尺寸,你也用MediaQuery
。
在这种情况下 homme:
就像
home: Scaffold(
body: LayoutBuilder(
builder: (context, constraints) => _controller.value.isInitialized
? AspectRatio(
aspectRatio: constraints.maxWidth / constraints.maxHeight,
// _controller.value.aspectRatio,
child: VideoPlayer(_controller),
)
: Container(),
),
),
结果
is you are thinking about Top and bottom spaces here, is empty because of it is beyond video aspectRatio.
我为此使用了堆栈,它非常适合我。 基于此视频: