There is a problem with onRecorderStateChanged on ios
See original GitHub issueWhen I first record and play what I just recorded, and then I click on record again, onRecorderStateChanged has a 0 result all the way and cannot be recorded ‘’’ import ‘dart:io’;
import ‘package:chongmeng/constants/constants.dart’; import ‘package:chongmeng/utils/date_utils.dart’; import ‘package:flutter/material.dart’; import ‘package:flutter_sound/flutter_sound_player.dart’; import ‘package:flutter_sound/flutter_sound_recorder.dart’; import ‘package:intl/intl.dart’; import ‘package:path_provider/path_provider.dart’;
class PlayPage extends StatefulWidget { @override _PlayPageState createState() => _PlayPageState(); }
class _PlayPageState extends State<PlayPage> { FlutterSoundPlayer soundPlayer; FlutterSoundRecorder soundRecorder; var recorderSubscription; var result;
@override void initState() { super.initState(); init(); }
init() async { soundPlayer = await FlutterSoundPlayer().initialize(); soundRecorder = await FlutterSoundRecorder().initialize(); }
void _onStartRecord() async {
showToast(“_onStartRecord
”);
Directory tempDir = await getTemporaryDirectory();
File outputFile =
File(‘${tempDir.path}/${DateUtils.currentTimeMillis()}.aac’);
result = outputFile.path;
String a = await soundRecorder.startRecorder(uri: outputFile.path);
recorderSubscription = soundRecorder.onRecorderStateChanged.listen((e) {
DateTime date =
new DateTime.fromMillisecondsSinceEpoch(e.currentPosition.toInt());
String txt = DateFormat('mm:ss:SS', 'en_US').format(date);
// if (txt.contains(“00:02”)) { // _onStopRecord(); // } }); soundRecorder.onRecorderDbPeakChanged.listen((value) { print(“got update -> $value”); }); }
Future<void> _onStopRecord() async {
showToast(“_onStopRecord
”);
print("_onStopRecord ");
String localUrl = await soundRecorder.stopRecorder();
if (recorderSubscription != null) {
recorderSubscription.cancel();
recorderSubscription = null;
}
}
@override void dispose() { soundRecorder.release(); soundPlayer.release(); super.dispose(); }
_onStartPlay() async {
showToast(“_onStartPlay
”);
soundPlayer.startPlayer(this.result);
}
@override Widget build(BuildContext context) { return Container( child: Column( children: <Widget>[ IconButton( icon: Icon(Icons.record_voice_over), onPressed: () { _onStartRecord(); }, ), Padding( padding: const EdgeInsets.symmetric(vertical: 24), child: RaisedButton( child: Text(“OK”), onPressed: () { _onStopRecord(); }, ), ), IconButton( icon: Icon(Icons.play_arrow), onPressed: () { _onStartPlay(); }, ), ], ), ); } }
‘’’
Issue Analytics
- State:
- Created 3 years ago
- Comments:18 (1 by maintainers)
Top GitHub Comments
Hi @Gibsouille ,
could you look to V 4.0.5 and see if better ?
Hi @zhangruiyu , I am glad that the issue is fixed. I am really sorry for the delay : the problem occurred on real devices and not the simulator. It was not easy for us to debug that.
Good luck, using Flutter Sound. 😄