Hi!
I'm trying to write a program that reads the microphone's data in real time.
Here is my main class so far:
I'm already having problems initializing the AudioRecord, the value of getState() is zero.
LogCat:
I already set the permission for RECORD_AUDIO in the manifest file.
I have a Samsung Galaxy Spica with API version 7.
Does anyone have any idea why I can't get it to work?
Thanks for any help!
-Tusike
I'm trying to write a program that reads the microphone's data in real time.
Here is my main class so far:
Code:
package com.example.mictest;
import android.media.AudioFormat;
import android.media.AudioManager;
import android.media.AudioRecord;
import android.media.AudioTrack;
import android.media.MediaRecorder;
import android.media.MediaRecorder.AudioSource;
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends Activity {
//variables
private boolean isRecording = false;
private int audioSource = MediaRecorder.AudioSource.MIC;
private int samplingRate = 44100; /* in Hz*/
private int channelConfig = AudioFormat.CHANNEL_IN_MONO;
private int audioFormat = AudioFormat.ENCODING_PCM_16BIT;
private int bufferSize = AudioRecord.getMinBufferSize(samplingRate, channelConfig, audioFormat);
private int sampleNumBits = 16;
private int numChannels = 1;
private byte[] data;
private TextView TV;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TV = (TextView) findViewById(R.id.textView1);
AudioRecord recorder = new AudioRecord(AudioSource.MIC, samplingRate, channelConfig, audioFormat, bufferSize);
TV.setText(Integer.toString(recorder.getState()));
recorder.release();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
I'm already having problems initializing the AudioRecord, the value of getState() is zero.
LogCat:
Code:
09-24 18:01:07.139: E/AudioRecord(2530): AudioFlinger could not create record track, status: -1
09-24 18:01:07.139: E/AudioRecord-JNI(2530): Error creating AudioRecord instance: initialization check failed.
09-24 18:01:07.139: E/AudioRecord-Java(2530): [ android.media.AudioRecord ] Error code -20 when initializing native AudioRecord object.
I already set the permission for RECORD_AUDIO in the manifest file.
I have a Samsung Galaxy Spica with API version 7.
Does anyone have any idea why I can't get it to work?
Thanks for any help!
-Tusike
Hopefully should find much more help and assistance here.