Custom Audio Capture

Of course, using an intent to trigger the sound recorder isn't the only way we can capture audio. The Android SDK includes a MediaRecorder class, which we can leverage to build our own audio recording functionality. Doing so enables a lot more flexibility, such as controlling the length of time audio is recorded for.

The MediaRecorder class is used for both audio and video capture. After constructing a MediaRecorder object, to capture audio, the setAudioEncoder and setAudioSource methods must be called. If these methods are not called, audio will not be recorded. (The same goes for video. If setVideoEncoder and setVideoSource methods are not called, video will not be recorded. We won't be dealing with video in this chapter; ...

Get Pro Android Media: Developing Graphics, Music, Video, and Rich Media Apps for Smartphones and Tablets now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.