ZaraclaJ / audio_recorder

Other
180 stars 127 forks source link

Getting error 'MediaRecorder: start called in an invalid state: 4' #65

Open eldarj opened 3 years ago

eldarj commented 3 years ago

Hello there,

I'm getting this error when I call AudioRecorder.start()

D/AudioRecorder( 3981): Start
D/AudioRecorder( 3981): Instance of 'Future<String>'.m4a
I/MediaRecorderJNI( 3981): setup
I/MediaRecorderJNI( 3981): setAudioSource(1)
I/MediaRecorderJNI( 3981): setAudioEncoder(3)
E/AudioRecorder( 3981): prepare() failed
I/MediaRecorderJNI( 3981): start
E/MediaRecorder( 3981): start called in an invalid state: 4
E/MethodChannel#audio_recorder( 3981): Failed to handle method call
E/MethodChannel#audio_recorder( 3981): java.lang.IllegalStateException
E/MethodChannel#audio_recorder( 3981):  at android.media.MediaRecorder._start(Native Method)
E/MethodChannel#audio_recorder( 3981):  at android.media.MediaRecorder.start(MediaRecorder.java:1405)
E/MethodChannel#audio_recorder( 3981):  at com.jordanalcaraz.audiorecorder.audiorecorder.AudioRecorderPlugin.startNormalRecording(AudioRecorderPlugin.java:116)
E/MethodChannel#audio_recorder( 3981):  at com.jordanalcaraz.audiorecorder.audiorecorder.AudioRecorderPlugin.startRecording(AudioRecorderPlugin.java:99)
E/MethodChannel#audio_recorder( 3981):  at com.jordanalcaraz.audiorecorder.audiorecorder.AudioRecorderPlugin.onMethodCall(AudioRecorderPlugin.java:60)
E/MethodChannel#audio_recorder( 3981):  at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:226)
E/MethodChannel#audio_recorder( 3981):  at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85)
E/MethodChannel#audio_recorder( 3981):  at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:631)
E/MethodChannel#audio_recorder( 3981):  at android.os.MessageQueue.nativePollOnce(Native Method)
E/MethodChannel#audio_recorder( 3981):  at android.os.MessageQueue.next(MessageQueue.java:336)
E/MethodChannel#audio_recorder( 3981):  at android.os.Looper.loop(Looper.java:197)
E/MethodChannel#audio_recorder( 3981):  at android.app.ActivityThread.main(ActivityThread.java:7814)
E/MethodChannel#audio_recorder( 3981):  at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#audio_recorder( 3981):  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
E/MethodChannel#audio_recorder( 3981):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1075)
E/flutter ( 3981): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: PlatformException(error, null, null)
E/flutter ( 3981): #0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:569:7)
E/flutter ( 3981): #1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:156:18)
E/flutter ( 3981): <asynchronous suspension>
E/flutter ( 3981): #2      MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:329:12)
E/flutter ( 3981): #3      AudioRecorder.start (package:audio_recorder/audio_recorder.dart:44:10)
E/flutter ( 3981): <asynchronous suspension>
E/flutter ( 3981): #4      SingleChatInputRow.startRecording (package:flutterping/activity/chats/component/single-chat/partial/chat-input-row.component.dart:35:25)
E/flutter ( 3981): #5      SingleChatInputRow.build.<anonymous closure> (package:flutterping/activity/chats/component/single-chat/partial/chat-input-row.component.dart:117:30)
E/flutter ( 3981): #6      GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:182:24)
E/flutter ( 3981): #7      TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:504:11)
E/flutter ( 3981): #8      BaseTapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:282:5)
E/flutter ( 3981): #9      BaseTapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:217:7)
E/flutter ( 3981): #10     PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:475:9)
E/flutter ( 3981): #11     PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:76:12)
E/flutter ( 3981): #12     PointerRouter._dispatchEventToRoutes.<anonymous closure> (package:flutter/src/gestures/pointer_router.dart:122:9)
E/flutter ( 3981): #13     _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:379:8)
E/flutter ( 3981): #14     PointerRouter._dispatchEventToRoutes (package:flutter/src/gestures/pointer_router.dart:120:18)
E/flutter ( 3981): #15     PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:106:7)
E/flutter ( 3981): #16     GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:218:19)
E/flutter ( 3981): #17     GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:198:22)
E/flutter ( 3981): #18     GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:156:7)
E/flutter ( 3981): #19     GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:102:7)
E/flutter ( 3981): #20     GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:86:7)
E/flutter ( 3981): #21     _rootRunUnary (dart:async/zone.dart:1196:13)
E/flutter ( 3981): #22     _CustomZone.runUnary (dart:async/zone.dart:1085:19)
E/flutter ( 3981): #23     _CustomZone.runUnaryGuarded (dart:async/zone.dart:987:7)
E/flutter ( 3981): #24     _invoke1 (dart:ui/hooks.dart:275:10)
E/flutter ( 3981): #25     _dispatchPointerDataPacket (dart:ui/hooks.dart:184:5)
E/flutter ( 3981): 

I also noted that AudioRecorder.hasPermissions returns false, even tho I gave the microphone permission.

Any thoughts please?

javadkt commented 3 years ago

Make sure you given WRITE_EXTERNAL_STORAGE permission also and start recording by passing the path in parameter.

Ex:

          Directory appDocDirectory = await getApplicationDocumentsDirectory();
          String path = appDocDirectory.path + '/' + 'testfile.aac';
          await AudioRecorder.start(path: path);
GauravCalidig commented 2 years ago

https://pub.dev/packages/audio_recorder_nullsafety