Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android cancel a mediarecording

I was wonderinging, is it possible to cancel a media recording. By cancel I mean do not save it. Currently I am starting a recording by doing this:

protected void startRecording() throws IOException 
{
    mrec = new MediaRecorder();  // Works well
    mCamera.unlock();

    mrec.setCamera(mCamera);

    mrec.setPreviewDisplay(surfaceHolder.getSurface());
    mrec.setVideoSource(MediaRecorder.VideoSource.CAMERA);
    mrec.setAudioSource(MediaRecorder.AudioSource.MIC); 

    mrec.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH));
    mrec.setPreviewDisplay(surfaceHolder.getSurface());

    File picDirectory = new File(Environment.getExternalStorageDirectory() +"/TrouwApp");
    picDirectory.mkdirs();

    mrec.setOutputFile( Environment.getExternalStorageDirectory() +"/TrouwApp/"  + date + "_" + videonr+ ".3gp"); 

    mrec.prepare();
    mrec.start();

    Log.d(TAG, "Recording started!!");
}

And save and stop it with:

protected void stopRecording() {    
    mrec.stop();
    mrec.release();
    mCamera.release();     
}

I want to make two buttons. One to save the media file(calling stopRecording()). And a second to cancel and delete the media recording. Is this even possible? If yes, how?

like image 634
Robin Dijkhof Avatar asked Jan 12 '23 15:01

Robin Dijkhof


1 Answers

Just delete created file

protected void stopAndDelete(){
    stopRecording();
    File file = new File(Environment.getExternalStorageDirectory() +
        "/TrouwApp/"  + date + "_" + videonr+ ".3gp");
    file.delete();
}
like image 169
Mieszko Avatar answered Jan 22 '23 21:01

Mieszko