Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TimeoutException in MediaRecorder.finalize() after 10 seconds

stacktrace0=java.util.concurrent.TimeoutException:
android.media.MediaRecorder.finalize() timed out after 10
seconds
    at android.media.MediaRecorder.native_finalize(Native Method)
    at android.media.MediaRecorder.finalize(MediaRecorder.java:1200)
    at java.lang.Daemons$FinalizerDaemon.doFinalize(Daemons.java:187)
    at java.lang.Daemons$FinalizerDaemon.run(Daemons.java:170)
    at java.lang.Thread.run(Thread.java:841)

if (isDirectoryExists) 
{
MediaRecorder recorder= new MediaRecorder();
recorder.reset();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.RAW_AMR);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setOutputFile(path);
recorder.setMaxDuration(30*60*1000);

if(recorder!=null)
{
    recorder.prepare();
}
try
{
    if(recorder!=null)
    {
        recorder.start();
        isRecordingStarted=true;
    }
}
catch (IllegalStateException ilse) 
{
    try
    {
        if(recorder!=null)
        {
            recorder.prepare();
        }
    }
    catch(Exception e)
    {
        e.printStackTrace();
    }
    try
    {
        if(recorder!=null)
        {
            recorder.start();
        }
    }
    catch(Exception e)
    {
        e.printStackTrace();
    }
}

}

Detail : This problem is mainly arrived in android 4.3 when first time exception occur when we again going for prepare and start media recorder. this logic successfully work in 4.0.. i dont understand why this exception occur.

like image 901
Smith Avatar asked Mar 10 '14 07:03

Smith


1 Answers

It seems that if device decide to sleep, and GC decide to run, then this will be happen.

See below:

Sometimes (very rarely) the System will decide to Sleep in the middle of the GC run.

If the sleep time was long - over 10 seconds, the concurrent.timeout exception will be thrown.

How to handle :java.util.concurrent.TimeoutException: android.os.BinderProxy.finalize() timed out after 10 seconds errors?

like image 124
Stanley Ko Avatar answered Nov 11 '22 01:11

Stanley Ko