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

Recorder has not yet been created or has already been disposed #366

Closed
SELiOTe opened this issue Jul 8, 2024 · 1 comment
Closed

Recorder has not yet been created or has already been disposed #366

SELiOTe opened this issue Jul 8, 2024 · 1 comment

Comments

@SELiOTe
Copy link

SELiOTe commented Jul 8, 2024

Package version

record: ^5.1.2

Environment

Development: MacOS 14.5
Debug Device: iOS 15.7

Describe the bug

I have a Button, it will call start or stop record when tap, and it will execute those code

Future<void> _startRecord() async {
  if (!await _audioRecorder.hasPermission()) {
    if (mounted) {
      AppLocalizations.of(context)!.audioRecordWithoutPermission;
    }
    return;
  }
  _recordContentBuilder = BytesBuilder();
  var stream = await _audioRecorder
      .startStream(const RecordConfig(encoder: AudioEncoder.pcm16bits));
  stream.listen((data) async {
    _recordContentBuilder?.add(data.toList());
  });
  _audioRecorder
      .onAmplitudeChanged(const Duration(milliseconds: 100))
      .listen((amplitude) {
    _audioWaveStreamController.sink.add(amplitude.current);
  });
}

Future<void> _stopRecording() async {
  if (!await _audioRecorder.isRecording()) {
    return;
  }
  await _audioRecorder.stop();
  _recordStartTime = null;
  _timer?.cancel();
  _timer = null;
  if (mounted) {
    Navigator.of(context).pop(_recordContentBuilder!.toBytes());
  }
}

when I click this button very quickly, it will continue raise many exception like this

...
[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(record, Recorder has not yet been created or has already been disposed., null, null)
#0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:648:7)
#1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:334:18)
<asynchronous suspension>
#2      RecordMethodChannel.isRecording (package:record_platform_interface/src/record_method_channel.dart:40:20)
<asynchronous suspension>
#3      AudioRecorder._updateAmplitudeAtInterval.shouldUpdate (package:record/src/record.dart:210:24)
<asynchronous suspension>
#4      AudioRecorder._updateAmplitudeAtInterval (package:record/src/record.dart:213:9)
<asynchronous suspension>
[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(record, Recorder has not yet been created or has already been disposed., null, null)
#0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:648:7)
#1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:334:18)
<asynchronous suspension>
#2      RecordMethodChannel.isRecording (package:record_platform_interface/src/record_method_channel.dart:40:20)
<asynchronous suspension>
#3      AudioRecorder._updateAmplitudeAtInterval.shouldUpdate (package:record/src/record.dart:210:24)
<asynchronous suspension>
#4      AudioRecorder._updateAmplitudeAtInterval (package:record/src/record.dart:213:9)
<asynchronous suspension>
...
@SELiOTe
Copy link
Author

SELiOTe commented Jul 13, 2024

Repeated clicks cause _startRecord to enter multiple executions repeatedly. Add a state to avoid this. Thank you to the author.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant