setAudioFocus method
Future<void>
setAudioFocus({
- AudioFocus focus = AudioFocus.requestFocusTransient,
- SessionCategory category = SessionCategory.playAndRecord,
- SessionMode mode = SessionMode.modeDefault,
- AudioDevice device = AudioDevice.speaker,
Changes the audio focus in an open Recorder
focus:
parameter possible values are
- AudioFocus.requestFocus (request focus, but do not do anything special with others App)
- AudioFocus.requestFocusAndStopOthers (your app will have exclusive use of the output audio)
- AudioFocus.requestFocusAndDuckOthers (if another App like Spotify use the output audio, its volume will be lowered)
- AudioFocus.requestFocusAndKeepOthers (your App will play sound above others App)
- AudioFocus.requestFocusAndInterruptSpokenAudioAndMixWithOthers
- AudioFocus.requestFocusTransient (for Android)
- AudioFocus.requestFocusTransientExclusive (for Android)
- AudioFocus.abandonFocus (Your App will not have anymore the audio focus)
Other parameters :
Please look to openAudioSession() to understand the meaning of the other parameters
Example:
myRecorder.setAudioFocus(focus: AudioFocus.requestFocusAndDuckOthers);
Implementation
Future<void> setAudioFocus(
{AudioFocus focus = AudioFocus.requestFocusTransient,
SessionCategory category = SessionCategory.playAndRecord,
SessionMode mode = SessionMode.modeDefault,
AudioDevice device = AudioDevice.speaker}) async {
_logger.d('FS:---> setAudioFocus ');
await _lock.synchronized(() async {
await _setAudioFocus(
focus: focus,
category: category,
mode: mode,
device: device,
);
});
_logger.d('FS:<--- setAudioFocus ');
}