The aural experience of an application is just as impactful as the visual or gestural experiences. A good background score and sound control can be the making of a runaway hit, just as a bad one can ruin a perfectly great application. As a result, it’s very important to get the audio accompaniments of your application just right. In Adobe AIR, the SoundMixer.audioPlaybackMode property gives some control over the behavior of audio output. Now, in the upcoming Adobe AIR 3.4, the application developer has another option to fine tune audio output – the new Ambient AudioPlaybackMode. You can download Adobe AIR 3.4 beta from Adobe Labs.
Upto Adobe AIR 3.3, there were only two modes: Media and Voice. Both these modes play sound in a manner assuming that the sound is central to the operation of the application. In these modes, sound continues to play even when the application is in the background or if the screen is locked. Most importantly, sound played in these modes does not obey the hardware silent switch on iPhones and iPads.
The new Ambient AudioPlaybackMode in Adobe AIR 3.4 fills in the requirement for a sound that is just an accompaniment to your application, not its main purpose. On iOS, Ambient mode allows the user to silence your application by flipping the silent switch or locking the screen. To use Ambient mode, simply set the audioPlaybackMode property of the SoundMixer class to AudioPlaybackMode.AMBIENT.
|SoundMixer.audioPlaybackMode = AudioPlaybackMode.AMBIENT;|
Android vs iOS
The driving force behind this new Audio Playback Mode has been the request for a mechanism to play sound in Adobe AIR that would respect the hardware silent switch on iPhones and iPads. Since most Android devices don’t have a dedicated hardware mute switch, nor was their any requirement for a sound mode on Android that would automatically silence sound on going into the background, these features have not been made available on Android. As a result, the Ambient AudioPlaybackMode on Android behaves identically to the Media AudioPlaybackMode.
The rest of this blog post refers to the implementation and behavior of Ambient AudioPlaybackMode on iOS
How it works
The Ambient AudioPlaybackMode is implemented using the iOS Audio Session category kAudioSessionCategory_AmbientSound. When the Adobe AIR Runtime sets this Audio Session property, iOS takes care of all changes in sound behavior related to sound output routing, silencing etc. Some of this behavior may not even be explicitly documented. For example, when sound output is being routed through connected headphones, the silent switch becomes ineffective, but the sound is still silenced if the application goes into the background or the screen is locked.
Paused or Muted? And what about Video?
When sound is silenced by the hardware silent switch on iPhones and iPads, it gets muted. When the screen is locked, or the application goes into the background by pressing the home key, the sound is paused. This behavior is even more important to note in case of videos. When the app is in the foreground and you flip the silent switch, the sound is muted and you can see the video frames progress as expected. But when the app is sent to the background, and then launched again, the video and audio remain in sync and continue from where they left off when the application was dismissed. Note also that in case of Video objects, a frozen frame is visible for about a second before the video continues playing when the application returns to the foreground. This transition is much smoother in case of StageVideo objects.
Known issue: No audio in Media Playbackmode for StageVideo when mute switch is muted
Working with Microphone
When a microphone is in use, the behavior of Ambient mode is drastically affected. This is because the underlying Audio Session category AmbientSound doesn’t support the use of Microphone. Thus the Adobe AIR Runtime internally falls back to the Audio Session category PlayAndRecord. When this happens, the behavior of sound in Ambient mode becomes effectively the same as the behavior in Media mode.