Chapter 11. Microphone and Audio

Sound is the vocabulary of nature.

Pierre Schaeffer

Audio has a place in mobile applications. Perhaps music is the core element of your project, or sound bites are the final touch to make your application look polished.

This chapter will review what ActionScript has to offer with audio on Android devices. First we will use the microphone, an enhanced modern digital Dictaphone of sorts. Then we will explore the various ways to use audio in your application.

The Microphone

You can use the microphone in many applications on a mobile device. For example, you can take quick audio notes. You can add an audio caption to your photograph. You can even create a DJ multitrack tool with a convenient multitouch interface.

flash.media.Microphone is a static class for monitoring and capturing audio from the device’s native microphone. It is a subclass of the EventDispatcher class.

Your application needs the audio permission to use it:

<uses-permission android:name="android.permission.RECORD_AUDIO"/>

First make sure your device has a microphone and gives you access to it:

import flash.media.Microphone;

if (Microphone.isSupported) {
    // continue on
}

If it does, create a reference to it through its getMicrophone method. On Android devices, you only have access to one microphone:

var microphone:Microphone = Microphone.getMicrophone();

The microphone has several properties that you can set to improve your recording.

gain works as a volume multiplier and has a value between 0 and ...

Get Developing Android Applications with Adobe AIR now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.