Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stopping a recording immediately after starting it throws multiple exceptions on Android #260

Conversation

mschudt
Copy link
Contributor

@mschudt mschudt commented Jan 15, 2024

This bug happened when calling stop immediately after start (few hundred milliseconds max).
Fixed this by catching the RuntimeException from the MediaRecorder stop call and returning null for path and -1 for duration.

E/flutter ( 9041): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(error, null, null, java.lang.IllegalStateException
E/flutter ( 9041): 	at android.media.MediaRecorder.getMaxAmplitude(Native Method)
E/flutter ( 9041): 	at com.simform.audio_waveforms.AudioRecorder.getDecibel(AudioRecorder.kt:35)
E/flutter ( 9041): 	at com.simform.audio_waveforms.AudioWaveformsPlugin.onMethodCall(AudioWaveformsPlugin.kt:68)
E/flutter ( 9041): 	at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:258)
E/flutter ( 9041): 	at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295)
E/flutter ( 9041): 	at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:322)
E/flutter ( 9041): 	at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12)
E/flutter ( 9041): 	at android.os.Handler.handleCallback(Handler.java:942)
E/flutter ( 9041): 	at android.os.Handler.dispatchMessage(Handler.java:99)
E/flutter ( 9041): 	at android.os.Looper.loopOnce(Looper.java:240)
E/flutter ( 9041): 	at android.os.Looper.loop(Looper.java:351)
E/flutter ( 9041): 	at android.app.ActivityThread.main(ActivityThread.java:8423)
E/flutter ( 9041): 	at java.lang.reflect.Method.invoke(Native Method)
E/flutter ( 9041): 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:584)
E/flutter ( 9041): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1013)
E/flutter ( 9041): )
E/MediaRecorder( 9041): getMaxAmplitude called in an invalid state: 32
E/MethodChannel#simform_audio_waveforms_plugin/methods( 9041): Failed to handle method call
E/MethodChannel#simform_audio_waveforms_plugin/methods( 9041): java.lang.IllegalStateException
E/MethodChannel#simform_audio_waveforms_plugin/methods( 9041): 	at android.media.MediaRecorder.getMaxAmplitude(Native Method)
E/MethodChannel#simform_audio_waveforms_plugin/methods( 9041): 	at com.simform.audio_waveforms.AudioRecorder.getDecibel(AudioRecorder.kt:35)
E/MethodChannel#simform_audio_waveforms_plugin/methods( 9041): 	at com.simform.audio_waveforms.AudioWaveformsPlugin.onMethodCall(AudioWaveformsPlugin.kt:68)
E/MethodChannel#simform_audio_waveforms_plugin/methods( 9041): 	at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:258)
E/MethodChannel#simform_audio_waveforms_plugin/methods( 9041): 	at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295)
E/MethodChannel#simform_audio_waveforms_plugin/methods( 9041): 	at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:322)
E/MethodChannel#simform_audio_waveforms_plugin/methods( 9041): 	at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12)
E/MethodChannel#simform_audio_waveforms_plugin/methods( 9041): 	at android.os.Handler.handleCallback(Handler.java:942)
E/MethodChannel#simform_audio_waveforms_plugin/methods( 9041): 	at android.os.Handler.dispatchMessage(Handler.java:99)
E/MethodChannel#simform_audio_waveforms_plugin/methods( 9041): 	at android.os.Looper.loopOnce(Looper.java:240)
E/MethodChannel#simform_audio_waveforms_plugin/methods( 9041): 	at android.os.Looper.loop(Looper.java:351)
E/MethodChannel#simform_audio_waveforms_plugin/methods( 9041): 	at android.app.ActivityThread.main(ActivityThread.java:8423)
E/MethodChannel#simform_audio_waveforms_plugin/methods( 9041): 	at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#simform_audio_waveforms_plugin/methods( 9041): 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:584)
E/MethodChannel#simform_audio_waveforms_plugin/methods( 9041): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1013)

@ujas-m-simformsolutions ujas-m-simformsolutions merged commit 142855e into SimformSolutionsPvtLtd:main Mar 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants