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 OS. Those resources are freed with the verb closePlayer(). 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()

On iOS you can pass the enableVoiceProcessing parameter to true to enable the VoiceProcessingIO AudioUnit, this is useful to improving speech audio or VoIP applications.

Example:

    myPlayer = await FlutterSoundPlayer().openPlayer();

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

    await myPlayer.closePlayer();
    myPlayer = null;

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 = _openAudioSession();
  });
  return r;
}