android-Camera2Video icon indicating copy to clipboard operation
android-Camera2Video copied to clipboard

100% success to crash the app: Press start immediately followed by stop

Open neilyoung opened this issue 10 years ago • 2 comments

Excepts always with java.lang.IllegalStateException

What is the way to prevent that?

neilyoung avatar Jan 20 '16 09:01 neilyoung

According to its doc: note that a RuntimeException is intentionally thrown to the application if no valid audio/video data has been received when stop() is called. This happens if stop() is called immediately after start().The failure lets the application take action accordingly to clean up the output file (delete the output file, for instance), since the output file is not properly constructed when this happens.

Stupid workaround according to someone's blog:

          try {  
                mediarecorder.setOnErrorListener(null);  
                mediarecorder.setOnInfoListener(null);    
                mediarecorder.setPreviewDisplay(null);  
                mediarecorder.stop();  
            } catch (IllegalStateException e) {  
                Log.i("Exception", Log.getStackTraceString(e));  
            }catch (RuntimeException e) {  
                Log.i("Exception", Log.getStackTraceString(e));  
            }catch (Exception e) {  
                Log.i("Exception", Log.getStackTraceString(e));  
            }  

tzutalin avatar Mar 20 '17 09:03 tzutalin

This sample has been migrated to a new location where we can accept Pull Requests (check README for more information).

As recommended by GitHub, we are closing all issues and pull requests now that this older repo will be archived.

If you still see this issue in the updated repo, please reopen the issue/PR there. Thank you!

codingjeremy avatar Sep 19 '19 22:09 codingjeremy