setAudioFocus method

Future<void> setAudioFocus({
  1. AudioFocus focus = AudioFocus.requestFocusAndKeepOthers,
  2. SessionCategory category = SessionCategory.playback,
  3. SessionMode mode = SessionMode.modeDefault,
  4. int audioFlags = outputToSpeaker | allowBlueTooth | allowBlueToothA2DP | allowEarPiece,
})

setAudioFocus is used to modify the state of the Focus. Very often, the App will not use this verb and will specify the focus value during the open() and close() verbs. If the App does not have the focus when it does a start() it automaticaly gets the focus AudioFocus.requestFocusAndStopOthers, and releases the focus automaticaly when the Player is stopped.

Be aware that the focus is a global resource for the App: If you have several players, you cannot handle their focus independantely.

Example:

        myPlayer.setFocus(focus: AudioFocus.requestFocusAndDuckOthers);

Implementation

Future<void> setAudioFocus({
  AudioFocus focus = AudioFocus.requestFocusAndKeepOthers,
  SessionCategory category = SessionCategory.playback,
  SessionMode mode = SessionMode.modeDefault,
  //AudioDevice device = AudioDevice.speaker,
  int audioFlags =
      outputToSpeaker | allowBlueTooth | allowBlueToothA2DP | allowEarPiece,
}) async {
  await _lock.synchronized(() async {
    await _setAudioFocus(
      focus: focus,
      category: category,
      mode: mode,
      //device: device,
      audioFlags: audioFlags,
    );
  });
}