系统录制
Intent intent=new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY,0);
intent.putExtra(MediaStore.EXTRA_SIZE_LIMIT,10485760L);
intent.putExtra(MediaStore.EXTRA_DURATION_LIMIT,10);
startActivityForResult(intent,VIDEO_CAPTURE);
本篇介绍MediaRecorder 和 SurfaceView 录制方法
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.lifecycle.Observer;
import android.Manifest;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Point;
import android.hardware.Camera;
import android.media.MediaPlayer;
import android.media.MediaRecorder;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.util.Log;
import android.view.Display;
import android.view.Surface;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import java.io.File;
import java.io.IOException;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.TimeUnit;
public class MainActivity extends Activity implements SurfaceHolder.Callback {
private SurfaceView surfaceView;
private ImageView recorderBtn;
private ImageView recorder_btn_car;
private ImageView recorder_btn_s;
private ImageView iv_confirm;
private ImageView iv_relase;
private VideoFullScreen video_view;
private RelativeLayout rl_bottom;
private TextView tv_time;
private MediaRecorder recorder;
private boolean isStart = false;
private boolean recorded = false;
private Camera camera;
private SurfaceHolder holder;
private String path;
private Camera.Size size;
private int facingBack = Camera.CameraInfo.CAMERA_FACING_BACK;
private boolean isBack = true;
private boolean isSource = true;
private String mCurrentPath;
private int mWidth = 1280;
private int mHeight = 720;
private static final int REQUEST_PERMISSION = 1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
init();
Display display = getWindowManager().getDefaultDisplay();
mWidth = display.getHeight();
mHeight= display.getWidth();
recorderBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!isStart) {
startTimer(16);
recorderBtn.setSelected(true);
recorder_btn_car.setVisibility(View.GONE);
recorder_btn_s.setVisibility(View.GONE);
startRecorder();
isStart = true;
} else {
recorderBtn.setSelected(false);
recorder_btn_car.setVisibility(View.VISIBLE);
recorder_btn_s.setVisibility(View.GONE);
if (mDisposable !=null) {
mDisposable.cancel();
mDisposable = null;
}
stopRecorder();
startVideo();
isStart = false;
}
}
});
recorder_btn_car.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
isBack = !isBack;
if (isBack) {
facingBack = Camera.CameraInfo.CAMERA_FACING_BACK;
}else {
facingBack = Camera.CameraInfo.CAMERA_FACING_FRONT;
}
releaseCamera();
initPreview();
}
});
recorder_btn_s.setSelected(true);
recorder_btn_s.setOnClickListener(new View.OnClickListener(