flutter - 如何在flutter中显示录制时间?

标签 flutter camera flutter-dependencies video-capture

如何在 flutter 中显示录制视频的时间。我正在使用camera (^0.9.4+16) 包。

        Future<String?> _startVideoRecording() async {
          
            if (!controller!.value.isInitialized) {
              Fluttertoast.showToast(
                  msg: 'Please wait',
                  toastLength: Toast.LENGTH_SHORT,
                  gravity: ToastGravity.CENTER,
                  timeInSecForIosWeb: 1,
                  backgroundColor: Colors.grey,
                  textColor: Colors.white);
        
              return null;
            }
            // Do nothing if a recording is on progress
            if (controller!.value.isRecordingVideo) {
        
              return null;
            }
        
            final Directory appDirectory = await getApplicationDocumentsDirectory();
            final String videoDirectory = '${appDirectory.path}/Videos';
            await Directory(videoDirectory).create(recursive: true);
            final String currentTime = DateTime.now().millisecondsSinceEpoch.toString();
            final String filePath = '$videoDirectory/${currentTime}.mp4';
        
            try {
              await controller!.startVideoRecording();
              videoPath = filePath;
            } on CameraException catch (e) {
              _showCameraException(e);
              return null;
            }
        
            return file Path;
          }

这是一个示例 image .

最佳答案

  String recordingTime = '0:0'; // to store value
  bool isRecording = false;

  void recordTime() {
    var startTime = DateTime.now();
    Timer.periodic(const Duration(seconds: 1), (Timer t) {
      var diff = DateTime.now().difference(startTime);

      recordingTime =
          '${diff.inHours < 60 ? diff.inHours : 0}:${diff.inMinutes < 60 ? diff.inMinutes : 0}:${diff.inSeconds < 60 ? diff.inSeconds : 0}';

      print(recordingTime);

      if (!isRecording) {
        t.cancel(); //cancel function calling
      }

      setState(() {});
    });
  }

现在使用录音时间

关于flutter - 如何在flutter中显示录制时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71556791/

相关文章:

flutter - 有没有办法始终在 DropDownButton 中显示提示?

android - OutOfMemoryError 来自在某些设备中拍照 android

flutter - 如何在 flutter 中拖动小部件时实现定位线?

menu - Flutter 中具有 3 页的自定义网格菜单

flutter - 如何在 Flutter 中更改 CupertinoNavigationBar 中后退按钮的颜色

ios - 在 Swift 中使用 AVFoundation 拍摄照片

flutter - 使用 page_transition 更改 Navigator.pop() 动画持续时间

flutter - 用于 Flutter Web 的 folder_picker?

Flutter找不到Android SDK

c# - 错误 : Object is currently in use elsewhere.