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 New A Activity Using ADT

Dear All,
Do you know how to new a android activity using eclipse+adt with class
file extends Activity created and AndroidManifest.xml filled? Thanks.

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

2. TabHost :: Changing tab content with intents dynamically

Dear all,

I have a tabactivity with several tabs. They are all defined with
intents. On one tab, I have an action that needs to bring me to
another tab and with a specific data.

I worked with Intents and I broadcast them to change the tab. For that
I have no problem.

But I am facing an issue as soon as I try to reset my tabs for the
second time (when the application starts, my method does not fail
while called for the second time it throws an exception). The issue
comes only If I call the clearAllTabs() method on TabHost.

Here is the exception :

07-21 19:40:16.327: ERROR/AndroidRuntime(3308): Caused by:
java.lang.NullPointerException
    at android.widget.TabWidget.setCurrentTab(TabWidget.java:164)
    at android.widget.TabWidget.focusCurrentTab(TabWidget.java:188)
  at android.widget.TabHost.setCurrentTab(TabHost.java:307)
 at android.widget.TabHost.addTab(TabHost.java:203)
at .ACTIVITY.initTabs(ACTIVITY.java:40)
07-21 19:40:16.327: ERROR/AndroidRuntime(3308):     at
<package>TabChanger.onReceive(TabChanger.java:30)
07-21 19:40:16.327: ERROR/AndroidRuntime(3308):     at
android.app.ActivityThread$PackageInfo$ReceiverDispatcher$Args.run
(ActivityThread.java:664)


Here is the method to init the tabs :

public void initTabs(Intent mapIntent){
                TabHost tabHost = getTabHost();
                tabHost.clearAllTabs();

                tabHost.addTab(tabHost.newTabSpec("TAB1").setIndicator(getString
(R.string.tab_title_fav),
                                
getResources().getDrawable(R.drawable.img_star)).setContent(
                                new Intent(this, FavoriteListActivity.class)));

                tabHost.addTab(tabHost.newTabSpec("TAB2").setIndicator(getString
(R.string.tab_title_search),
                                
getResources().getDrawable(R.drawable.img_search)).setContent(
                                new Intent(this, 
SearchForBikesOrSlotsActivity.class)));

                mapTab = tabHost.newTabSpec("TAB3").setIndicator(getString
(R.string.tab_title_map),
                                
getResources().getDrawable(R.drawable.img_map)).setContent
(mapIntent);

                tabHost.addTab(mapTab);

                tabHost.addTab(tabHost.newTabSpec("TAB4").setIndicator(getString
(R.string.tab_title_timer),
                                
getResources().getDrawable(R.drawable.img_timer)).setContent(
                                new Intent(this, 
NewStationActivityStep1.class)));
        }


I also tries to keep an handle on the tab I'd like to change (the map
one), in order to change its content but still no success (the content
does not change).

ANy help will be highly appreciated XD

Rgds

C.
--~--~---------~--~----~------------~-------~--~----~

3. Detect virtual keyboard or access onsizechanged of layout view

4. How To include End User License Agreement with the APP

5. fullscreen doesn't hide Status Bar in Android SDK 1.5 R2

6. Setting a listener for drag animations in MapView

7. Find Default Activity corresponding to Intent