Mediarecorder Ioexception: Prepare Failed
Solution 1:
This is a big problem but has a very small solution
In most cases, the filename that we get from this.file.getAbsolutePath() contains file:/// as a prefix
////////////////////////////////////////////////* INCORRECT CODE */
this.mediaRecorder.setOutputFile(this.file.getAbsolutePath());
/*the above line sets a file url beginning with a "file:///"
//however, since this setOutputFile requires us to send a
//string referring to the uri, we will have to get rid of the
//"file:///"and simply write the uri */
////////////////////////////////////////////////* CORRECTED CODE BELOW */
this.mediaRecorder.setOutputFile(this.file.getAbsolutePath().substring(8));
/*the above line of code extracts the string uri eliminating
// file:/// */
Hope you find this answer helpful
Solution 2:
First at all you code looks fine. Have you added the required permissions to your manifest file?
<uses-permissionandroid:name="android.permission.WRITE_EXTERNAL_STORAGE" /><uses-permissionandroid:name="android.permission.RECORD_AUDIO" />
If yes, then try replacing:
this.mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
by
this.mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
Don't forget to check if the path of your video file is correct.
Solution 3:
This Exception will be raised . if any of the following things failed:
file not found: Ensure that output file location that yu have specified is existing, otherwise it will throw you filenotfoundexception
Write Permission: You must specify Write permission in your manifest file.
Record permission : specify Record permission in your manifest file.
you can use this..
<uses-permissionandroid:name="android.permission.WRITE_EXTERNAL_STORAGE"/><uses-permissionandroid:name="android.permission.RECORD_AUDIO"/>
Still you get error.. try display the error. Like this
try{
mRecorder.prepare();
} catch (IOException e) {
Log.e(LOG_TAG, "prepare() failed");
System.out.println(""+e); //to display the error
}
mRecorder.start();
Solution 4:
I deleted
this.mediaRecorder.setAudioEncodingBitRate(16);
at method 2 and now it's working.
Solution 5:
For devices targeting version >= 10+ , you need to use MediaStore api, in my case file could not be found because the file is out of my app's scoped storage.
Post a Comment for "Mediarecorder Ioexception: Prepare Failed"