iOS Developer Library

Developer

AVFoundation Framework Reference AVAudioSessionDelegate Protocol Reference

Options
Deployment Target:

On This Page
Language:

AVAudioSessionDelegate

Inheritance


Not Applicable

Import Statement


Swift

import AVFoundation

Objective-C

@import AVFoundation;

Availability


Available in iOS 3.0 and later.

The use of this protocol is deprecated in iOS 6 and later. Instead, you should use the notifications declared in AVAudioSession Class Reference.

The delegate of an AVAudioSession object must adopt the AVAudioSessionDelegate protocol. The methods in this protocol are optional. They allow a delegate to respond to the following sorts of changes in state:

  • Changes to the availability of audio input

  • Audio session interruption, or end of audio session interruption

An AVAudioSession delegate can respond to interruptions at the audio session level. You can use this interface along with any iOS audio technology. For example, your AVAudioSession delegate can handle interruptions for OpenAL and audio unit playback.

When using the AV Foundation framework for recording or playback, you can also respond to interruptions at the individual recorder or player level. To do this, create audio recorder or audio player delegates using the protocols described in AVAudioRecorderDelegate Protocol Reference and AVAudioPlayerDelegate Protocol Reference.

  • Called after your audio session is interrupted.

    Declaration

    Swift

    optional func beginInterruption()

    Objective-C

    - (void)beginInterruption

    Discussion

    By the time this interruption arrives, your audio has already stopped. Your application may be suspended or terminated following an interruption—for example, if a user chooses to take an incoming phone call. Use this method to adjust the user interface, and to save application state, as necessary.

    Import Statement

    Objective-C

    @import AVFoundation;

    Swift

    import AVFoundation

    Availability

    Available in iOS 3.0 and later.

  • Called after your audio session interruption ends.

    Declaration

    Swift

    optional func endInterruption()

    Objective-C

    - (void)endInterruption

    Discussion

    The endInterruptionWithFlags: method provides you with more information upon interruption end than this method does. Apple recommends that you use endInterruptionWithFlags: instead of this method.

    If you implement the endInterruptionWithFlags: method, that method is called instead of this one when an interruption ends.

    To resume using audio after an interruption ends, you must ensure that your audio session is active. AVAudioPlayer and AVAudioRecorder instances reactivate your audio session automatically when an interruption ends. If you are using another audio technology, such as OpenAL, audio units, or audio queues, you must reactivate your audio session yourself before you can again use audio.

    You can also use this method to update the user interface and application state, as necessary.

    Import Statement

    Objective-C

    @import AVFoundation;

    Swift

    import AVFoundation

    Availability

    Available in iOS 3.0 and later.

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

    Declaration

    Swift

    optional func endInterruptionWithFlags(_ flags: Int)

    Objective-C

    - (void)endInterruptionWithFlags:(NSUInteger)flags

    Parameters

    flags

    Flags indicating the state of the audio session when this method is called. Flags are described in Interruption Flags.

    Discussion

    To resume using audio after an interruption ends, you must ensure that your audio session is active. AVAudioPlayer and AVAudioRecorder instances reactivate your audio session automatically when an interruption ends. If you are using another audio technology, such as OpenAL, audio units, or audio queues, you must reactivate your audio session yourself before you can again use audio.

    You can also use this method to update the user interface and application state, as necessary.

    If this delegate method receives the AVAudioSessionInterruptionFlags_ShouldResume constant in its flags parameter, the audio session is immediately ready to be used.

    If you implement this method, it is called instead of the endInterruption method when an interruption ends.

    Import Statement

    Objective-C

    @import AVFoundation;

    Swift

    import AVFoundation

    Availability

    Available in iOS 4.0 and later.

  • Called after the availability of audio input changes on a device.

    Declaration

    Swift

    optional func inputIsAvailableChanged(_ isInputAvailable: Bool)

    Objective-C

    - (void)inputIsAvailableChanged:(BOOL)isInputAvailable

    Parameters

    isInputAvailable

    YEStrue if audio input is now available, or NOfalse if it is not.

    Import Statement

    Objective-C

    @import AVFoundation;

    Swift

    import AVFoundation

    Availability

    Available in iOS 3.0 and later.