O'Reilly logo

Android Recipes: A Problem-Solution Approach, Third Edition by Jeff Friesen, Dave Smith

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

5-7. Recording Audio

Problem

You have an application that needs to use the device microphone to record audio input.

Solution

(API Level 1)

Use the MediaRecorder to capture the audio and store it out to a file.

How It Works

MediaRecorder is quite simple to use. All you need to provide is some basic information about the file format to use for encoding and where to store the data. Listings 5-24 and 5-25 provide examples of how to record an audio file to the device’s SD card, monitoring user actions for when to start and stop.

Important  In order to use MediaRecorder to record audio input, you must also declare the android.permission.RECORD_AUDIO permission in the application manifest.

Listing 5-24. res/layout/main.xml

<?xml version="1.0" ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required