Mediarecorder start failed -19 - android

I am getting this error when running start() for mediarecorder.
06-28 18:46:22.570: E/MediaRecorder(9540): start failed: -19
06-28 18:46:22.570: W/System.err(9540): java.lang.RuntimeException: start failed.
I am extending mediarecorder class
My code:
camera = Camera.open(cameraId);
super.setCamera(camera);
super.setVideoSource(MediaRecorder.VideoSource.CAMERA);
super.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);
if (mode==MODE_DEFAULT) {
super.setMaxDuration(1000);
super.setMaxFileSize(Integer.MAX_VALUE);
} else {
// On some phones a RuntimeException might be thrown :/
try {
super.setMaxDuration(0);
super.setMaxFileSize(Integer.MAX_VALUE);
} catch (RuntimeException e) {
Log.e(TAG,"setMaxDuration or setMaxFileSize failed !");
}
}
super.setVideoEncoder(videoEncoder);
if(surfaceHolder!=null)
super.setPreviewDisplay(surfaceHolder.getSurface());
//super.setVideoSize(quality.resX,quality.resY);
super.setVideoFrameRate(quality.frameRate);
super.setVideoEncodingBitRate(quality.bitRate);
I saw these pages
Error opening android camera for streaming video
Android MediaRecorder - "start failed: -19"
But non of them worked for me...
Running on archos 80 g9, android 3.2
Any one got any ideas?

Fixed by removing
super.setVideoFrameRate(quality.frameRate);

I was facing the same proble during video recording and i solved it by adding this for video recording
/**
* Start video recording by cleaning the old camera preview
*/
private void startVideoRecorder() {
// THIS IS NEEDED BECAUSE THE GLASS CURRENTLY THROWS AN ERROR OF
// "MediaRecorder start failed: -19"
// THIS WONT BE NEEDED INCASE OF PHONE AND TABLET
// This causes crash in glass kitkat version so remove it
// try {
// mCamera.setPreviewDisplay(null);
// } catch (java.io.IOException ioe) {
// Log.d(TAG,
// "IOException nullifying preview display: "
// + ioe.getMessage());
// }
// mCamera.stopPreview();
// mCamera.unlock();
recorder = new MediaRecorder();
// Let's initRecorder so we can record again
initRecorder();
}
/**
* Initialize video recorder to record video
*/
private void initRecorder() {
try {
File dir = new File(folderPath);
if (!dir.exists()) {
dir.mkdirs();
}
mCamera.stopPreview();
mCamera.unlock();
videofile = new File(dir, fileName + ".mp4");
recorder.setCamera(mCamera);
// Step 2: Set sources
recorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
// Step 3: Set a CamcorderProfile (requires API Level 8 or higher)
recorder.setProfile(CamcorderProfile
.get(CamcorderProfile.QUALITY_HIGH));
// Step 4: Set output file
recorder.setOutputFile(videofile.getAbsolutePath());
// Step 5: Set the preview output
recorder.setPreviewDisplay(mPreview.getHolder().getSurface());
// Step 6: Prepare configured MediaRecorder
recorder.setMaxDuration(video_duration * 1000);
recorder.setOnInfoListener(new OnInfoListener() {
#Override
public void onInfo(MediaRecorder mr, int what, int extra) {
if (what == MediaRecorder.MEDIA_RECORDER_INFO_MAX_DURATION_REACHED) {
mCamera.stopPreview();
releaseMediaRecorder();
/*
* initiate media scan and put the new things into the
* path array to make the scanner aware of the location
* and the files you want to see
*/MediaScannerConnection.scanFile(
CuxtomCamActivity.this,
new String[] { videofile.getPath() }, null,
null);
Intent intent = new Intent();
intent.putExtra(CuxtomIntent.FILE_PATH,
videofile.getPath());
intent.putExtra(CuxtomIntent.FILE_TYPE, FILE_TYPE.VIDEO);
setResult(RESULT_OK, intent);
finish();
}
}
});
recorder.prepare();
recorder.start();
} catch (Exception e) {
Log.e("Error Stating CuXtom Camera", e.getMessage());
}
}
private void releaseMediaRecorder() {
if (recorder != null) {
recorder.reset(); // clear recorder configuration
recorder.release(); // release the recorder object
recorder = null;
}
}
To see detail of how a camera is actually implemented refer to Open Source Cuxtom Cam

I found a subtle hint in documentation for the MediaRecorder.start() method that suggest if it fails to lock() the Camera before attempting to re-record. This worked for me. Implies a Camera state bug was fixed post API level 13 - calling Camera.lock() is the known workaround.

This code worked for me (found here)
mCamera.unlock(); // maybe not for your activity flow
//1st. Initial state
mProfile = CamcorderProfile.get( CamcorderProfile.QUALITY_HIGH );
mMediaRecorder = new MediaRecorder();
mMediaRecorder.setCamera( mCamera );
//2nd. Initialized state
mMediaRecorder.setAudioSource( MediaRecorder.AudioSource.CAMCORDER );
mMediaRecorder.setVideoSource( MediaRecorder.VideoSource.CAMERA );
//3rd. config
mMediaRecorder.setOutputFormat( mProfile.fileFormat );
mMediaRecorder.setAudioEncoder( mProfile.audioCodec );
mMediaRecorder.setVideoEncoder( mProfile.videoCodec );
mMediaRecorder.setOutputFile( "/sdcard/FBVideo.3gp" );
mMediaRecorder.setVideoSize( mProfile.videoFrameWidth, mProfile.videoFrameHeight );
mMediaRecorder.setVideoFrameRate( mProfile.videoFrameRate );
mMediaRecorder.setVideoEncodingBitRate( mProfile.videoBitRate );
mMediaRecorder.setAudioEncodingBitRate( mProfile.audioBitRate );
mMediaRecorder.setAudioChannels( mProfile.audioChannels );
mMediaRecorder.setAudioSamplingRate( mProfile.audioSampleRate );
mMediaRecorder.setPreviewDisplay( mHolder.getSurface() );
try {
mMediaRecorder.prepare();
mMediaRecorder.start();
} catch ( IllegalStateException e ) {
e.printStackTrace();
} catch ( IOException e ) {
e.printStackTrace();
}

The problem here is about the camera. Just use camera.unlock() to allow the media process to access the camera.
This must be done before calling MediaRecorder.setCamera(Camera). This cannot be called after recording starts.
Read more here.

Related

Unable to start mediarecorder for front camera, it throws illegalStateException start failed: -38

What is the meaning of start failed: -38?
I created two CameraView(Preview) Objects and one Camera Object.
Using Handlers I am able to switch the camera for some times, say, 10 secs open back camera and 10 secs open front camera.
Now I am facing some issue in recording front camera.
When I click the record button, first it will record back camera for 10 secs, and save it into sd card. and after 10 secs automatically it switches to front camera to record.
Back camera recording is working fine. But front camera preview is showing correctly, but it is not recording video, it says IllegalStateException start failed: -38 when I call mediarecorder.start();
here is the code
Prepare Media
mediaRecorder = new MediaRecorder();
mCamera.unlock(); // lock camera for later use
mediaRecorder.setCamera(mCamera); // lock camera for later use
//mediaRecorder.setCamera(mCamera); // lock camera for later use
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
//mediaRecorder.setOrientationHint(90);
mediaRecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_720P));
//mediaRecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_LOW));
//mediaRecorder.setVideoSize(320, 240);
//mediaRecorder.setVideoFrameRate(15);
//mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
//mediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
long l = System.currentTimeMillis();
mediaRecorder.setOutputFile("/sdcard/" + l + ".mp4");
mediaRecorder.setMaxDuration(600000); // Set max duration 60 sec.
mediaRecorder.setMaxFileSize(50000000); // Set max file size 50M
try {
mediaRecorder.prepare();
Log.e(TAG, "prepareMediaRecorder: ");
} catch (IllegalStateException e) {
releaseMediaRecorder();
return false;
} catch (IOException e) {
releaseMediaRecorder();
return false;
}
Log.e(TAG, "prepareMediaRecorder: RETURN TRUE");
Start Record
if (!prepareMediaRecorder()) {
Toast.makeText(getContext(), "Fail in prepareMediaRecorder()!\n - Ended -", Toast.LENGTH_LONG).show();
//finish();
return;
}
try {
Log.e(TAG, "recordBackCameraVideo: START START ");
mediaRecorder.start();
Log.e(TAG, "recordBackCameraVideo: START END ");
} catch (final Exception ex) {
Log.i("---", "Exception in thread");
}
recording = true;
Stop Recording
try {
Log.e(TAG, "stopRecording: STOP START");
mediaRecorder.stop(); // stop the recording
Log.e(TAG, "stopRecording: STOP END");
} catch (RuntimeException stopException) {
Log.e(TAG, "stopRecording: " + stopException.getMessage());
}
releaseMediaRecorder(); // release the MediaRecorder object
Toast.makeText(getContext(), "Video captured!", Toast.LENGTH_LONG).show();
recording = false;
Try this one. First you need to check CamcorderProfile.hasProfile("CameraID", "Pass your desired quality") If it is true then you can use that quality for video recording otherwise you need to use some other CamcorderProfile quality.
Below code is just for the reference which I used in my project you can change the code according to your need.
private boolean prepareMediaRecorder() {
mediaRecorder = new MediaRecorder();
CamcorderProfile profile = null;
if (!cameraFront) {
profile = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH);
} else {
if (CamcorderProfile.hasProfile(0, CamcorderProfile.QUALITY_HIGH)) {
profile = CamcorderProfile.get(0, CamcorderProfile.QUALITY_HIGH);
} else {
profile = CamcorderProfile.get(0, CamcorderProfile.QUALITY_LOW);
}
}
mCamera.unlock();
if (!cameraFront) {
// Back
mediaRecorder.setOrientationHint(90);
} else {
// Front
mediaRecorder.setOrientationHint(270);
}
mediaRecorder.setCamera(mCamera);
mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
mediaRecorder.setOutputFormat(profile.fileFormat);
mediaRecorder.setVideoEncoder(profile.videoCodec);
mediaRecorder.setVideoEncodingBitRate(profile.videoBitRate);
mediaRecorder.setVideoFrameRate(profile.videoFrameRate);
mediaRecorder.setOutputFile(Utils.getOriginalFileName());
mediaRecorder.setVideoSize(640, 480);
mediaRecorder.setMaxDuration(50000); // Set max duration 5 sec.
mediaRecorder.setMaxFileSize(50000000); // Set max file size 50M
try {
mediaRecorder.prepare();
} catch (IllegalStateException e) {
releaseMediaRecorder();
return false;
} catch (IOException e) {
releaseMediaRecorder();
return false;
}
return true;
}

IllegalStateException when reusing MediaRecorder instance

Hey I'm trying to make MediaRecorder record the contents of my screen. It works when I'm making a recording for a first time but when I try to record the screen for a second time it fails. Here is relevant code:
void startRecording(String directory,String filename,MediaProjection mediaProjection) {
this.mediaProjection=mediaProjection;
this.directory=directory;
this.filename=filename;
initRecorder();
prepareRecorder();
virtualDisplay = createVirtualDisplay();
mediaRecorder.start();
}
void stopRecording() {
mediaRecorder.stop();
mediaRecorder.reset();
if (virtualDisplay != null) {
virtualDisplay.release();
}
if (mediaProjection != null) {
mediaProjection.stop();
mediaProjection = null;
}
initRecorder();
prepareRecorder();
}
void setScreen(int screenWidth, int screenHeight, int screenDensity) {
this.screenWidth = screenWidth;
this.screenHeight = screenHeight;
this.screenDensity = screenDensity;
}
void prepareRecorder() {
try {
mediaRecorder.prepare();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
void initRecorder() {
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE);
mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
mediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
mediaRecorder.setVideoEncodingBitRate(512 * 1000);
mediaRecorder.setVideoFrameRate(30);
mediaRecorder.setVideoSize(screenWidth, screenHeight);
mediaRecorder.setOutputFile(directory + "/" + filename + ".mp4");
//mediaRecorder.setOutputFile(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES).getAbsolutePath()+"/vitalij.mp4");
}
So in my activity I create a new instance of this class once then after pressing the button the startRecording method get's invoked. Then user can press stop recording which calls stopRecording method. When app is destroyed i release the mediaRecorder object.
This is the error I get:
Caused by: java.lang.IllegalStateException
at android.media.MediaRecorder.setAudioSource(Native Method)
at com.example.xxx.myapplication.VideoRecorder.initRecorder(VideoRecorder.java:77)
at com.example.xxx.myapplication.VideoRecorder.startRecording(VideoRecorder.java:30)
at com.example.xxx.myapplication.MainActivity.onActivityResult(MainActivity.java:134)
I'm sure that I have the correct permissions set and the first video gets created fine. The problem only occurs when making the recording for a second time.
The issue is that you're executing these two lines of code:
initRecorder();
prepareRecorder();
at the end of your stopRecording() function and again in your startRecording() function.
When you try to call mediaRecorder.setAudioSource in initRecorder() after the audio source has already been set, you get an IllegalStateException because it's in the incorrect state.
If you look at the state diagram on the Android MediaRecorder reference page, you'll see that a MediaRecorder must be in the Initial state to call setAudioSource(), but yours is in the Prepared state after stopRecording() has been called and you try to call setAudioSource() again.

MediaRecorder start failed -19 and Camera error 100

I am developing an app to record video.
I got this code in my App which is running fine in Nexus 4 and Sony Ericsson mini pro, but when I test in other devices, like Archos 80G9 and Jiayu G3ST, the app gives me the following error
"MediaRecorder start failed -19"
or sometimes
"camera error 100 ".
I tried implementing some changes suggested in other stackoverflow posts but the error still appears.
private boolean prepareVideoRecorder() {
/** ADDED Sony Ericsson Stoped */
try {
mCamera.setPreviewDisplay(null);
} catch (java.io.IOException ioe) {
Log.d(TAG,
"IOException nullifying preview display: "
+ ioe.getMessage());
}
mCamera.stopPreview();
mMediaRecorder = new MediaRecorder();
// Step 1: Unlock and set camera to MediaRecorder
mCamera.unlock();
mMediaRecorder.setCamera(mCamera);
// Step 2: Set sources
mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
// Step 3: Set a CamcorderProfile (requires API Level 8 or higher)
CameraBackFront cm = new CameraBackFront();
int id = cm.getBackCameraId();
if (qualityString().equalsIgnoreCase("Low")) {
mMediaRecorder.setProfile(CamcorderProfile.get(id,
CamcorderProfile.QUALITY_LOW));
} else if (qualityString().equalsIgnoreCase("High")) {
mMediaRecorder.setProfile(CamcorderProfile.get(id,
CamcorderProfile.QUALITY_HIGH));
} else if (qualityString().equalsIgnoreCase("480p")) {
mMediaRecorder.setProfile(CamcorderProfile.get(id,
CamcorderProfile.QUALITY_480P));
} else if (qualityString().equalsIgnoreCase("720p")) {
mMediaRecorder.setProfile(CamcorderProfile.get(id,
CamcorderProfile.QUALITY_720P));
} else if (qualityString().equalsIgnoreCase("1080p")) {
try {
mMediaRecorder.setProfile(CamcorderProfile.get(id,
CamcorderProfile.QUALITY_1080P));
} catch (Exception e) {
mMediaRecorder.setProfile(CamcorderProfile.get(id,
CamcorderProfile.QUALITY_HIGH));
}
} else {
mMediaRecorder.setProfile(CamcorderProfile.get(0,
CamcorderProfile.QUALITY_HIGH));
}
// Step 4: Set output file
mMediaRecorder.setOutputFile(getOutputMediaFile(MEDIA_TYPE_VIDEO)
.toString());
/** ADD FILE NAME */
addFileNameDB();
// Step 5: Set the preview output
mMediaRecorder.setPreviewDisplay(mPreview.getHolder().getSurface());
// Step 6: Prepare configured MediaRecorder
try {
mMediaRecorder.prepare();
} catch (IllegalStateException e) {
Log.d(TAG,
"IllegalStateException preparing MediaRecorder: "
+ e.getMessage());
releaseMediaRecorder();
return false;
} catch (IOException e) {
Log.d(TAG, "IOException preparing MediaRecorder: " + e.getMessage());
releaseMediaRecorder();
return false;
}
return true;
}
I have tried:
put a thread.sleep(1000); before mediarecorder.start() but this gives me a error.
put a Default CameraPreview in development.android.com.
my app works with a custom CameraPreview that resized the preview.
I obtain the camera qualitys with CamcorderProfile.hasProfile(CamcorderProfile.QUALITY_720P) , because this always uses profiles that work on phone.
Finally i fix my problem using
...
releaseCamera();
if(prepareVideoRecorder){
...
}
before prepareVideoRecorder().
and into prepareVideoRecorder add a new instance of camera.
public void prepareVideoRecorder(){
mCamera = getCameraInstance();
...
}
With this things i have fixed:
MediaRecorder start failed -19.
Camera Error 100 (media server died and camera died ).

MediaRecorder, start failed: -19

Has anyone managed to successfully record a video using MediaRecorder on Glass?
This is the code i am using in order to prepare the Recorder. I keep getting error -19.
recorder = new MediaRecorder();
recorder.setOutputFile(videoFile);
recorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
recorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
recorder.setVideoFrameRate(15);
recorder.setVideoEncoder(MediaRecorder.VideoEncoder.DEFAULT);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
Thank you.
Update:
It seems to be a GDK bug. I have reported it and it got accepted. If you are having the same issue just star the bug report to stay informed:
https://code.google.com/p/google-glass-api/issues/detail?id=360
To start video capture on Glass it seems that you have to completely stop the video preview. If you are using a previewing camera, prior of doing anything with a MediaRecorder, just run:
try {
mCamera.setPreviewDisplay(null);
} catch (java.io.IOException ioe) {
Log.d(TAG, "IOException nullifying preview display: " + ioe.getMessage());
}
mCamera.stopPreview();
mCamera.unlock();
More info here: https://code.google.com/p/google-glass-api/issues/detail?id=360#c6
After much frustration and iteration, I'm pleased to report that it IS possible to use MediaRecorder on Glass XE12. The below code works for me on my Glass Version 1 running XE12:
mMediaRecorder = new MediaRecorder();
mMediaRecorder.setCamera(mCamera);
mMediaRecorder.setPreviewDisplay(preview.getHolder().getSurface());
mCamera.unlock();
// Step 2: Set sources
mMediaRecorder.setOnErrorListener(new android.media.MediaRecorder.OnErrorListener() {
public void onError(MediaRecorder mediarecorder1, int k, int i1)
{
Log.e(TAG,String.format("Media Recorder error: k=%d, i1=%d", k, i1));
}
});
mMediaRecorder.setVideoSource(0);
mMediaRecorder.setAudioSource(0);
mMediaRecorder.setOutputFormat(2);
mMediaRecorder.setVideoEncoder(2);
mMediaRecorder.setVideoEncodingBitRate(0x4c4b40);
mMediaRecorder.setVideoFrameRate(30);
mMediaRecorder.setVideoSize(1280, 720);
mMediaRecorder.setAudioChannels(2);
mMediaRecorder.setAudioEncoder(3);
mMediaRecorder.setAudioEncodingBitRate(0x17700);
mMediaRecorder.setAudioSamplingRate(44100);
mMediaRecorder.setMaxDuration(0);
mMediaRecorder.setOutputFile(getOutputMediaFile(MEDIA_TYPE_VIDEO).toString());
mMediaRecorder.setMaxDuration(-1);
// Step 5: Set the preview output
// Step 6: Prepare configured MediaRecorder
try {
mMediaRecorder.prepare();
mMediaRecorder.start();
} catch (IllegalStateException e) {
Log.d(TAG, "IllegalStateException preparing MediaRecorder: " + e.getMessage());
releaseMediaRecorder();
return false;
} catch (IOException e) {
Log.d(TAG, "IOException preparing MediaRecorder: " + e.getMessage());
releaseMediaRecorder();
return false;
} catch (Exception e) {
Log.d(TAG, "Unknown exception preparing MediaRecorder: " + e.getMessage());
releaseMediaRecorder();
return false;
}
When do you prepare the recorder, is it something that happens when you launch your application? If so, are you launching it with a voice trigger?
If both of those things are true, this might be an instance of the bug described here. Can you try the workaround in that thread (exponential backoff) and see if it works?

Recording video using MediaRecorder and FileOutputStream produces video file that can't be played

I am trying to implement the function where i can start and stop the video recording multiple times, and accumulate video data into a File.
This is how i prepare my media recorder:
private boolean prepareVideoRecorder(){
mMediaRecorder = new MediaRecorder();
//0 for landscape
//90 for portrait
//Check for available profile
CamcorderProfile profile = null;
if(CamcorderProfile.hasProfile(CamcorderProfile.QUALITY_480P)){
Log.d(TAG, "480p");
profile = CamcorderProfile.get(CamcorderProfile.QUALITY_480P);
}else if(CamcorderProfile.hasProfile(CamcorderProfile.QUALITY_720P)){
Log.d(TAG, "720p");
profile = CamcorderProfile.get(CamcorderProfile.QUALITY_720P);
}else{
Log.d(TAG, "LOW");
profile = CamcorderProfile.get(CamcorderProfile.QUALITY_LOW);
}
// Step 1: Unlock and set camera to MediaRecorder
mCamera.unlock();
mMediaRecorder.setCamera(mCamera);
// Step 2: Set sources
mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
// Step 3: Set profile
mMediaRecorder.setProfile(profile);
// Step 4: Set output file and pass media recorder the file descriptor
if(mStoreFile == null){
mStoreFile = MediaUtil.getOutputMediaFile(MediaUtil.MEDIA_TYPE_VIDEO);
try {
mStoreFile.createNewFile();
} catch (Exception e) {
e.printStackTrace();
}
}
try {
mOutputStream = new FileOutputStream(mStoreFile, true);
mMediaRecorder.setOutputFile(mOutputStream.getFD());
} catch (Exception e1) {
e1.printStackTrace();
}
mMediaRecorder.setMaxDuration(30000);
// Step 5: Set the preview output
mMediaRecorder.setPreviewDisplay(mPreviewSurface.getHolder().getSurface());
//Check orientation and set hint
switch(mOrientation){
case ORIENTATION_PORTRAIT_NORMAL:
mMediaRecorder.setOrientationHint(90);
break;
case ORIENTATION_PORTRAIT_INVERTED:
mMediaRecorder.setOrientationHint(270);
break;
case ORIENTATION_LANDSCAPE_NORMAL:
mMediaRecorder.setOrientationHint(0);
break;
case ORIENTATION_LANDSCAPE_INVERTED:
mMediaRecorder.setOrientationHint(180);
break;
}
// Step 6: Prepare configured MediaRecorder
try {
mMediaRecorder.prepare();
} catch (IllegalStateException e) {
Log.d(TAG, "IllegalStateException preparing MediaRecorder: " + e.getMessage());
releaseMediaRecorder();
return false;
} catch (IOException e) {
Log.d(TAG, "IOException preparing MediaRecorder: " + e.getMessage());
releaseMediaRecorder();
return false;
}
return true;
}
This is the button on click code:
#Override
public void onClick(View v) {
if (isRecording) {
try{
mOutputStream.close();
}catch(Exception ee){
}
// stop recording and release camera
mMediaRecorder.stop(); // stop the recording
mMediaRecorder.reset();
mCamera.lock(); // take camera access back from MediaRecorder
// inform the user that recording has stopped
mRecordButton.setImageResource(R.drawable.record_button);
isRecording = false;
} else {
// initialize video camera
if (prepareVideoRecorder()) {
// Camera is available and unlocked, MediaRecorder is prepared,
// now you can start recording
mMediaRecorder.start();
// inform the user that recording has started
mRecordButton.setImageResource(R.drawable.record_button_on);
isRecording = true;
} else {
// prepare didn't work, release the camera
releaseMediaRecorder();
// inform user
}
}
}
});
MediaUtil.getOutputMediaFile(MediaUtil.MEDIA_TYPE_VIDEO) will give me something like:
/storage/sdcard0/Pictures/Project/VID_2013.mp4
Current problem:
The way i test it at the moment is by:
Start recording
Stop Recording
Start recording
stop recording
Go to android's file manager on /Pictures/Project path
I can see the file that was created and "appended" with multiple segments of data. But it won't play. And it doesn't have a cover image like other video files.
Somewhere along the line, the file is corrupted? It doesn't work as well if i just record once and check the file in the storage. I am able to record video if i just define a File for the MediaRecorder in setOutputFile, but i'm trying append video data for multiple shoot. Is this possible?

Categories

Resources