Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 颤振:视频播放器裁剪/覆盖_Flutter_Flutter Video Player - Fatal编程技术网

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
上居中
无效。有什么想法吗