1

我正在使用VideoPlayer包在我的应用程序中显示 .mp4。我可以很容易地通过添加来循环它_controller.setLooping(true);。但是,我无法使用此软件包创建回旋镖效果。你有任何想法如何实现它吗?

在这里你可以得到我的示例代码:

class DashboardVideoBackground extends StatefulWidget {
  DashboardVideoBackground({Key key}) : super(key: key);

  @override
  State<StatefulWidget> createState() => _DashboardVideoBackgroundState();
}

class _DashboardVideoBackgroundState extends State<DashboardVideoBackground> {
  VideoPlayerController _controller;
  Future<void> _initializeVideoPlayerFuture;

  @override
  void initState() {
    _controller =
        VideoPlayerController.asset('assets/mock/dashboard_background.mp4');
    _initializeVideoPlayerFuture = _controller.initialize();
    _controller.setLooping(true);

    _controller.play();
    super.initState();
  }

  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return LayoutBuilder(
      builder: (context, constraints) {
        return FutureBuilder(
          future: _initializeVideoPlayerFuture,
          builder: (context, snapshot) =>
              snapshot.connectionState == ConnectionState.done
                  ? OverflowBox(
                      maxWidth: double.infinity,
                      maxHeight: double.infinity,
                      alignment: Alignment.center,
                      child: FittedBox(
                        fit: BoxFit.cover,
                        alignment: Alignment.center,
                        child: Container(
                          width: MediaQuery.of(context).size.width * 1.5,
                          height: MediaQuery.of(context).size.height,
                          child: VideoPlayer(_controller),
                        ),
                      ),
                    )
                  : Center(child: CircularProgressIndicator()),
        );
      },
    );
  }
}
4

0 回答 0