record icon indicating copy to clipboard operation
record copied to clipboard

Error prompted when recreating controller

Open Grrravity opened this issue 2 years ago • 4 comments

Package version 4.4.1

Description When recording multiple things and disposing / initializing my Record() instance, I'm prompted with a warning message that seems like an error.

Reproducing

  1. I record something from page B ( final recorder = Record(); is initialized in my view controller)
  2. I get back to the previous page A with disposing my controller
  3. I push again page B then this message is prompted :
Error Domain=AVFoundationErrorDomain Code=-11806 "Recording Stopped" UserInfo={AVErrorRecordingSuccessfullyFinishedKey=true, NSLocalizedDescription=Recording Stopped, NSLocalizedRecoverySuggestion=Try recording again.}

Expected behavior No warning / error message prompted

Desktop (please complete the following information):

  • OS: macos
  • Version Monterey 12.6 with m1 pro

Additional context

Saw quite the same issue in here. https://github.com/gardner-lab/video-capture/issues/12 The guy has attached the MR that fixed it. Hope it'll help

my impl here : https://github.com/Grrravity/promptme/blob/master/lib/view/projects/prepare/controller/prepare_controller.dart

Grrravity avatar Oct 12 '22 20:10 Grrravity

Thanks for the report,

To be sure, this is only a disturbing message when you want to start or restart a recording? There is no issue about the actual recording, right?

llfbandit avatar Oct 16 '22 11:10 llfbandit

Yes, it works perfectly fine anyway.

I'm not 100% sure but it seems to be prompted when closing the app too.

Grrravity avatar Oct 16 '22 21:10 Grrravity

I just checked your code, I don't see anywhere when you dispose the recorder. According to your reproducing steps, when you return to page A something is recording and never stopped or disposed.

llfbandit avatar Oct 17 '22 16:10 llfbandit

Haven't pushed it yet, i was trying to fix the message.

check this if you wish :

//import ...blablabla
class PrepareController extends GetxController
    with StateMixin<RxStatus>, YamlMixin {
    //... many vars
  late final Record recorder; // Made it late

  @override
  void onInit() {
    recorder = Record(); //Init here
    change(null, status: RxStatus.loading());
    super.onInit();
  }

  @override
  Future<void> onReady() async {
  //...blablabla
    super.onReady();
  }
//... many functions

  Future<void> record() async {
    // Check and request permission
    if (await recorder.hasPermission() && !(await recorder.isRecording())) {
      isRecording.value = true;
      isPauseRecording.value = false;
      // Start recording
      final date =
          DateFormat('yyyy-MM-dd_HH-mm-ss-SSSS').format(DateTime.now());
      await recorder.start(
        path: projects.first.entity.path.replaceAllMapped(
          projects.first.name,
          (match) => 'promptme_rec_$date.m4a',
        ),
        numChannels: 1,
      );
    }
  }

  Future<void> stopRecord() async {
    if (await recorder.isRecording()) {
      isRecording.value = false;
      isPauseRecording.value = false;
      await recorder.stop();
    }
  }

  Future<void> playPause() async {
    if (isPauseRecording.value) {
      await unPauseRecord();
    } else {
      await pauseRecord();
    }
  }

  Future<void> pauseRecord() async {
    if (isRecording.value) {
      isPauseRecording.value = true;
      await recorder.pause();
    }
  }

  Future<void> unPauseRecord() async {
    if (isRecording.value) {
      isPauseRecording.value = false;
      await recorder.resume();
    }
  }

  void retry() {
    onInit();
  }

  @override
  Future<void> onClose() async {
    await recorder.dispose(); //Disposed here
  }
}

Regarding the current implementation, there's a way to get back without stopping recording but as i'm using it for myself, i always stop it before going back. I'll secure this later on

Grrravity avatar Oct 17 '22 17:10 Grrravity

Available in v5-beta.1. The message is now filtered. AVFoundation returns this message as an error which not...

llfbandit avatar Jun 05 '23 10:06 llfbandit