Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Video capture in Android 4.3 using Camera app intent

How do you capture Video by calling the Android camera app using an intent in 4.3. I had it working in 4.2 and below. Even Google's sample is broken. Is this a bug? Or has Google changed how they return recorded video. Image capture still works.

I still get a RESULT_OK back but the intent data is null on MediaStore.ACTION_VIDEO_CAPTURE intents.

like image 273
kasgoku Avatar asked Aug 27 '13 18:08

kasgoku


1 Answers

The problem

Yes, there is a bug starting with Android 4.3 release.

As the documentation says:

If EXTRA_OUTPUT is not present the video will be written to the standard location for videos, and the Uri of that location will be returned in the data field of the Uri.

What I have experienced is that the returned data field value is Null instead of containing the video file's Uri.


The solution

For now, is to pass MediaStore.EXTRA_OUTPUT to the Intent specifying the output location for the video file if the device's API Version is 18. This works as intended.

Since you were using the default gallery location for storing your videos, my guess is that you will want to keep it the same. So for this you need to set EXTRA_OUTPUT as follows.

  1. Insert a new record into MediaStore.Video.Media.EXTERNAL_CONTENT_URI:

    Uri videoUri = context.getContentResolver().insert(EXTERNAL_CONTENT_URI, value);
    

    Being value a ContentValues with display name, file type and file path to the new video file. E.g. :

    ContentValues value = new ContentValues();
    value.put(MediaStore.Video.Media.TITLE, "VideoTitle");
    value.put(MediaStore.Video.Media.MIME_TYPE, "video/mp4");
    value.put(MediaStore.Video.Media.DATA, videoFilePath);
    
  2. Pass the returned value, videoUri, as the EXTRA_OUPUT to the Intent.

like image 180
Juan Andrés Diana Avatar answered Nov 16 '22 21:11

Juan Andrés Diana