AIR 3 has two important new audio capabilities:
- Device speaker selection. Play audio through a phone’s speaker, or through its earpiece.
- Background audio playback on iOS. Keep audio playing in the background when a user switches away from your application, and even when the screen is switched off.
Device Speaker Selection
Toggling between a phone’s speaker and earpiece for playing audio is as easy as setting the
audioPlaybackMode property on
SoundMixer like this:
// Play audio through the speaker:
SoundMixer.audioPlaybackMode = AudioPlaybackMode.MEDIA;
// Play audio through the earpiece:
SoundMixer.audioPlaybackMode = AudioPlaybackMode.VOICE;
Background audio playback has always worked on Android because of the nature of the Android’s multi-tasking implementation. Starting with AIR 3, it works on iOS, as well. To allow audio to continue playing when your application is closed — and even when the device’s screen is turned off — add the following to your application descriptor: