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 AVAudioSessionErrorCode.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

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software