17

Is there a stand-alone sample code for video capturing in Android ?

4 Answers 4

23

Here is what I provide to my students: Camcorder Source

3
  • Change Camcorder -> onKeyDown :: KeyEvent.KEYCODE_DPAD_CENTER to KEYCODE_SEARCH if your phone doesn't have a physical keyboard. That way hitting search will turn on and off the recording. Also note that the Camcorder Activity calls finish() when you stop recording, which closes the app.
    – JoJo
    Jul 28, 2011 at 0:35
  • 1
    This is awesome but I'm having a hard time get the app to show a preview before it starts recording.
    – neufuture
    Aug 7, 2011 at 19:19
  • hello @vanevery is there any way to record device screen video as wel as audio..please let me know if it is Thanks.
    – Poison
    Jan 29, 2014 at 6:11
3

Not sure why I didn't think of this sooner. If you're just looking to capture a video so you can take that video and upload it to a server (or do something similar) you can use the native camera app extremely easily using intents.

Launch the intent, capture the video, then return to your activity, and access the video via onActivityResult.

// Setup a result flag for your video capture
int ACTION_TAKE_VIDEO = 100;

// Launch an intent to capture video from MediaStore
Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
startActivityForResult(takeVideoIntent, ACTION_TAKE_VIDEO);

// Obtain the file path to the video in onActivityResult
public void onActivityResult(int requestCode, int resultCode, Intent data) {

if (resultCode == RESULT_OK) {

    if (requestCode == ACTION_TAKE_VIDEO) {

        Uri videoUri = data.getData();
        String filePath = getPath(videoUri);
        Log.d("LOGCAT", "Video path is: " + filePath);
    }
}

More at http://developer.android.com/training/camera/videobasics.html

2

I found a good solution from here

1
  • hello @krishna is there any way to record device screen video as wel as audio..please let me know if it is Thanks.
    – Poison
    Jan 29, 2014 at 6:12
0

I am not aware of a stand-alone code sample, but in the Android camera documentation, in the Class overview, there is a very nice step by step procedure that shows you how to record video.

I think is nearly as well as a sample code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.