open method

Future<TauPlayer?> open({
  1. required InputNode from,
  2. required OutputDeviceNode to,
  3. AudioFocus? focus,
  4. SessionCategory category = SessionCategory.playAndRecord,
  5. SessionMode mode = SessionMode.modeDefault,
  6. int audioFlags = outputToSpeaker | allowBlueToothA2DP | allowAirPlay,
  7. bool withShadeUI = false,
})

Open the Player.

A player must be opened before used. A player correspond to an Audio Session. A Player manages its own playback, with its own sound volume, its own seekToPlayer and its own set of callbacks. A Player is a High level OS object. It corresponds to an AVAudioPlayer on iOS and a MediaPlayer on Android. Players play Files, Buffers and Assets. Players do not manage RAW PCM data.

The App can create several Players. Each player must be independently opened and closed. When you have finished with a Player, you must close it. Opening a player takes resources inside the OS. Those resources are freed with the verb close(). Returns a Future, but the App does not need to wait the completion of this future before doing a start(). The Future will be automaticaly awaited by start()

  • withShadeUI : true if the App wants to show an UI on the lock screen. (Ignored on Flutter Web).
  • focus : What to do with the focus. Useful if you want to open a player and at the same time acquire the focus. But be aware that the focus is a global resource for the App: If you have several players, you cannot handle their focus independantely. If this parameter is not specified, the Focus will be acquired with stop others

Example:

    myPlayer = await TauPlayer().open();

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

    await myPlayer.close();
    myPlayer = null;

Implementation

Future<TauPlayer?> open({
  required InputNode from,
  required OutputDeviceNode to,
  AudioFocus? focus,
  SessionCategory category = SessionCategory.playAndRecord,
  SessionMode mode = SessionMode.modeDefault,
  //AudioDevice device = AudioDevice.speaker,
  int audioFlags = outputToSpeaker | allowBlueToothA2DP | allowAirPlay,
  bool withShadeUI = false,
}) async {
  if (_isInited) {
    return this;
  }
  TauPlayer? r;
  await _lock.synchronized(() async {
    _from = from;
    _to = to;
    r = await _open(
      from: from,
      to: to,
      focus: focus,
      category: category,
      mode: mode,
      //device: device,
      audioFlags: audioFlags,
      withShadeUI: withShadeUI,
    );
  });
  return r;
}