Skip to main content Link Menu Expand (external link) Document Search Copy Copied
openPlayer method - FlutterSoundPlayer class - player library - Dart API
menu
openPlayer

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().

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 = _openPlayer();
  });
  return r;
}
flutter_sound 9.24.0