Protocol

AVAudioPlayerDelegate

The delegate of an AVAudioPlayer object must adopt the AVAudioPlayerDelegate protocol. All of the methods in this protocol are optional. They allow a delegate to respond to audio interruptions and audio decoding errors, and to the completion of a sound’s playback.

Topics

Responding to Sound Playback Completion

Responding to an Audio Decoding Error

func audioPlayerDecodeErrorDidOccur(AVAudioPlayer, error: Error?)

Called when an audio player encounters a decoding error during playback.

Handling Audio Interruptions

func audioPlayerBeginInterruption(AVAudioPlayer)

Called when an audio player is interrupted, such as by an incoming phone call.

Deprecated
func audioPlayerEndInterruption(AVAudioPlayer, withOptions: Int)

Called after your audio session interruption ends, with options indicating the state of the audio session.

Deprecated
func audioPlayerEndInterruption(AVAudioPlayer)

Called after your audio session interruption ends.

Deprecated
func audioPlayerEndInterruption(AVAudioPlayer, withFlags: Int)

Called after your audio session interruption ends, with flags indicating the state of the audio session.

Deprecated

Relationships

Inherits From

See Also

Configuring and Controlling Playback

func play()

Plays a sound asynchronously.

func play(atTime: TimeInterval)

Plays a sound asynchronously, starting at a specified point in the audio output device’s timeline.

func pause()

Pauses playback; sound remains ready to resume playback from where it left off.

func stop()

Stops playback and undoes the setup needed for playback.

func prepareToPlay()

Prepares the audio player for playback by preloading its buffers.

var isPlaying: Bool

A Boolean value that indicates whether the audio player is playing (true) or not (false).

var volume: Float

The playback volume for the audio player, ranging from 0.0 through 1.0 on a linear scale.

var pan: Float

The audio player’s stereo pan position.

var rate: Float

The audio player’s playback rate.

var enableRate: Bool

A Boolean value that specifies whether playback rate adjustment is enabled for an audio player.

var numberOfLoops: Int

The number of times a sound will return to the beginning, upon reaching the end, to repeat playback.

var delegate: AVAudioPlayerDelegate?

The delegate object for the audio player.

var settings: [String : Any]

The audio player’s settings dictionary, containing information about the sound associated with the player.