Recording audio with AudioRecord

by benmccann » Sun, 10 May 2009 12:43:27 GMT

Sponsored Links
I'm having a hard time using the AudioRecord class.
I put some logging in the callback, but never see any output in the
logs.  Any idea what I'm doing wrong?


import android.util.Log;

public class AudioListener {

  public static final int DEFAULT_SAMPLE_RATE = 8000;
  private static final int DEFAULT_BUFFER_SIZE = 4096;
  private static final int CALLBACK_PERIOD = 4000;  // 500 msec
(sample rate / callback period)
  private final AudioRecord recorder;

  public AudioListener() {

  private AudioListener(int sampleRate) {
    recorder = new AudioRecord(MediaRecorder.AudioSource.DEFAULT,
        sampleRate, AudioFormat.CHANNEL_CONFIGURATION_DEFAULT,

  public void start() {
AudioRecord.OnRecordPositionUpdateListener() {
      public void onMarkerReached(AudioRecord recorder) {
        Log.e(this.getClass().getSimpleName(), "onMarkerReached

      public void onPeriodicNotification(AudioRecord recorder) {
        Log.e(this.getClass().getSimpleName(), "onPeriodicNotification




Other Threads

1. Custom View orientation change

I have a custom view A which extends RelativeLayout and internally
uses 3 instances of custom view B: B1, B2 and B3, which can be 'flung'
left or right to move to B4, B5 and B6.

I want to resize the whole view based on the orientation. I have
hardcoded the size of B based on the screen width of 320 (if the view
is initialized in potrait mode), or 480 (landscape mode), and then use
the screen density from getDisplayMetrics() to convert them into real
pixel values to draw my view. Is this is best way to do it?

I was trying to use onSizeChanged to look for orientation changes, but
this does not work because onMeasure() is called before
onSizeChanged() and the orientation change does not show up.

Any advice anyone?


2. onCellLocationChanged and updateNetworkNameExtension showing up in Log files. Where do these come from? and can I make them stop?


As I know you get the event onCellLocationChanged when there is change
in Cell Tower connectivity..

To stop this event you need to stop listing to this update. Look for
listen method in Telephonymanager (URL:

I am not aware of the other event.


3. facing issue with sound driver(TLV320AIC33)

4. ext2/3/4 file system support in emulator

5. Hidden Backdoors In Apps Possible

6. Calendar issue

7. mouse cursor alpha blending issue