Raw Audio Capture and Playback Example
Here is a full example that records using AudioRecord
and plays back using AudioTrack
. Each of these operations lives in their own thread through the use of AsyncTask
, so that they don't make the application become unresponsive by running in the main thread.
package com.apress.proandroidmedia.ch07.altaudiorecorder;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import android.app.Activity;
import android.media.AudioFormat;
import android.media.AudioManager;
import android.media.AudioRecord; import android.media.AudioTrack; ...
Get Pro Android Media: Developing Graphics, Music, Video, and Rich Media Apps for Smartphones and Tablets 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.