0

I am creating an Android app which calls the built-in camera to capture a video and then display it in a preview.

This is the code.

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        vid1 = (VideoView) findViewById(R.id.videoView);
        btn1 = (Button) findViewById(R.id.button);

        btn1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i1 = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
                if(i1.resolveActivity(getPackageManager()) != null) {
                    startActivityForResult(i1, 123);
                }
            }
        });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        if(requestCode == 123 && resultCode == RESULT_OK) {
            Log.d("hi", data.getData().getPath());
            Uri myvideolink = data.getData();
            vid1.setVideoURI(myvideolink);
        }
    }

What is happening is, the data.getData() is giving me a path from external storage whereas the video is saved in the internal storage, DCIM folder. That is, the log statement,

Log.d("hi", data.getData().getPath());

is giving me this

/hi: /external/video/media/162872

So,

  1. How do I avoid this and get the right path so that the video is displayed in the preview?
  2. Is there any commands/libraries using which I can retrieve the path of the most recent video captured from the internal storage, DCIM? (I need this because after displaying preview, I also need to send it to a server)
Keerthan Bhat
  • 314
  • 2
  • 15
  • The video is being stored on what the Android SDK refers to as [external storage](https://commonsware.com/blog/2017/11/14/storage-situation-external-storage.html). Second, you are not looking at the scheme of your `Uri`, which in this case is `content`. That `Uri` should work in `VideoView`. – CommonsWare Jun 24 '19 at 16:24
  • Answer available at : https://stackoverflow.com/a/8554433/10941112 – Saswata Jun 24 '19 at 16:44
  • Possible duplicate of [Getting the video path of capture video using default camera in android](https://stackoverflow.com/questions/7756349/getting-the-video-path-of-capture-video-using-default-camera-in-android) – Saswata Jun 24 '19 at 16:46

0 Answers0