VIAudioManager
Interface that may be used to manage audio devices on iOS device.
Limitations:
- It is not possible to select an VIAudioDeviceTypeReceiver while wired headset is connected.
- Wired headsets without a microphone may be recognized and selected as VIAudioDeviceTypeReceiver.
- iOS 12 and AirPods: during an active call, VIAudioDeviceTypeReceiver or VIAudioDeviceTypeSpeaker selection may fail if AirPods are used as current active device.
Methods
availableAudioDevices
- (NSSet<VIAudioDevice *> *
)availableAudioDevices
Returns the list of available audio devices.
For Bluetooth devices with Automatic Ear Detection feature (AirPods) please consider the following list of known issues and limitations:
- Before a call: if AirPods are connected to the phone, but you are not wearing them, audio device list is updated and include AirPods on a call start.
- Before a call: Bluetooth device may not be detected if AVAudioSession category is different from PlayAndRecord.
- During a call: if Bluetooth device is AirPods and they have been put to the case after another device is seleted by [VIAudioManager selectAudioDevice:], available audio devices list is not updated.
- During a call: if the active audio device is switched from Bluetooth to another audio device by the [VIAudioManager selectAudioDevice:] API, the Bluetooth device is not removed from the available audio devices list after Bluetooth is turned off on the phone.
Returns
type:
NSSet<VIAudioDevice *> *
callKitConfigureAudioSession:
- (void
)callKitConfigureAudioSession:(NSError * _Nullable *
)error
Initializes AVAudioSession to use with CallKit integration.
Required for the correct CallKit integration only. Otherwise do not use this method.
Should be called before [CXProviderDelegate provider:performStartCallAction:] and before [CXProviderDelegate provider:performAnswerCallAction:].
Parameters
error:
NSError * _Nullable *
Error during configuration steps
Returns
type:
void
callKitReleaseAudioSession
- (void
)callKitReleaseAudioSession
Restores the default AVAudioSession initialization routines, MUST be called after a call has ended, i.e. [CXProvider reportCallWithUUID:endedAtDate:reason:] has been called.
Required for the correct CallKit integration only. Otherwise do not use this method.
Returns
type:
void
callKitStartAudio
- (void
)callKitStartAudio
Starts AVAudioSession.
Required for the correct CallKit integration only. Otherwise do not use this method.
Should be called in [CXProviderDelegate provider:didActivateAudioSession:].
Returns
type:
void
callKitStopAudio
- (void
)callKitStopAudio
Stops AVAudioSession.
Required for the correct CallKit integration only. Otherwise do not use this method.
Should be called in [CXProviderDelegate provider:didDeactivateAudioSession:].
Returns
type:
void
currentAudioDevice
- ()currentAudioDevice
Returns the active audio device during a call or the audio device to be used for a call if there are no calls at this moment.
Please note that the active audio device can be later changed if a new device is connected. In this case [VIAudioManagerDelegate audioDeviceChanged:] is triggered to notify about the new active device.
Returns
type:
selectAudioDevice:
- (void
)selectAudioDevice:()audioDevice
Selects the currently active audio device.
There are two cases:
Before a call. The method does not activate an audio device, it just selects (i.e. points to) the audio device to be activated.
During a call. If the selected audio device is available, the method activates this audio device.
Please note that the active audio device can be later changed if a new device is connected. In this case [VIAudioManagerDelegate audioDeviceChanged:] is triggered to notify about the new active device.
If the application uses CallKit, you should take into consideration:
If a Bluetooth headset is connected, audio routing depends on where a call is answered (from a Bluetooth headset or the phone screen). Bluetooth headset is activated only if a call is answered via the Bluetooth headset controls. In other case the audio is played via the Receiver.
Audio is always routed to a Bluetooth headset only if a user selects "Bluetooth headset" as Call Audio Routing in the phone preferences.
If audio device is selected before CallKit activates the audio session, it is required to reselect this audio device after [CXProviderDelegate provider:didActivateAudioSession:] is called. Otherwise audio routing may be reset to default.
Known issues:
- It is not possible to select Receiver while a call is on hold and it is reported to CallKit.
- It is not possible to select Receiver before a call is connected, if a Blutooth audio device is connected.
Parameters
audioDevice:
Preferred audio device to use
Returns
type:
void
Props
delegate
@property (weak, nullable, nonatomic) delegate
Delegate to monitor audio session route changes.
Returns
type:
mode
@property (nonatomic) AVAudioSessionMode
mode
Selects AVAudioSessionMode to be used for a call.
AVAudioSessionModeVoiceChat is the default value.
AVAudioSessionModeVideoChat may be selected for video calls.
Other AVAduioSessionMode values may be incompatible with other AVAudioSession options used for calls and may cause audio issues during a call.
Returns
type:
AVAudioSessionMode
speakerIsDefault
@property (assign, nonatomic) BOOL
speakerIsDefault
Whether to use Speaker or Receiver as the default audio service.
If set to NO, Receiver is the default audio device. If set to YES, Speaker becomes the default audio device.
The default value is NO.
Setting this property does not actually change the selected audio device, but changes the preference of the default audio device.
If an audio device has not been selected via [VIAudioManager selectAudioDevice:] method and there is no priority audio devices such as Bluetooth or wired headset connected to the mobile phone, this property sets the priority between Receiver and Speaker (built-in audio devices).
The option is recommended to be used for video calls.
Returns
type:
BOOL