flutter - 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();
}
解决方案
推荐阅读
- c# - 如何从 SQliteConnection c# Xamarin Android 中列出表名
- python - Django-allauth 将注册限制为电子邮件列表
- python - 如何在python中从未来检索任务?
- macos - 导出 PDF:找不到字体
- c++ - 为什么 i = ++i + 2 是未定义的行为?
- python - 3种python库中的MFCC和delta系数
- tensorflow - Sagemaker ImportError:不支持按文件名导入
- sql - 如何在sql的多行临时表中插入数据
- java - 使用 jdbc 时出错
- javascript - 将 mysql_insert_id 从 PHP 传递到 AJAX