밑에 소스 이용하면 저장은 되는 것 같은데 stop버튼을 누르면 멈추지가 않네요... 왜그러죠..ㅠㅠㅠ
고수님들 도와주세요..
//////////////////////////////////////////////////////////////////////////////////////////////
public class aaa extends Activity {
/** Called when the activity is first created. */
private Button mStart_btn;
private Button mStop_btn;
private boolean isRecording = false;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mStart_btn = (Button)findViewById(R.id.start_btn);
mStop_btn = (Button)findViewById(R.id.stop_btn);
mStart_btn.setOnClickListener(new Button.OnClickListener()
{
public void onClick(View v)
{
isRecording = true;
bbb();
}
});
mStop_btn.setOnClickListener(new Button.OnClickListener()
{
public void onClick(View v)
{
isRecording = false;
}
});
}
public void bbb() {
int sampleRateInHz = 8000;// 44100, 22050 and 11025
int channelConfig = AudioFormat.CHANNEL_CONFIGURATION_MONO;
int audioFormat = AudioFormat.ENCODING_PCM_16BIT;
File file = new
File(Environment.getExternalStorageDirectory(), "xyz.pcm");
if (file.exists())
file.delete();
try {
file.createNewFile();
} catch (IOException e) {
Log.e("crate file:", e.toString());
}
try {
OutputStream os = new FileOutputStream(file);
BufferedOutputStream bos = new BufferedOutputStream(os);
DataOutputStream dos = new DataOutputStream(bos);
//int bufferSize =11025 +
AudioRecord.getMinBufferSize(sampleRateInHz,channelConfig,
audioFormat);
int bufferSize = 440000;
short[] buffer = new short[bufferSize];
AudioRecord audioRecord = new
AudioRecord(MediaRecorder.AudioSource.MIC, sampleRateInHz,
channelConfig, audioFormat, bufferSize);
audioRecord.startRecording();
Log.e("recording", "before");
while (isRecording) {
int bufferReadResult = audioRecord.read(buffer, 0, bufferSize);
for (int i = 0; i < bufferReadResult; i++) {
dos.writeShort(buffer[i]);
Log.e("recording", "recording....");
}
}
audioRecord.stop();
dos.close();
Log.e("recording", "stopeed");
} catch (Throwable e) {
Log.e("record:", e.toString());
}
}
}