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; otherwise false.

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 stops them, deactivates the session, and return an AVAudioSession.ErrorCode.isBusy error.

Topics

Data Types

struct AVAudioSession.SetActiveOptions

Options that provide additional information about your app’s audio intentions upon session deactivation.

See Also

Activating the Audio Session