Canardoux / flutter_sound

Flutter plugin for sound. Audio recorder and player.
Mozilla Public License 2.0
850 stars 553 forks source link

[BUG]: BasicLock.synchronized io.flutter.plugins.firebase.crashlytics.FlutterError - PlatformException(startRecorder, startRecorder, Failure to start recorder, null) #1026

Open nergal79 opened 2 months ago

nergal79 commented 2 months ago

Using -> flutter_sound: ^9.4.6

We are getting this crash on One Plus Android 9 device .

Crash Stacktrace -> Fatal Exception: io.flutter.plugins.firebase.crashlytics.FlutterError: PlatformException(error, null, null, java.lang.IllegalStateException at android.media.MediaRecorder.native_resume(Native Method) at android.media.MediaRecorder.resume(MediaRecorder.java:1205) at gc.o.d(Unknown Source:15) at gc.k.n(Unknown Source:7) at hc.e.G(Unknown Source:2) at hc.f.E(Unknown Source:218) at s9.j$a.a(Unknown Source:17) at g9.c.l(Unknown Source:18) at g9.c.m(Unknown Source:41) at g9.c.i(Unknown Source:0) at g9.b.run(Unknown Source:12) at android.os.Handler.handleCallback(Handler.java:873) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:193) at android.app.ActivityThread.main(ActivityThread.java:6898) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:537) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) ) at StandardMethodCodec.decodeEnvelope(message_codecs.dart:651) at MethodChannel._invokeMethod(platform_channel.dart:334) at FlutterSoundRecorder._resumeRecorder(flutter_sound_recorder.dart:832) at FlutterSoundRecorder.resumeRecorder.<fn>(flutter_sound_recorder.dart:813) at BasicLock.synchronized(basic_lock.dart:33) at FlutterSoundRecorder.resumeRecorder(flutter_sound_recorder.dart:812) at _AudioRecorderModal._resume(audio_recorder_modal.dart:260)

Below is the config we are using to record.

`_setupRecorder() async {
   await TheAudioPlayer().pauseAll();
await recorder.openRecorder();
final session = await AudioSession.instance;
await session.configure(AudioSessionConfiguration(
  avAudioSessionCategory: AVAudioSessionCategory.record,
  avAudioSessionCategoryOptions:
      AVAudioSessionCategoryOptions.allowBluetooth |
          AVAudioSessionCategoryOptions.defaultToSpeaker,
  avAudioSessionMode: AVAudioSessionMode.spokenAudio,
  avAudioSessionRouteSharingPolicy:
      AVAudioSessionRouteSharingPolicy.defaultPolicy,
  avAudioSessionSetActiveOptions: AVAudioSessionSetActiveOptions.none,
  androidAudioAttributes: const AndroidAudioAttributes(
    contentType: AndroidAudioContentType.speech,
    flags: AndroidAudioFlags.none,
    usage: AndroidAudioUsage.voiceCommunication,
  ),
  androidAudioFocusGainType: AndroidAudioFocusGainType.gain,
  androidWillPauseWhenDucked: true,
));
recorder.setSubscriptionDuration(const Duration(milliseconds: 250));
await _start();
 }` 

I m not sure if this is a device specific issue or a library issue .. Any help here would be appreciated .. If u need any further detail just ask

Larpoux commented 2 months ago

@nergal79

'''java.lang.IllegalStateException at android.media.MediaRecorder.native_resume(Native Method)'''

Are you sure that your Recorder is in Pause State when you call the Resume() function ?

Larpoux commented 2 months ago

Your problem is probably in _AudioRecorderModal._resume(audio_recorder_modal.dart:260). You probably call RecorderResume() here but you recorder is not in pause mode.

nergal79 commented 2 months ago

@Larpoux Thx for quick reply.. Yeah I am sure Recorder is in Pause State when i call Resume() function .. its working fine in other devices .. This crash is reported on firebase crashlytics for our app only for one device .. Which is the Model:OnePlus5T Android 9 .

Larpoux commented 2 months ago

If you do not encounter this issue always, it could be a problem with Async functions. The crash is because Android is asked to resume the recorder but its device is not in pause mode. You should look very carefully to your asynchronous processing.

Sorry but I cannot help better.

nergal79 commented 2 months ago

Thanks for your inputs .. I'll do some deep investigation for this. Cheers 🍺.