Instance Method

setActive(_:options:)

Activates or deactivates your app’s audio session using the specified options.

Declaration

func setActive(_ active: Bool, options: AVAudioSession.SetActiveOptions = []) throws

Parameters

active

Specify true to activate your app’s audio session, or false to deactivate it.

options

An integer bit mask containing one or more constants from the AVAudioSession.SetActiveOptions enumeration.

Return Value

true if the session’s active state was changed successfully, or false if it was not.

Discussion

If another active audio session has higher priority than yours (for example, a phone call), and neither audio session allows mixing, attempting to activate your audio session fails. Deactivating an audio session that has running audio objects will stop the running audio objects, deactivate the session, and a AVAudioSession.ErrorCode.isBusy error will be returned.

Topics

Data Types

struct AVAudioSession.SetActiveOptions

A flag that provides additional information about your app’s audio intentions upon session deactivation.

See Also

Activating the Audio Session