I know that he was a little late to answer this question, but I think that I need that if others encounter this problem, they can easily handle it.
Actually the problem is that you are reducing the quality of the video with this
intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 0);
Camera Intent no longer works as a VCR. It really creates a millimeter when we try to reduce quality. Regarding time, I don't know if this is a bug in Android or there might be some memory limitations. Therefore, the decision I made is to create a custom video recording class using SurfaceView. So I am embedding a video code from one of my projects. Also, the recorded video is practically played on all Android and iOS devices that I have tested so far. Here is my video class
package com.mukesh.videorecordingsample; import android.app.Activity; import android.app.AlertDialog; import android.content.DialogInterface; import android.content.Intent; import android.hardware.Camera; import android.hardware.Camera.Size; import android.media.CamcorderProfile; import android.media.MediaRecorder; import android.os.Build; import android.os.Bundle; import android.os.Environment; import android.os.Handler; import android.os.Message; import android.util.Log; import android.view.KeyEvent; import android.view.Surface; import android.view.SurfaceHolder; import android.view.SurfaceView; import android.view.View; import android.view.View.OnClickListener; import android.view.Window; import android.widget.ImageView; import android.widget.TextView; import android.widget.Toast; import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; public class RecordVideoPostsActivity extends Activity implements SurfaceHolder.Callback, OnClickListener { protected static final int RESULT_ERROR = 0x00000001; private static final int MAX_VIDEO_DURATION = 8 * 1000; private static final int ID_TIME_COUNT = 0x1006; private SurfaceView mSurfaceView; private ImageView iv_cancel, iv_ok, iv_record; private TextView tv_counter; private SurfaceHolder mSurfaceHolder; private MediaRecorder mMediaRecorder; private Camera mCamera; private List<Size> mSupportVideoSizes; private String filePath; private boolean mIsRecording = false; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.activity_recordvideo); initView(); } private void initView() { mSurfaceView = (SurfaceView) findViewById(R.id.surfaceView); iv_record = (ImageView) findViewById(R.id.iv_record); iv_cancel = (ImageView) findViewById(R.id.iv_cancel); iv_ok = (ImageView) findViewById(R.id.iv_ok); iv_record.setImageResource(R.drawable.btn_video_start); tv_counter = (TextView) findViewById(R.id.timer); tv_counter.setVisibility(View.GONE); iv_cancel.setOnClickListener(this); iv_ok.setOnClickListener(this); iv_record.setOnClickListener(this); mSurfaceHolder = mSurfaceView.getHolder(); mSurfaceHolder.addCallback(this); } private void exit(final int resultCode, final Intent data) { if (mIsRecording) { new AlertDialog.Builder(RecordVideoPostsActivity.this) .setTitle("Video Recorder") .setMessage("Do you want to exit?") .setPositiveButton("yes", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { stopRecord(); if (resultCode == RESULT_CANCELED) { if (filePath != null) deleteFile(new File(filePath)); } setResult(resultCode, data); finish(); } }) .setNegativeButton("no", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }).show(); return; } if (resultCode == RESULT_CANCELED) { if (filePath != null) deleteFile(new File(filePath)); } setResult(resultCode, data); finish(); } private void deleteFile(File delFile) { if (delFile == null) { return; } final File file = new File(delFile.getAbsolutePath()); delFile = null; new Thread() { @Override public void run() { super.run(); if (file.exists()) { file.delete(); } } }.start(); } private Handler mHandler = new Handler() { @Override public void handleMessage(android.os.Message msg) { switch (msg.what) { case ID_TIME_COUNT: if (mIsRecording) { if (msg.arg1 > msg.arg2) {
and you can just call this class in your activity, like this
if (isDeviceSupportCamera()) { startActivityForResult(new Intent(PostStatusActivity.this, yourActivity.class), EmBazaarConstants.CAMERA_CAPTURE_VIDEO); } else { Toast.makeText(this, "Your device doesn't support camera", Toast.LENGTH_LONG).show(); }
and here isDeviceSupportCamera () function
private boolean isDeviceSupportCamera() { if (getApplicationContext().getPackageManager().hasSystemFeature( PackageManager.FEATURE_CAMERA)) { return true; } else { return false; } }
In your onActivityResult you need to write this code
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == EmBazaarConstants.CAMERA_CAPTURE_VIDEO && resultCode == RESULT_OK) { if (data != null && data.getStringExtra("videopath") != null) videoFilePath= data.getStringExtra("videopath"); } }
Hope this helps.
** Although we have the new Camera2 APIs in android lollipop, but this code still works in android lollipop. But still, you can upgrade to the new Camera2 APIs if you want.