FULL
Important: Result of the command : flutter pub deps | grep flutter_sound
|-- flutter_sound 8.1.1
| |-- flutter...
| |-- flutter_sound_platform_interface 8.1.1
| | |-- flutter...
| | |-- meta...
| | '-- plugin_platform_interface...
| |-- flutter_sound_web 8.1.1
| | |-- flutter...
| | |-- flutter_sound_platform_interface...
| | |-- flutter_web_plugins...
| | |-- js...
| | '-- meta...
| |-- flutter_spinkit 5.0.0
| | '-- flutter...
| |-- logger 1.0.0
| |-- path...
| |-- path_provider...
| |-- provider 5.0.0
| | |-- collection...
| | |-- flutter...
| | '-- nested 1.0.0
| | '-- flutter...
Describe the bug
When click on record, the first time, it throws me a error, and does not record, but if i close the screen and do it a second time it works.
To Reproduce
here are some code snippets to reproduce
final flutterSoundRecorder = FlutterSoundRecorder();
/// Somewhere in a button
FormButton(
label: Text(
'Record Audio',
),
onPressed: () async {
await flutterSoundRecorder.openAudioSession(
focus: AudioFocus.requestFocusAndDuckOthers,
);
await flutterSoundRecorder.startRecorder(
toFile: track.trackPath,
codec: track.codec
);
flutterSoundRecorder
.dispositionStream()
.listen((event) {
recordDuration.value = event.duration;
});
},
icon: Icon(Icons.mic),
)
I can confirm the audio permissions were already given
I/flutter (24534): FS:---> openAudioSession
I/flutter (24534): ---> openAudioSession
I/flutter (24534): Resetting flutter_sound Recorder Plugin
E/MethodChannel#com.dooboolab.flutter_sound_recorder(24534): Failed to handle method call
E/MethodChannel#com.dooboolab.flutter_sound_recorder(24534): java.lang.IllegalStateException: Reply already submitted
E/MethodChannel#com.dooboolab.flutter_sound_recorder(24534): at io.flutter.embedding.engine.dart.DartMessenger$Reply.reply(DartMessenger.java:155)
E/MethodChannel#com.dooboolab.flutter_sound_recorder(24534): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler$1.success(MethodChannel.java:238)
E/MethodChannel#com.dooboolab.flutter_sound_recorder(24534): at com.dooboolab.fluttersound.FlutterSoundManager.resetPlugin(FlutterSoundManager.java:112)
E/MethodChannel#com.dooboolab.flutter_sound_recorder(24534): at com.dooboolab.fluttersound.FlutterSoundRecorderManager.onMethodCall(FlutterSoundRecorderManager.java:81)
E/MethodChannel#com.dooboolab.flutter_sound_recorder(24534): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:233)
E/MethodChannel#com.dooboolab.flutter_sound_recorder(24534): at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85)
E/MethodChannel#com.dooboolab.flutter_sound_recorder(24534): at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:818)
E/MethodChannel#com.dooboolab.flutter_sound_recorder(24534): at android.os.MessageQueue.nativePollOnce(Native Method)
E/MethodChannel#com.dooboolab.flutter_sound_recorder(24534): at android.os.MessageQueue.next(MessageQueue.java:336)
E/MethodChannel#com.dooboolab.flutter_sound_recorder(24534): at android.os.Looper.loop(Looper.java:181)
E/MethodChannel#com.dooboolab.flutter_sound_recorder(24534): at android.app.ActivityThread.main(ActivityThread.java:7562)
E/MethodChannel#com.dooboolab.flutter_sound_recorder(24534): at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#com.dooboolab.flutter_sound_recorder(24534): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
E/MethodChannel#com.dooboolab.flutter_sound_recorder(24534): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
E/DartMessenger(24534): Uncaught exception in binary message listener
E/DartMessenger(24534): java.lang.IllegalStateException: Reply already submitted
E/DartMessenger(24534): at io.flutter.embedding.engine.dart.DartMessenger$Reply.reply(DartMessenger.java:155)
E/DartMessenger(24534): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:253)
E/DartMessenger(24534): at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85)
E/DartMessenger(24534): at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:818)
E/DartMessenger(24534): at android.os.MessageQueue.nativePollOnce(Native Method)
E/DartMessenger(24534): at android.os.MessageQueue.next(MessageQueue.java:336)
E/DartMessenger(24534): at android.os.Looper.loop(Looper.java:181)
E/DartMessenger(24534): at android.app.ActivityThread.main(ActivityThread.java:7562)
E/DartMessenger(24534): at java.lang.reflect.Method.invoke(Native Method)
E/DartMessenger(24534): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
E/DartMessenger(24534): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
E/flutter (24534): [ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: type 'String' is not a subtype of type 'int?' in type cast
E/flutter (24534): #0 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:158:41)
E/flutter (24534): <asynchronous suspension>
E/flutter (24534): #1 FlutterSoundRecorder._openAudioSession (package:flutter_sound/public/flutter_sound_recorder.dart:393:9)
E/flutter (24534): <asynchronous suspension>
E/flutter (24534): #2 FlutterSoundRecorder.openAudioSession.<anonymous closure> (package:flutter_sound/public/flutter_sound_recorder.dart:355:11)
E/flutter (24534): <asynchronous suspension>
E/flutter (24534): #3 BasicLock.synchronized (package:synchronized/src/basic_lock.dart:33:16)
E/flutter (24534): <asynchronous suspension>
E/flutter (24534): #4 FlutterSoundRecorder.openAudioSession (package:flutter_sound/public/flutter_sound_recorder.dart:354:5)
E/flutter (24534): <asynchronous suspension>
E/flutter (24534): #5 _ReportScreenState.buildAudioDescriptionForm.<anonymous closure> (package:reporter/screens/report_screen/report_screen.dart:576:27)
E/flutter (24534): <asynchronous suspension>
E/flutter (24534):
That should be fixed with my pull request #677
Hey @satyajitghana, i am facing the exact error in version 8.1.4. can you share how you resolve the issue ?!
@Yash-Aervadiya
Future<String> getTempAudioFile() async {
var uuid = Uuid();
String path;
var tmpDir = await getTemporaryDirectory();
path = '${join(tmpDir.path, uuid.v4())}.m4a';
var parent = dirname(path);
Directory(parent).createSync(recursive: true);
return path;
}
Future<void> resetAudioTrack() async {
String path = await getTempAudioFile();
recordingFile = path;
track = Track(trackPath: recordingFile, codec: Codec.aacMP4);
// setState(() {});
}
and then on the record button you do something like this
FormButton(
label: Text(
'Record Audio',
),
onPressed: () async {
/// just to be extra safe
await resetAudioTrack();
await flutterSoundRecorder.openAudioSession(
focus: AudioFocus.requestFocusAndDuckOthers,
);
await flutterSoundRecorder.startRecorder(
toFile: track.trackPath,
codec: track.codec
);
flutterSoundRecorder
.dispositionStream()
.listen((event) {
recordDuration.value = event.duration;
});
},
icon: Icon(Icons.mic),
)
and this is the stop button
FormButton(
label: Text(
'Stop',
),
onPressed: () async {
await flutterSoundRecorder.stopRecorder();
await flutterSoundRecorder.closeAudioSession();
I'm not sure why, but this works for me. I still get some memory leaks, but that is something that many other things could have caused.
Most helpful comment
That should be fixed with my pull request #677