Hi,

Perhaps try to see if AudioRecorder is ready to go, by using this API:

"
public int getState ()
Since: API Level 3

Returns the state of the AudioRecord instance. This is useful after
the AudioRecord instance has been created to check if it was
initialized properly. This ensures that the appropriate hardware
resources have been acquired.
See Also

    * STATE_INITIALIZED
    * STATE_UNINITIALIZED
"

http://developer.android.com/reference/android/media/AudioRecord.html#getState%28%29

It appears that for whatever reason, recorder wasn't ready or was
already started or something.


On Jan 26, 3:58 pm, frantz lohier <floh...@gmail.com> wrote:
> Hi All,
>
> I'm writing an Activity that attempts to use the AudioRecord API. When I
> invoke the setNotificationMarkerPosition, my activity crashes with the
> following error message:
>
> *java.lang.IllegalStateException: Unable to retrieve AudioRecord pointer for
> setPositionUpdatePeriod()*
>
> E/AndroidRuntime( 4543):        at
> android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2401)
>
> E/AndroidRuntime( 4543):        at
> android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2417)
>
> E/AndroidRuntime( 4543):        at
> android.app.ActivityThread.access$2100(ActivityThread.java:116)
>
> E/AndroidRuntime( 4543):        at
> android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
>
> E/AndroidRuntime( 4543):        at
> android.os.Handler.dispatchMessage(Handler.java:99)
>
> E/AndroidRuntime( 4543):        at android.os.Looper.loop(Looper.java:123)
>
> E/AndroidRuntime( 4543):        at
> android.app.ActivityThread.main(ActivityThread.java:4203)
>
> E/AndroidRuntime( 4543):        at
> java.lang.reflect.Method.invokeNative(Native Method)
>
> E/AndroidRuntime( 4543):        at
> java.lang.reflect.Method.invoke(Method.java:521)
>
> E/AndroidRuntime( 4543):        at
> com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
>
> E/AndroidRuntime( 4543):        at
> com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
>
> E/AndroidRuntime( 4543):        at dalvik.system.NativeStart.main(Native
> Method)
>
> E/AndroidRuntime( 4543): *Caused by: java.lang.IllegalStateException: Unable
> to retrieve AudioRecord pointer for setPositionUpdatePeriod()*
>
> E/AndroidRuntime( 4543):        at
> android.media.AudioRecord.native_set_pos_update_period(Native Method)
>
> E/AndroidRuntime( 4543):        at
> android.media.AudioRecord.setPositionNotificationPeriod(AudioRecord.java:650)
>
> E/AndroidRuntime( 4543):        at
> com.intentionis.ambulabilis.android.ambu.full.AmBuMain.onStart(AmBuMain.java:2069)
>
> E/AndroidRuntime( 4543):        at
> android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1205)
>
> E/AndroidRuntime( 4543):        at
> android.app.Activity.performStart(Activity.java:3519)
>
> E/AndroidRuntime( 4543):        at
> android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2373)
>
> The code snippet that triggers this bug is as follows:
>
> AudioRecord audiorec = new AudioRecord(
>
> MediaRecorder.AudioSource.MIC,
>
> 11025,
>
>                         AudioFormat.CHANNEL_CONFIGURATION_MONO,
>
> AudioFormat.ENCODING_PCM_16BIT,
>
> 11025*20);
>
>                                         //No exception is thrown and
> audiorec seems to be valid
>
>                                                             //THIS CALL
> CAUSES THE CRASH (THIS HAPPENS EVEN WHEN I PLACE THE LINE BELOW THE NEXT
> SENTENCE
>
>  audiorec.setPositionNotificationPeriod(4000);
>
> audiorec.setRecordPositionUpdateListener(new
> AudioRecord.OnRecordPositionUpdateListener()
>
>                                                             {
>
> public void onMarkerReached(AudioRecord rec) {
>
>                                                                           ;
>
>                                                                         }
>
> public void onPeriodicNotification(AudioRecord rec) {
>
>                                                                           ;
>
>                                                                         }
>
>                                                             });
>
> Thanks for anyone's feedback.
>
> PS: the above code also fails when I try different sampling rate, channel
> configuration.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to