Recording audio with AudioRecord

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


Sponsored Links
 Hi,
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?

Thanks,
Ben



import android.media.AudioFormat;
import android.media.AudioRecord;
import android.media.MediaRecorder;
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() {
    this(DEFAULT_SAMPLE_RATE);
  }

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

  public void start() {
    recorder.setPositionNotificationPeriod(CALLBACK_PERIOD);
    recorder.setRecordPositionUpdateListener(new
AudioRecord.OnRecordPositionUpdateListener() {
      @Override
      public void onMarkerReached(AudioRecord recorder) {
        Log.e(this.getClass().getSimpleName(), "onMarkerReached
Called");
      }

      @Override
      public void onPeriodicNotification(AudioRecord recorder) {
        Log.e(this.getClass().getSimpleName(), "onPeriodicNotification
Called");
      }
    });

    recorder.startRecording();
  }

}

--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. Testing /system/bin/linker

Hi All,

I just built 'system/bin/linker' and copied to the target(SH) machine.The
target machine has linux which includes all the necessary android modules
like,ashmem,ipc binder ,low memory killer etc.
Before proceeding further i just wanted to make sure the 'linker' which i
built is working fine or not?How do i test the 'linker'?
Should i write a hello world C program and cross compile it and use 'linker'
to  run that hello world binary on the target?

Can anyone put some light on this ?

Anand

-- 
unsubscribe: android-porting+unsubscr...@googlegroups.com
website: 

2. Observing User inactivity time and broadcasting intent after timeout

Intent.ACTION_SCREEN_OFF is broadcast at the time where the user has been
inactive and the screen is about to turn off.




> 

3. Invalid View object passed to onListItemClick()?

4. How to add a new product project ?

5. Kernel panic occurs while Android is running

6. Invoking apps in background when phone starts

7. List of Intents related to Contact