# openPlayer method

Future<FlutterSoundPlayer?> openPlayer({

1. dynamic isBGService = false,

})

Open the Player.

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

## Return

Returns a Future, but the App does not need to wait the completion of this future before doing a startPlayer(). The Future will be automaticaly waited by startPlayer().

## Example

        myPlayer = await FlutterSoundPlayer().openPlayer();

        ...
        (do something with myPlayer)
        ...

        await myPlayer.closePlayer();
        myPlayer = null;

## See also

- closePlayer()

## Implementation

    Future<FlutterSoundPlayer?> openPlayer({isBGService = false}) async {
      //if (!Platform.isIOS && enableVoiceProcessing) {
      //throw ('VoiceProcessing is only available on iOS');
      //}

      if (_isInited != Initialized.notInitialized) {
        return this;
      }

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

      Future<FlutterSoundPlayer?>? r;
      await _lock.synchronized(() async {
        r = _openPlayer();
      });
      return r;
    }