flutter - how to resume playing video from previous duration with Chewie controller?

Viewed 494

I have used the Chewie video player plugin to implement a video player.

  1. I want to save the duration when the video is paused/ exit from the video screen and
  2. resume playing from the exact duration the next time I visit the video screen.

    class VideoPlayerScreen extends StatefulWidget {
    @override
     _VideoPlayerScreenState createState() => _VideoPlayerScreenState();
    
    final String video_link;
     VideoPlayerScreen({Key key, @required this.video_link}) : super(key: key);
    }
    
    class _VideoPlayerScreenState extends State<VideoPlayerScreen> {
    
      VideoPlayerController _videoPlayerController;
      ChewieController _chewieController;
    
    @override
    void initState() {
    super.initState();
    _videoPlayerController = VideoPlayerController.network(
        widget.video_link)..initialize().then((_){setState(() {});
        });
    _chewieController = ChewieController(
      allowedScreenSleep: false,
      allowFullScreen: true,
      deviceOrientationsAfterFullScreen: [
        DeviceOrientation.landscapeRight,
        DeviceOrientation.landscapeLeft,
        DeviceOrientation.portraitUp,
        DeviceOrientation.portraitDown,
      ],
      videoPlayerController: _videoPlayerController,
      aspectRatio: 16/9,
      looping: true,
      showControls: true,
    );
    _chewieController.addListener(() {
      if (_chewieController.isFullScreen) {
        SystemChrome.setPreferredOrientations([
          DeviceOrientation.landscapeRight,
          DeviceOrientation.landscapeLeft,
        ]);
      }
    });}
    
    
    @override
    void dispose() {
    _videoPlayerController.dispose();
    _chewieController.dispose();
    SystemChrome.setPreferredOrientations([
      DeviceOrientation.landscapeRight,
      DeviceOrientation.landscapeLeft,
      DeviceOrientation.portraitUp,
      DeviceOrientation.portraitDown,
    ]);
    super.dispose();}
    
0 Answers
Related