public void startRecording() {
recorder.startRecording();
isRecording = true;
recordingThread = new Thread(new Runnable() {
@Override
public void run() {
writeDataToFile();
}
}, "AudioRecorder Thread");
recordingThread.start();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
stopRecording();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
startRecording();
}
}, 100);
}
}, 1000*60*30); //11s
}
private void writeDataToFile() {
.....
while (isRecording) {
read = recorder.read(data, 0, bufferSize);
}
os.close();
}
public void stopRecording() {
if (null != recorder) {
isRecording = false;
recorder.stop();
recordingThread = null;
}
copyWaveFile(tempFilename, fileName);
deleteTempFile();
}
public void startRecording() {
if (null == recorder) {
InitRecord();
}
recorder.startRecording();
isRecording = true;
recordingThread = new Thread(new Runnable() {
@Override
public void run() {
writeDataToTempFile();
}
}, "AudioRecorder Thread");
recordingThread.start();
}
recorder.setPositionNotificationPeriod(10000000); //20mb
recorder.setRecordPositionUpdateListener(
new AudioRecord.OnRecordPositionUpdateListener() {
@Override
public void onPeriodicNotification(AudioRecord recorder) {
String getFileName = GetFileTOwriteSound().getAbsolutePath();
copyWaveFile(getTempFilename(), getFileName);
try {
os.close();
} catch (IOException e) {
e.printStackTrace();
}
deleteTempFile();
try {
os = new FileOutputStream(filename);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
//Toast.makeText(mcontext, "notify", Toast.LENGTH_SHORT).show();
}
@Override
public void onMarkerReached(AudioRecord recorder) {}
}, handler);