How to select memory file?

Asked

Viewed 57 times

0

I am trying to make a video player, but not using "raw" or the internet, I need to get the file from the mobile memory, be it internal memory or sd card memory, I have tried through the path obtained by a "file manager" but when I put it to Uri.parse from videoViewer, it says it can’t 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?

1 answer

0

Try to transform in 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 the SDCARD you must use the function getExternalStorageDirectory (), example:

File files= Environment.getExternalStorageDirectory(Environment.DIRECTORY_MOVIES);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.