Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android MediaStore.ACTION_VIDEO_CAPTURE, external path?

Tags:

android

video

I use the MediaStore.ACTION_VIDEO_CAPTURE intent class to capture the video, the video stored in default location(gallery),i want to store the video in specific location with specific name.

I use MediaStore.EXTRA_MEDIA_TITLE and MediaStore.EXTRA_MEDIA_OUTPUT but I don`t get the video at correct location, at least I need the path of recorded video.

Thanks in advance.

like image 237
Karthi Avatar asked Feb 14 '11 09:02

Karthi


1 Answers

The solution from Zelimir doesn't work in my case (the videos were at the right location but had a size of zero bytes). So i've found another solution:

protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
  super.onActivityResult(requestCode, resultCode, intent);

  if (resultCode != RESULT_OK) return;

  try {
    AssetFileDescriptor videoAsset = getContentResolver().openAssetFileDescriptor(intent.getData(), "r");
    FileInputStream fis = videoAsset.createInputStream();
    File tmpFile = new File(Environment.getExternalStorageDirectory(),"VideoFile.3gp"); 
    FileOutputStream fos = new FileOutputStream(tmpFile);

    byte[] buf = new byte[1024];
    int len;
    while ((len = fis.read(buf)) > 0) {
        fos.write(buf, 0, len);
    }       
    fis.close();
    fos.close();
  } catch (IOException io_e) {
    // TODO: handle error
  }

}

The MediaStore.EXTRA_OUTPUT and the Uri aren't necessary in this case.

like image 145
René Fischer Avatar answered Oct 29 '22 19:10

René Fischer