ZaraclaJ / audio_recorder

Other
180 stars 128 forks source link

Exception when trying to record #23

Open shinayser opened 5 years ago

shinayser commented 5 years ago

When I press my button that start the recording I get this exception: I am running on a motorola Android device Moto G5S

D/AudioRecorder(29157): Start D/AudioRecorder(29157): /storage/emulated/0.m4a E/AudioRecorder(29157): prepare() failed E/MediaRecorder(29157): start called in an invalid state: 4 E/MethodChannel#audio_recorder(29157): Failed to handle method call E/MethodChannel#audio_recorder(29157): java.lang.IllegalStateException E/MethodChannel#audio_recorder(29157): at android.media.MediaRecorder.start(Native Method) E/MethodChannel#audio_recorder(29157): at com.jordanalcaraz.audiorecorder.audiorecorder.AudioRecorderPlugin.startRecording(AudioRecorderPlugin.java:107) E/MethodChannel#audio_recorder(29157): at com.jordanalcaraz.audiorecorder.audiorecorder.AudioRecorderPlugin.onMethodCall(AudioRecorderPlugin.java:59) E/MethodChannel#audio_recorder(29157): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:191) E/MethodChannel#audio_recorder(29157): at io.flutter.view.FlutterNativeView.handlePlatformMessage(FlutterNativeView.java:163) E/MethodChannel#audio_recorder(29157): at android.os.MessageQueue.nativePollOnce(Native Method) E/MethodChannel#audio_recorder(29157): at android.os.MessageQueue.next(MessageQueue.java:323) E/MethodChannel#audio_recorder(29157): at android.os.Looper.loop(Looper.java:136) E/MethodChannel#audio_recorder(29157): at android.app.ActivityThread.main(ActivityThread.java:6165) E/MethodChannel#audio_recorder(29157): at java.lang.reflect.Method.invoke(Native Method) E/MethodChannel#audio_recorder(29157): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:888) E/MethodChannel#audio_recorder(29157): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:778)

My code that executes the recording is:

void _recordingButtonClick() async {
    Directory dir = await path.getExternalStorageDirectory();

    print("has permission: ${await AudioRecorder.hasPermissions}");

    if (await AudioRecorder.hasPermissions) {
      if (isRecording) {
        AudioRecorder.stop();

        setState(() {
          isRecording = false;
        });

      } else {
        AudioRecorder.start(
            path: dir.path, audioOutputFormat: AudioOutputFormat.AAC);

        setState(() {
          isRecording = true;
        });

      }
    } else {
      await SimplePermissions.requestPermission(Permission.RecordAudio);
      await SimplePermissions.requestPermission(Permission.WriteExternalStorage);
    }
  }
jonataslaw commented 5 years ago

Same issue on moto z2

jonataslaw commented 5 years ago

Issue solved with storage permission

shinewanna commented 4 years ago

First step: Please make sure your dir.path is not getting null otherwise go for second step Second step: Add on path "${dir.path}/AppNameOrWhatEver,