如何切换到下一个视频抖动

时间:2020-08-22 22:17:34

标签: flutter

我正在快速创建视频播放器,我需要知道视频何时结束才能播放下一个视频,我找到了几个示例,但它们对我没有用

这是我的代码

  const switched = useRef(cookies.darkTheme == "true"? true: false);
  const [darkState, setDarkState] = useState(switched);

2 个答案:

答案 0 :(得分:0)

您可以添加一个侦听器

_videoController = VideoPlayerController.network(
      _urlVideo ?? 'https://flutter.github.io/assets-for-api-docs/assets/videos/bee.mp4'
    );
    _chewieController = ChewieController(
      videoPlayerController: _videoController,
      aspectRatio: 3/2,
      autoPlay: false,
      looping: true,
      allowFullScreen: true,
      cupertinoProgressColors: ChewieProgressColors(),
    )..addListener((){

    //do anything you want with _chewieController in listener. for example :
       if(_chewieController.videoPlayerController.value.position == finalPosition){
           var _position = _chewieController.videoPlayerController.value.position;
           var _duration = _chewieController.videoPlayerController.value.duration;
           if(_duration?.compareTo(_position) == 0 || _duration?.compareTo(_position) == -1){
              _playOtherVideo();
           }
       }  
    });

答案 1 :(得分:0)

您可以设置loop:false

然后,当播放结束时,用下一个视频触发另一个play

如果需要,可以在完成的事件中做您想做的事情。