首页 > 解决方案 > Flutter 录音 onProgress 流返回 null

问题描述

我想使用 flutter_sound 在我的颤振应用程序中可视化录制的声音强度。我在未来的构建器中监听 onProgress 流,它应该在录制打开时返回值分贝。问题是流总是返回 null!

  StreamBuilder<RecordingDisposition>(
                  stream: _recorder!.onProgress,
                  builder: (context, snapshot) {
                    log.debug(snapshot.data);
                    if (!snapshot.hasData || snapshot.data == null) {
                      return Container(
                        width: 120,
                        color: Colors.green,
                      );
                    }
                    return Container(
                        width: 120,
                        child: Container(
                          color: Colors.red,
                          width: snapshot.data!.decibels,
                        ));
                  }),

这是我在其中初始化记录器的代码。

  Future<void> openTheRecorder() async {
var status = await Permission.microphone.request();
if (status != PermissionStatus.granted) {
  throw RecordingPermissionException('Microphone permission not granted');
}

await _recorder!.openAudioSession(
  focus: AudioFocus.requestFocusAndDuckOthers,
  category: SessionCategory.record,
);


 this.record();
}

标签: flutterstreamstream-buildervoice-recording

解决方案


推荐阅读