Search code examples
androidaudiowear-osaudio-recordingvoice-recording

How to set recording audio few seconds on Android?


I am trying to record some audio from microphone on android wear, 3 seconds long. In this case we can't do that with Thread.sleep(3000); because during those seconds main thread works. Also I was trying with manipulate with time and I got current time in seconds from Calendar example:

Calendar c = Calendar.getInstance();
int seconds = c.get(Calendar.SECOND);
seconds = seconds + 2;
if (seconds == 60 || seconds == 61)
{
    seconds = seconds - 60;
}
int sada; //with initialization here is pretty much same
do
{
    sada = 105; //without this line is pretty much same
    sada = c.get(Calendar.SECOND);
    Log.d("SEKUNDI", String.valueOf(sada));
}while(sada != seconds);

Anyone help?


Solution

  • I started recording in main thread, and I created new thread in background and sleep it for 3 seconds. In a postBack method I called the stopRecording() method. Important code is:

    Thread.currentThread();
    Thread.sleep(3000);
    

    This can be applied to any other similar problem. Thanks for comments.