Instance Method

overrideOutputAudioPort(_:)

Temporarily changes the current audio route.

Declaration

func overrideOutputAudioPort(_ portOverride: AVAudioSession.PortOverride) throws

Parameters

portOverride

The override option for audio output. For a list of constants, see AVAudioSession.PortOverride.

Return Value

true if the new audio routing option was set successfully, or false if it was not.

Discussion

If your app uses the playAndRecord category, calling this method with the AVAudioSession.PortOverride.speaker option causes audio to be routed to the built-in speaker and microphone regardless of other settings. This change remains in effect only until the current route changes or you call this method again with the AVAudioSession.PortOverride.none option.

If you would prefer to permanently enable this behavior, you should instead set the category's defaultToSpeaker option. Setting this option will always route to the speaker rather than receiver if no other accessory such as headphones are in use.

Topics

Data Types

See Also

Working with Audio Routes

var currentRoute: AVAudioSessionRouteDescription

An object describing the current audio input and output route.

var isInputAvailable: Bool

A Boolean value indicating whether an audio input path is available.

var availableInputs: [AVAudioSessionPortDescription]?

An array of input ports available for routing.

var preferredInput: AVAudioSessionPortDescription?

The preferred input port for audio routing.

func setPreferredInput(AVAudioSessionPortDescription?)

Sets the preferred input port for audio routing.

var inputDataSources: [AVAudioSessionDataSourceDescription]?

An array of available data sources for the audio session’s current input port.

var inputDataSource: AVAudioSessionDataSourceDescription?

The currently selected input data source.

func setInputDataSource(AVAudioSessionDataSourceDescription?)

Selects a data source for the audio session’s current input port.

var outputDataSources: [AVAudioSessionDataSourceDescription]?

An array of available output data sources for the current audio route.

var outputDataSource: AVAudioSessionDataSourceDescription?

The currently selected output data source.

func setOutputDataSource(AVAudioSessionDataSourceDescription?)

Sets the output data source for an audio session.