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. How to add screens to launcher?

Dear all:
     In cupcake, the workspace contains 3 screens of cells. How to
make the number of screens a little more? Such as 5 or 7 screens.
     I've tried to change SCREEN_COUNT in launcher.java and add codes
like <include android:id="@+id/cell4" ... /> to launcher.xml, but it
didn't work.
     My emulator screen resolution is 800*480.

     THX...

-- 

2. 2.2: wifi startScan never produces SCAN_RESULTS_AVAILABLE_ACTION

In my experience, previous versions of Android broadcast
SCAN_RESULTS_AVAILABLE even when no APs are found. getScanResults()
would then return a null or empty list.

It seems that the behaviour has changed in 2.2, I now don't get any
SCAN_RESULTS_AVAILABLE even two minutes after the scan started if
there are no APs around.

Can anyone confirm ?

Lee

-- 

3. Problem in programmatically installing a 3rd party App onto the SD card

4. Problem in programmatically installing a 3rd party App onto the SD card

5. abis upgrade froyo insttaler sama eoeinstaller fc

6. We need developer feedback, STOP rating when customer has canceled order

7. Bottom of one LinearLayout being hidden by other LinearLayout?