Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the video path of capture video using default camera in android

Tags:

android

I am declaring a global variable for String selectedImagePath. On button click I am calling video capture code

Intent intent=new Intent("android.media.action.VIDEO_CAPTURE");
intent.putExtra("android.intent.extra.durationLimit", 120);  
startActivityForResult(intent, REQUEST_VIDEO_CAPTURED);

OnActivity result I am getting video path selectedImagePath = getPath(selectedImageUri);

onActivityResult Code I am getting the value here properly

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
 // TODO Auto-generated method stub

 if(resultCode==RESULT_OK)
 {
  if(requestCode==REQUEST_VIDEO_CAPTURED)
  {
      Toast.makeText(VideoPostActivity.this, "Video Recorded", Toast.LENGTH_LONG).show();
      Uri selectedImageUri = data.getData();   

       selectedImagePath = getPath(selectedImageUri);

       System.out.println("selected image path"+selectedImagePath);

      /* imgPublishVideo.setEnabled(true);
          imgRecordVideo.setEnabled(false);*/





  }


 }
  if(resultCode == RESULT_CANCELED)
 {
 Toast.makeText(VideoPostActivity.this,  "Cancelled!",  Toast.LENGTH_LONG).show();

 }


 }

I am not getting value here

SetMyVideoPostAsyncTask myVideoPostAsyncTask=new SetMyVideoPostAsyncTask(VideoPostActivity.this,videoTitle,videoComment,selectedImagePath);
myVideoPostAsyncTask.execute();

public String getPath(Uri uri)
{       
        String[] projection = { MediaStore.Images.Media.DATA };        
        Cursor cursor = managedQuery(uri, projection, null, null, null);        
        if(cursor!=null)         
        {            

            int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);          
            cursor.moveToFirst();          
            return cursor.getString(column_index);       
            }       
        else 
            return null;    
}

but I am not able to pass selectedImagePath value from activity it is going null can anybody tell what is problem? What do I do?

like image 782
mohan Avatar asked Oct 13 '11 15:10

mohan


1 Answers

Try this instead:

private String videoPath = "";

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if(resultCode==RESULT_OK)
    {

      Uri vid = data.getData();
      videoPath = getRealPathFromURI(vid);
    }


}

public String getRealPathFromURI(Uri contentUri) {
    String[] proj = { MediaStore.Images.Media.DATA };
    Cursor cursor = managedQuery(contentUri, proj, null, null, null);
    int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
    cursor.moveToFirst();
    return cursor.getString(column_index);
}
like image 158
Seantron Avatar answered Oct 01 '22 19:10

Seantron