Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid AudioRecord - Won't Initialize 2nd time
    text
    copied!<p>Hej, im currently trying to get AudioRecord to work. Because I need it in a bigger project. But it seems to mess up a lot. I have been trying alot of things, so I went back to basic when I traced this bug. I am using my Samsung Galaxy S as my debugdevice.</p> <p>My problem is, first time after a reboot of my device I can initialize the AudioRecord object I create without problems. But the second time I run it, it won't initialize the AudioRecord object. I have tried several frequencies, fyi. </p> <p>Here is my code: </p> <pre><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; /** Called when the activity is first created. */ @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&gt;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); } } </code></pre> <p>After a few hours of looking through logcat information i found this event</p> <pre><code> 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 </code></pre> <p>Which seems to "release the native hold on the AudioRecord. So i tried doing an override of finalize with my Audiorecord object.release(). This didnt work though.. Anyone have any idea?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload