2

I am basically trying to prevent the user from rewinding or forwarding the video via progress slider but user should still be able to pause and play the video and see how many seconds/minutes remains till the end of the video.

How can i achieve this using Chewie package in Flutter?

@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),
        );
      })
    );
  }

Need to disable the blue progress bar

Emre Turan
  • 83
  • 1
  • 8
  • Note: the reason that i asked this question is, it is wanted that the user to watch the full video without skipping and forwarding it. Although i could not figure out how to disable progress slider, i found another way to somehow achieve this goal. I simply set a stopwatch and add a listener to VideoPlayerController. Whenever video plays, stopwatch starts and when video stops/ends, stopwatch stops. Then we can check if the duration of the video is equal to the elapsed time of the stopwatch. – Emre Turan Jul 22 '22 at 08:03

1 Answers1

1

you can did it by use customControls property in ChewieController

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

in CustomMaterialControls, just clone MaterialControls from chewie and you will see that a function called _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,
      ),
    );
  }

You can disable function onDragStart, onHorizontalDragUpdate in VideoProgressBar then you will get your expectation

onHorizontalDragStart: (DragStartDetails details) {
        if (!controller.value.isInitialized|| widget.disableDrag) {
          return;
        }
}
thaovd1712
  • 120
  • 1
  • 1
  • 9