February 2014
Intermediate to advanced
772 pages
18h 53m
English
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" ...Read now
Unlock full access