dart 如何使用Flutter Chewie软件包禁用倒带和转发视频?

wgx48brx  于 2023-01-10  发布在  Flutter
关注(0)|答案(1)|浏览(269)

我基本上是试图阻止用户通过进度滑块倒带或转发视频,但用户仍然应该能够暂停和播放视频,看看还有多少秒/分钟,直到视频结束。
我怎样才能在Flutter中使用Chewie软件包实现这一点?

@override
  void initState() {
    super.initState();
    _chewieController = ChewieController(
      videoPlayerController: widget.vpController,
      aspectRatio: widget.vpController.value.aspectRatio,
      autoInitialize: true,
      allowFullScreen: true,
      allowPlaybackSpeedChanging: false,
      deviceOrientationsAfterFullScreen: [DeviceOrientation.portraitUp, DeviceOrientation.portraitDown],
      showControls: true,
      playbackSpeeds: [1.0],
      showOptions: false,
      errorBuilder: ((context, errorMessage) {
        return Center(
          child: Text(errorMessage),
        );
      })
    );
  }

vc9ivgsu

vc9ivgsu1#

您可以通过使用ChewieController中的customControls属性来完成此操作

_chewieController = ChewieController(
      videoPlayerController: _videoPlayerController!,
      allowFullScreen: false,
      showOptions: false,
      looping: false,
      autoPlay: true,
      hideControlsTimer: const Duration(seconds: 1),
      customControls: const CustomMaterialControls(
        showPlayButton: false,
      ),
    );

在CustomMaterialControls中,只需从Chewie克隆MaterialControls,您就会看到一个名为_buildProgressBar()函数

Widget _buildProgressBar() {
    return Expanded(
      child: VideoProgressBar(
        controller,
        colors: chewieController.materialProgressColors ??
            ChewieProgressColors(
              playedColor: Theme.of(context).colorScheme.secondary,
              handleColor: Theme.of(context).colorScheme.secondary,
              bufferedColor: Theme.of(context).backgroundColor.withOpacity(0.5),
              backgroundColor: Theme.of(context).disabledColor.withOpacity(.5),
            ),
        handleHeight: 0,
        drawShadow: false,
        barHeight: 4,
      ),
    );
  }

您可以在VideoProgressBar中禁用功能onDragStart、onHorizontalDragUpdate,然后您将获得预期效果

onHorizontalDragStart: (DragStartDetails details) {
        if (!controller.value.isInitialized|| widget.disableDrag) {
          return;
        }
}

相关问题