0

i'm trying to create an app that allows video recording. i know that using MediaStore.ACTION_IMAGE_CAPTURE, it actually calls the camera system from my app and after taking the picture, it will return to my app with result.

while using the code, i found a MediaStore.ACTION_VIDEO_CAPTURE. which i assume it will camera but in video mode, rather then image capturing mode.

the code that i used for calling the camera in video mode:

Intent takeVideoFromCameraIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
Uri mUri = Uri.fromFile(new File(Environment.getExternalStorageDirectory(), "/Record/vid_"+ String.valueOf(System.currentTimeMillis()) + ".mp4"));
takeVideoFromCameraIntent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, mUri);
startActivityForResult(takeVideoFromCameraIntent, RESULT_OK);

when i run the app with a real device, it does call the camera in video mode and also allows video recording. however, when i press the record button to finish recording, it returns to my app with a force close message saying that the camera is not responding.

at 1st, i thought that the video has not been captured, but when i searched for the file, it actually exist.

then, i thought its my onActivityResult method that causes the problem, but after i comment it with /* ... */ , it still have the same problem. but there isn't any details shown in LogCat.

starvi
  • 519
  • 4
  • 15
  • 29

3 Answers3

3

i realize that i got the error because i'm adding extra to it. what i just needed to do is

Intent takeVideoFromCameraIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
startActivityForResult(takeVideoFromCameraIntent, 1111);

then, add an onActivityResult, with the request code == 1111 (depends on what you entered) and retrieve the last modified file that consist of the extension ".mp4" from the default folder of camera "DCIM/Camera"

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) 
{
    super.onActivityResult(requestCode, resultCode, data);

    if(requestCode == 1111)//cam
    {
         File folder = new File(Environment.getExternalStorageDirectory(), "/DCIM/Camera");
         long folderModi = folder.lastModified();

    FilenameFilter filter = new FilenameFilter() 
    {
        public boolean accept(File dir, String name) 
        {
            return (name.endsWith(mp4));
        }
    };

    File[] folderList = folder.listFiles(filter);

    String recentName = "";

    for(int i=0; i<folderList.length;i++)
    {
        long fileModi = folderList[i].lastModified();

        if(folderModi == fileModi)
        {
            recentName = folderList[i].getName();
        }
    }
}

this way, i can get the name of the file and also do the modification (e.g renaming) with it.

hope this would help other people. =)

starvi
  • 519
  • 4
  • 15
  • 29
0

please,add your logcat. For the video capture, i am using the MediaRecorder class, I suggest you tu use this. If you are interested, i can give you the right code.

Milos Cuculovic
  • 19,631
  • 51
  • 159
  • 265
  • there isnt anything in the logcat. thanks, but i'm hopping to use a easy and simple code that i understand, as what i know, MediaRecorder seems to be a complicated one. – starvi Jan 28 '12 at 08:30
  • No, it is very simple to use the MediaRecorder, I will post an exemple if you will try it. – Milos Cuculovic Jan 29 '12 at 10:10
0

I think, your problem is resolved by using this code.


//create new Intent

 Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);

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

    intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1); // set the video image quality to high

    // start the Video Capture Intent
    startActivityForResult(intent, CAPTURE_VIDEO_ACTIVITY_REQUEST_CODE);

Use this code in an activity and also set some property in xml file.
<uses-feature android:name="android.hardware.camera" android:required="false" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />

If you have another problem, please reply me.

Manoj Kumar
  • 587
  • 2
  • 9
  • 20
  • erm... well... the code you provided consist of error saying that i do not have the variable. may i know where do you get it (e.g MEDIA_TYPE_VIDEO) – starvi Jan 28 '12 at 09:51
  • public static final int MEDIA_TYPE_VIDEO = 2; – Manoj Kumar Jan 28 '12 at 09:55
  • hi, where did you get the method getOutputMediaFileUri ? is it not possible of you to tell me what went wrong with my codes ? thanks – starvi Jan 28 '12 at 17:40