How to select file from memory?

0

I'm trying to make a video player, but not using the "raw" or internet, I need to get the file from the memory of the phone, be it internal memory or sd card memory, I already tried through the path obtained by a " files "but when I put it in the Uri.parse of the videoViewer, it says it can not play the file:

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_video_pasta);
        VideoView video = (VideoView) findViewById(R.id.videoView);
        video.setVideoURI(Uri.parse("/storage/emulated/0/Download/video.mp4"));
        video.setMediaController(new MediaController(this));
    }
}

Would anyone have any idea how to do it?

    
asked by anonymous 04.11.2017 / 06:53

1 answer

0

It tries to transform into this format, which is for access to internal memory:

Uri.fromFile(new File("/sdcard/Download/video.mp4"))

or

String filePath = getApplication().getFilesDir().getAbsolutePath()
                + File.separator + "video.mp4";
        File f = new File(filePath);
        if (f.exists()) {
            Uri internal = Uri.fromFile(f);
            video.setVideoURI(internal);

To access files in SDCARD you should use the getExternalStorageDirectory () function, for example:

File files= Environment.getExternalStorageDirectory(Environment.DIRECTORY_MOVIES);
    
04.11.2017 / 13:19