几秒钟后如何停止录像?

时间:2019-11-25 13:31:01

标签: flutter dart

我正在使用image_picker录制视频。我想在20秒后停止录制。有什么办法可以在20秒后停止录制。

 _pickVideoFromCamera() async {
    File video = await ImagePicker.pickVideo(source: ImageSource.camera);
    _cameraVideo = video;
    _cameraVideoPlayerController = VideoPlayerController.file(_cameraVideo)
      ..initialize().then((_) {
        _cameraVideoPlayerController.play();
        setState(() {});
      });
  }

1 个答案:

答案 0 :(得分:0)

您可以使用Future.delayed

_pickVideoFromCamera() async {
    File video = await ImagePicker.pickVideo(source: ImageSource.camera);
    _cameraVideo = video;
    _cameraVideoPlayerController = VideoPlayerController.file(_cameraVideo)
      ..initialize().then((_) {
        _cameraVideoPlayerController.play();
        setState(() {});
      });
    Future.delayed(Duration(seconds: 20)).then((_) { // camera stop process });
  }