I'm using the following code to record the camera in Android that uses the basic Intent
. How can I change it to use MediaRecorder
API instead of this Intent-based approach?
private Uri fileUri;
//...
private void recordVideo() {
Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
fileUri = getOutputMediaFileUri(MEDIA_TYPE_VIDEO);
// set video quality
intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); // set the image file
// start the video capture Intent
startActivityForResult(intent, CAMERA_CAPTURE_VIDEO_REQUEST_CODE);
}
// ...
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAMERA_CAPTURE_IMAGE_REQUEST_CODE && resultCode == RESULT_OK) {
// play the video given the global fileUri
}
I don't use the Android SDK (my Java skills are on Windows only), but from a quick research...
See if this tutorial helps you (more info further beow)...
Just replace their audio setup (3GP) with the H264 & AAC setup from the other Question.
Also read the section about "Recording Video" on this article to understand the needed parts.
Also declare permissions in your Manifest.xml. An example of such manifest and related code is here on Github (that one allows
RECORD_AUDIO
but you need also aRECORD_VIDEO
so set as):Back to the tutorial, I cannot test their code but something like the below edit should get you started:
Then inside that class you add useful functions (initialise Recorder, start rec, stop rec, save file)...
So to begin a recording, just inititalise the media recorder and do a
recorder.start();
to begin recording (camera and mic are used automatically according to your MediaRecorder settings).