Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - How to start recording video automatically when calling the camera intent

The Android Dev has some easy code describing how to start the camcorder via Intents.

Now this is good if you just want to start up the camera and wait for the user to press the red "REC" button.

But I want to call the camcorder via Intent and tell it to start recording programmatically.

How to I do that? Do I pass some kind of start() method in the Intent command?

(if it can't be done, please show me a simple code bit that can be set up to record video automatically - I have been searching the web, but all codesnippets regarding this issue don't work)

private static final int CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE = 100;
private Uri fileUri;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

// create Intent to take a picture and return control to the calling application
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE); // create a file to save the image
intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); // set the image file name

// start the image capture Intent
startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
}
like image 428
user1020196 Avatar asked Nov 14 '22 15:11

user1020196


1 Answers

For this you should use MediaRecorder class.

Please have a look at this :

http://developer.android.com/reference/android/media/MediaRecorder.html

like image 87
Ravi Sharma Avatar answered Dec 28 '22 08:12

Ravi Sharma