If you have ever used Android MediaRecorder to record video or audio in your android application, you must have faced this error. Recently I had nightmare in using MediaRecorder in my android application. I think it's most unstable class in Android SDK and there is a different behavior in each device. In this blog I am going to explain more about this and possible resolution of this.
First lets see wha's the meaning of this error : Android MediaRecorder Stop Failed - 1007
There is no documentation on Android developer site about this error code but from my experience I found out that there are three reasons behind this error
1) You called stop method too early.
According to documentation on MediaRecorder.java class it says
Stops recording. Call this after start(). Once recording is stopped, you will have to configure it again as if it has just been constructed. 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.
That means if you start recording and in couple of seconds you call stop recording there is no significant data of recording hence stop method throws an exception. So you must wait for sometime. From my testing I found out that you should at least for minimum 10 seconds. So the solution is to have stop method called inside try catch block and handle the exception properly or do not allow user to stop recording till 10 seconds of start of recording. You can either disable stop button and make it enable after sometime. Once the exception is thrown, you should clean the the resources, release media recorder and camera and all other objects.
2) Error in Writing to Output file
We have to set output file to MediaRecorder when we start recording. When you stop all the recorded data will be appended in output file specified by you on start. This could failed due to reasons like insufficient space to write file or you don't have permissions to write to external and internal storage due in Android 6.0 on words.
3) MisMatch in preview size and video size set in MediaRecorder
I have mentioned about this in my previous blog. You can read it here.
Android MediaRecorder Start Failed - 19
Hope this helps you and save you time.
First lets see wha's the meaning of this error : Android MediaRecorder Stop Failed - 1007
There is no documentation on Android developer site about this error code but from my experience I found out that there are three reasons behind this error
1) You called stop method too early.
According to documentation on MediaRecorder.java class it says
Stops recording. Call this after start(). Once recording is stopped, you will have to configure it again as if it has just been constructed. 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.
That means if you start recording and in couple of seconds you call stop recording there is no significant data of recording hence stop method throws an exception. So you must wait for sometime. From my testing I found out that you should at least for minimum 10 seconds. So the solution is to have stop method called inside try catch block and handle the exception properly or do not allow user to stop recording till 10 seconds of start of recording. You can either disable stop button and make it enable after sometime. Once the exception is thrown, you should clean the the resources, release media recorder and camera and all other objects.
2) Error in Writing to Output file
We have to set output file to MediaRecorder when we start recording. When you stop all the recorded data will be appended in output file specified by you on start. This could failed due to reasons like insufficient space to write file or you don't have permissions to write to external and internal storage due in Android 6.0 on words.
3) MisMatch in preview size and video size set in MediaRecorder
I have mentioned about this in my previous blog. You can read it here.
Android MediaRecorder Start Failed - 19
Hope this helps you and save you time.
thank u
ReplyDelete