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

Getting error on dispose (Cannot add new events after calling close) #373

Open
himanshus26 opened this issue Dec 4, 2024 · 1 comment · May be fixed by #379
Open

Getting error on dispose (Cannot add new events after calling close) #373

himanshus26 opened this issue Dec 4, 2024 · 1 comment · May be fixed by #379
Labels
bug Something isn't working

Comments

@himanshus26
Copy link

himanshus26 commented Dec 4, 2024

I'm using this package to implement tap & hold to record audio like whatsapp. when I'm calling stop recording function then its throwing error due to dispose() (Unhandled Exception: Bad state: Cannot add new events after calling close).

Screenshot 2024-12-04 at 4 44 32 PM

Here's my code snippet.

Start Recording >

void startAudioRecording() {
    state =
        state.copyWith(isAudioRecording: true, recorder: RecorderController());
    state.recorder?.record();
    recordAudioListener = () {
      log('Is Recording from addListener  ======>   ${state.recorder?.isRecording}');
      updateRecordTime(time: state.recorder?.elapsedDuration.inSeconds ?? 0);
    };
    state.recorder?.addListener(recordAudioListener!);
  }

Stop Recording >

Future<void> stopAudioRecording() async {
    state = state.copyWith(isAudioRecording: false, dragValue: 0);
    await state.recorder?.pause();
    final audioFile = await state.recorder?.stop();
    final time = state.recorder?.recordedDuration.inSeconds;
    state.recorder?.removeListener(recordAudioListener!);
    log('Duration  ======>  $audioFile   $time');
    if (audioFile != null && (time ?? 0) > 0) {
      await uploadAudioFile(
        file: File(audioFile),
      );
    }
    state.recorder?.dispose();
    state = state.copyWith(recorder: null);
  }
@ujas-m-simformsolutions
Copy link
Collaborator

@himanshus26 Thanks for the reporting this issue. This looks like an edge case that we're adding events to Recorder state stream even though stream is closed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants