Set time limit for audio recording in android
I created a button that, when touched, starts recording, and when not touched, stops voice recording. Should I implement such a flow? but where exactly should I put it in ACTION.DOWN or ACTION.UP?
public class StopRecord extends Thread {
int i = 0;
@Override
public void run() {
super.run();
handler.post(new Runnable() {
@Override
public void run() {
stopRecording();
}
});
}
}
which I have to post here:
@Override
public boolean onTouch(View v, MotionEvent event) {
switch(event.getAction()){
case MotionEvent.ACTION_DOWN:
startRecording();
break;
case MotionEvent.ACTION_UP:
stopRecording();
break;
}
return false;
}
});
I don't have the example code, but I suggest checking the developer guide that gives a good example, check it out: http://developer.android.com/guide/topics/media/audio-capture.html
For the timeout part, check the following: MediaRecorder.setMaxDuration (int timer) what happens when the timer expires
Hope this helps you.
source to share
You are more likely to create a button. When you click on it, recording starts and the button changes (text, possibly background color) to inform the user that recording is in progress. When he presses again, he stops. You can make the timeout with handler.postDelayed (runnable, delayMs). But if the user hits the break button before the timeout, you must cancel the handler. You do it with handler.removeCallbacks (runnable)
source to share
So, I did it additionally:
private MediaRecorder.OnInfoListener infoListener = new MediaRecorder.OnInfoListener()
{
@Override
public void onInfo(MediaRecorder mr, int what, int extra) {
if (what == MediaRecorder.MEDIA_RECORDER_INFO_MAX_DURATION_REACHED) {
//display in long period of time
Toast.makeText(getApplicationContext(), "End Recording", Toast.LENGTH_LONG).show();
stopRecording();
}
}
};