# openRecorder method

Future<FlutterSoundRecorder?> openRecorder({

1. dynamic isBGService = false,

})

Open a Recorder

A recorder must be opened before used. Opening a recorder takes resources inside the system. Those resources are freed with the verb `closeRecorder()`.

Overload your widget's `dispose()` method to close the recorder when your widget is disposed. In this way you will reset the Recorder and clean up the device resources, and the recorder will be no longer usable.

    @override
    void dispose()
    {
            if (myRecorder != null)
            {
                myRecorder.closeRecorder();
                myRecorder = null;
            }
            super.dispose();
    }

## Parameters

- FIXME : document `isBGService` parameter

## Return

openRecorder() returns Futures. You do not need to wait the end of the initialization before startRecorder(). It will automatically wait the end of `openRecorder()` before starting the recorder.

## Example:

        myRecorder = await FlutterSoundRecorder().openRecorder();

        ...
        (do something with myRecorder)
        ...

        myRecorder.closeRecorder();
        myRecorder = null;

## See also

- closeRecorder()

## Implementation

    Future<FlutterSoundRecorder?> openRecorder({isBGService = false}) async {
      if (_isInited != Initialized.notInitialized) {
        return this;
      }

      if (isBGService) {
        await MethodChannel(
          "xyz.canardoux.flutter_sound_bgservice",
        ).invokeMethod("setBGService");
      }

      Future<FlutterSoundRecorder?>? r;
      _logger.d('FS:---> openRecorder ');
      await _lock.synchronized(() async {
        r = _openAudioSession();
      });
      _logger.d('FS:<--- openAudioSession ');
      return r;
    }