使用以下代码录制视频并使用videoView播放。
static final int VIDEO_CAPTURE = 101;
File mediaFile;
VideoView videoView;
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Uri videoUri = Uri.fromFile(mediaFile);
videoView.setVideoURI(videoUri);
videoView.requestFocus();
videoView.start();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video_rec);
videoView=(VideoView)findViewById(R.id.videoView);
mediaFile = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/myvideo.mp4");
Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
Uri videoUri = Uri.fromFile(mediaFile);
intent.putExtra(MediaStore.EXTRA_OUTPUT, videoUri);
startActivityForResult(intent, VIDEO_CAPTURE);
}
但是当我开始活动相机打开但是当我开始录制我的应用程序崩溃时。有什么问题?