Flutter 颤振:视频播放器裁剪/覆盖
我试图在一个容器中显示一个视频,视频可能会超过容器的纵横比,所以需要对其进行裁剪 对于图像,它很简单:Flutter 颤振:视频播放器裁剪/覆盖,flutter,flutter-video-player,Flutter,Flutter Video Player,我试图在一个容器中显示一个视频,视频可能会超过容器的纵横比,所以需要对其进行裁剪 对于图像,它很简单: Image.network(someUrl, fit: BoxFit.cover) 但是如何使用视频播放器 我当前的代码如下所示: Stack( children: [ Container( width: double.infinity, height: double.infi
Image.network(someUrl, fit: BoxFit.cover)
但是如何使用视频播放器
我当前的代码如下所示:
Stack(
children: [
Container(
width: double.infinity,
height: double.infinity,
child: ShowcaseVideoPlayer(someUrl)
),
Material(
color: Colors.transparent,
child: InkWell(
onTap: () {},
),
),
],);
class ShowcaseVideoPlayer extends StatefulWidget {
final String url;
ShowcaseVideoPlayer(this.url);
@override
_ShowcaseVideoPlayerState createState() => _ShowcaseVideoPlayerState();
}
class _ShowcaseVideoPlayerState extends State<ShowcaseVideoPlayer> {
VideoPlayerController _controller;
Future<void> _initializeVideoPlayerFuture;
@override
void initState() {
_controller = VideoPlayerController.network(widget.url);
_initializeVideoPlayerFuture = _controller.initialize();
_controller.setVolume(0);
super.initState();
}
@override
Widget build(BuildContext context) {
return FutureBuilder(
future: _initializeVideoPlayerFuture,
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
_controller.play();
// If the VideoPlayerController has finished initialization, use
// the data it provides to limit the aspect ratio of the VideoPlayer.
return AspectRatio(
aspectRatio: _controller.value.aspectRatio,
// Use the VideoPlayer widget to display the video.
child: VideoPlayer(_controller),
);
} else {
// If the VideoPlayerController is still initializing, show a
// loading spinner.
return Center(),
);
}
},
);
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
}
Stack(
children: [
OverflowBox(
child: Wrap(
children: [
ShowcaseVideoPlayer(someUrl)
],
),
)]);
现在,视频实际上被裁剪了,但没有居中(我看到的是视频的上半部分,而不是中央部分)。将包裹
放在中间
并设置对齐:对齐。在OverfowBox
上居中
无效。有什么想法吗