Canardoux / flutter_sound

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

[HELP]: onProgress Stream is not consistent in between pause and start recording #741

Open Haidar0096 opened 3 years ago

Haidar0096 commented 3 years ago

I need Help for :


Here is my question :

I am using BLoC pattern, I send to my UI a Stream so they can display the time elapsed since I started recording, and that time should be stopped if the recorder is paused, and then continued when the recorder is resumed again.

My approach now is to map the onProgress Stream to a new Stream and use StreamBuilder in the UI to update the progress.

However, when I pause then resume the recording, the onProgress Stream starts sending durations again starting from zero, as if it had forgotten the real progress that was reached.

Is this inconsistent behaviour intended or Am I using the API wrong?

I can provide sample code if requested

Larpoux commented 3 years ago

No. If I understand you clearly this is no intended. If you look to the Demo Example, you can see that the onProgress stream is correctly paused and resumed with the Pause button. Are you sure not to call startRecorder() instead of resumeRecorder() ?

Yes, sample code can be useful. Also :

Haidar0096 commented 3 years ago
await _recorder.openAudioSession();
      _recorder.setSubscriptionDuration(
        Duration(milliseconds: 100),
      ); //rate at which duration updates are fired
      _durationStream = _recorder.onProgress!.map((event) =>
          event.duration); //this is the stream that I return to my UI

This code is inside my startRecorder

 await _recorder.startRecorder(
      toFile: path,
    );

This code is inside my resumeRecorder

await _recorder.resumeRecorder();
            Duration last =
                previousRecorderState.durationSinceStart ?? Duration.zero;
            _recorderState = RecorderState.recording(
                durationSinceStart:
                    _durationStream!.map((event) => last + event));//here I tried to get the last element of the onProgress stream and add it to every element emitted in the new onProgress stream, assuming as I said in the post, it is resetting after resume, but this didn't work even
Haidar0096 commented 3 years ago

And also a note: the documentation is not very helpful alot of times

For example here on the website of tau project in the section of onProgress it mentions a link to what is supposed to be a simple demo about using onProgress, but if you go to the link (on github) you find a simple demo about the usage of the recorder but without any mentioning of the onProgress. I know it maybe take you alot of time to fix the documentation but I just wanted to shed the light on this problem.

Larpoux commented 3 years ago

the section of onProgress it mentions a link to what is supposed to be a simple demo about using onProgress, but if you go to the link (on github) you find a simple demo about the usage of the recorder but without any mentioning of the onProgress

You are right. The links on this page are wrong.

Where is your Pull Request ?

dizzersee commented 1 year ago

@Haidar0096 Were you able to resolve the issue?

Haidar0096 commented 1 year ago

@Haidar0096 Were you able to resolve the issue?

It's been a while, but I don't remember solving it.

github-actions[bot] commented 8 months ago

This issue is stale because it has been open 90 days with no activity. Leave a comment or this will be closed in 7 days.