0

I am using a button to pick videos from device like

dStatus.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
                photoPickerIntent.setType("video/*");
                startActivityForResult(photoPickerIntent, SELECT_VIDEO);
            }
        });

Then in the onActivityResult I have something like this

protected void onActivityResult(int requestCode, int resultCode, Intent data)
    {
        super.onActivityResult(requestCode, resultCode, data);
        switch(requestCode) {
            case SELECT_VIDEO:
                if (resultCode == RESULT_OK) {
                    Uri selectedVideo = data.getData();
                    final String realPath = selectedVideo.getPath();
                 }
                break;
        }
    }

The realPath which I need is the location to the file in the device like /directory/subdirectory/myVideo.mp4. I have tried a lot of posts previously from stackoverflow itself. All results lead to the value of realPath as null. The posts which I tried are

  1. GetRealPathFromUri always get null result
  2. Get filename and path from uri from mediastore
  3. Get Real Path For Uri Android

So if you know any way that works, suggest me below. Dont mark as duplicate and other stuff. I know nothing is working.

Community
  • 1
  • 1
Kalai Arasi
  • 249
  • 1
  • 6
  • 16
  • `The realPath which I need is the location to the file in the device like /directory/subdirectory/myVideo.mp4.`. You did not tell why. Please tell. – greenapps Jun 06 '15 at 07:22
  • `final String realPath = selectedVideo.getPath();`. Did you say that realPath==null? If not, what is it? – greenapps Jun 06 '15 at 07:24
  • i need in that format, with the real path not the content uri. The selectedVideo.getPath() returns some other value. I need the real path.If you have any solution, please share. – Kalai Arasi Jun 06 '15 at 10:13
  • `I need the real path.`. You did not tell why. Please tell. – greenapps Jun 06 '15 at 10:15
  • `selectedVideo.getPath() ` Other value? Please tell what it returns. – greenapps Jun 06 '15 at 10:16
  • You did not tell that you use Lollipop. Do you? Try to pick a picture and you will se the same. – greenapps Jun 06 '15 at 10:23
  • I need the realpath to send the FFMPEG to edit the video, I think you can suggest me how do I get that done, more than worrying about why I need it ? – Kalai Arasi Jun 06 '15 at 10:28
  • You also did not tell which Android target version you are compiling for. – greenapps Jun 06 '15 at 10:53

1 Answers1

0

This method returns you the real path from the contentUri of the video.

public String getRealPathFromURI(Context context, Uri contentUri) {

        String res = "";
        String[] proj = { MediaStore.Video.Media.DATA };
        Cursor cursor = context.getContentResolver().query(contentUri, proj, null, null, null);
        if (cursor != null) {
            if (cursor.moveToFirst()) {
                int column_index = cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA);
                res = cursor.getString(column_index);
            }
            cursor.close();
        } else {
            Log.d(TAG, "Cursor is null");
            return contentUri.getPath();
        }
        return res;
    }
Kartheek
  • 7,104
  • 3
  • 30
  • 44