setAudioFocus method

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

Set or unset the Audio Focus.

This verb is very similar to openAudioSession and allow to change the parameters during an open Session Example:

        myPlayer.setAudioFocus(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,
    );
  });
}