Can麓t create an AudioRecor der object

by HeHe » Mon, 08 Mar 2010 01:16:04 GMT

Sponsored Links
 what is the value of the variable SAMPLE_RATE?


Can麓t create an AudioRecor der object

by Gabriel Sim玫es » Mon, 08 Mar 2010 02:06:15 GMT


On 7 mar, 14:15, HeHe <> wrote:


Sponsored Links

Can麓t create an AudioRecor der object

by Gabriel Sim玫es » Mon, 08 Mar 2010 02:06:50 GMT

 AMPLE_RATE = 8000;

On 7 mar, 14:15, HeHe <> wrote:


Can麓t create an AudioRecor der object

by Gabriel Sim玫es » Thu, 11 Mar 2010 10:29:35 GMT

 ell, after spending my free time for the last 5 days working on the
AudioRecord class Im here again to post my findings.
But first let me make myself clear:

- What Im about to write is the result of my tests and findings after
having a lot of trouble to use the basic routines of the class. I
found a lot of forums posts over the internet about the same problems
so my idea here is to help people so they dont face the same problems
Ive faced.

- It may be beginners stuff, but a lot of people have faced or are
facing the same problems.

- If something here is wrong please dont come here just to say it,
share your knowledge with us and post not only whats wrong but how to
do it right.

- Ive done all tests on the EMULATOR provided by google. Also Im
using the sdk 2.1 (build 7)

Ok, lets go.

Creating an AudioRecord object:

When you create a new instance of AudioRecord there are two ways of
finding out if it was created properly (the device can handle the
audio parameters and resources were trully allocated to your object):
by catching an exception or by verifying the return of the getState()

- Handling the IllegalArgumentException : Well, tricky is what I can
say. Exceptions will only be thrown if any of the parameters you have
used are NOT acceptable by the CLASS (not if the device cant handle
it). For example, a sample rate = 12345 is not a standard value and
then the class will throw an exception. If SR = 44100 is not supported
by the DEVICE, the object will be created and no exception will be
* An interesting thing is that the official documentation says:
"sampleRateInHz the sample rate expressed in Hertz. Examples of rates
are (but not limited to) 44100, 22050 and 11025."
If you try SR = 11025 the system will throw an exception as it
considers this an illegal parameter. Strange, huh?

- Then ok, you have created an instance of AudioRecord but you dont
know if the parameters you have set are available in an specific
device. What you do? Verify AudioRecord.getState(), right?
Ok then, it works. But if you find out your instance is not ok and
then you have to create a new AudioRecord object you will be in
trouble. Why? Even after running AudioRecord.release() the resources
for the audio input you are interested in will keep being in use and
you wont be abble to recreate your object in a way it would work.
To verify this create an instace of AudioRecord with parameters that
are known not to work on the emulator (ex. SR = 44100). Then verify
the errors on logcat. After that call release() and then try to create
another instance of AudioRecorder with the parameters that work (sr =
8000, mono channel, pcm 16 bits) and check the first error line.

Then how should you find out which parameters the device will allow
you to use? Say with me: AudioRecord.getMinBufferSize() is my
Loop checking from the best combination of parameters to the worst. If
it returns -2, you should try another combination, if it returns -1
the audio input source is already being in use or isnt even available
for the specific device. If it returns something > 0 then youre ok
and can proceed creating a new AudioRecord object.

AudioRecord notification:

YES, IT WORKS! Believe me. The trick is: the notification will only be
called AFTER you call read() for the first time! And not only one time
(Oo). After a periodic notification you need to read from the audio

Other Threads

1. felix OSGi Container and Android


I try felix OSGi on android it works fine... until i try to embed an

now some package are missing:
   Unresolved constraint in bundle 4: package;

i'm unable to find where is this package... I think i must customize
bootclasspath but how ?

I launch felix with this command (found on felix web site):
/system/bin/dalvikvm -Xbootclasspath:/system/framework/core.jar -
classpath bin/felix.jar org.apache.felix.main.Main.

Any idea !



2. status bar

any idea how i can have a "permanent" view independent of activities
much lika a status bar on a windows program (not the mobile phone's
status bar with icons).
It is meant to have info about the program status and the user's
points for example and that can be updated from a service.

I thought about having an activity that is constant and have all the
other activites with less height value so that the first is visible,
but it doesn't sound like a good idea :P

any thoughts?



3. get orientation via SensorListener

4. add files to data/data folder of android phone

5. ListView :: How to automatically scrool to see a element ?

6. Digital Sign,or Permission fidden: PackageManager( 458): Package has mismatched uid: 1000 on disk, 10003 in setting

7. Starting an Activity by sending an Intent with Extra Data