Hej, im currently trying to get AudioRecord to work. Because I need it in a larger project. But it looks like a lot. I tried many things, so I returned to the main thing when I traced this error. I am using my Samsung Galaxy S as my debugdevice.
My problem is that the first time I reboot my device, I can initialize the AudioRecord object that I created without problems. But the second time I ran it, it does not initialize the AudioRecord object. I tried a few frequencies, fyi.
Here is my code:
package android.audiorecordtest; import android.app.Activity; import android.media.AudioFormat; import android.media.AudioRecord; import android.media.MediaRecorder; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.TextView; public class AudioRecordTest extends Activity { int frequency; AudioRecord audRec; TextView txtVw; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); txtVw = (TextView) findViewById(R.id.txtVw); frequency=8000; int bufferSize=(AudioRecord.getMinBufferSize(frequency, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT))*2; if (bufferSize>0) { audRec = new AudioRecord(MediaRecorder.AudioSource.MIC, frequency, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT, bufferSize); int status = audRec.getState(); if (status == AudioRecord.STATE_INITIALIZED) { txtVw.setText("Initialized" + frequency); } else { txtVw.setText("Not Initialized i=" + frequency); } }
After hours of viewing logcat information, I found this event
02-28 10:46:37.048: DEBUG/dalvikvm(4477): GC_EXPLICIT freed 1801 objects / 98944 bytes in 97ms 02-28 10:46:37.048: VERBOSE/AudioRecord(4477): stop
It seems that βrelease the native hold on AudioRecord. So I tried to do a redefinition of completion with my Audiorecord object. Release (). That didn't work though .. Does anyone have an idea?
android audio alsa android-audiorecord
Anders Metnik Feb 28 '11 at 8:41 2011-02-28 08:41
source share