'Could not play video in the path (/storage/emulated/0/Android/data/com...)

I have saved my video internally on the phone with the following code :

public static void DownloadVideo(Context context, String URL) {

        DownloadManager.Request request = new DownloadManager.Request(Uri.parse(URL));
        Date date = new Date();
        SimpleDateFormat videoName = new SimpleDateFormat("yyyymmdd_HHmmss");
        String strDate = videoName.format(date);
        request.setDescription("Setting up the AR");
        request.setTitle("AR setup ...");

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            request.allowScanningByMediaScanner();
            request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
        }

        request.setDestinationInExternalFilesDir(context, "/NewVisionARVideos/", "" + strDate + System.currentTimeMillis() + ".mp4");

        System.out.println("count  files  --- " + context.getExternalFilesDir(null).listFiles());

        for(int i = 0; i < context.getExternalFilesDir(null).listFiles().length; i++){

            System.out.println("** each file -- " + context.getExternalFilesDir(null).listFiles()[i]);
        }

        DownloadManager manager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
        manager.enqueue(request);

    }

This I what I have added in the manifest file :

 <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

This is the path am pointing to load the video :

String path = "/storage/emulated/0/Android/data/com.shliama.augmentedvideotutorial/files/NewVisionARVideos/test.mp4";

Below is the error am getting when I try to play the video in the media player. The path is correct and I have enabled the permissions in the manifest and the phone as well.

Below is the error am getting :

D/ArVideoFragment: playbackVideo = /storage/emulated/0/Android/data/com.shliama.augmentedvideotutorial/files/NewVisionARVideos/test.mp4
E/ArVideoFragment: Could not play video [/storage/emulated/0/Android/data/com.shliama.augmentedvideotutorial/files/NewVisionARVideos/test.mp4]
    java.io.FileNotFoundException: /storage/emulated/0/Android/data/com.shliama.augmentedvideotutorial/files/NewVisionARVideos/test.mp4

Is there another way of playing a video in the android MediaPlayer ?

EDIT:

Actually, found out that I was pointing to the assets folder since I was following this blog post.

This is method which points to the assets folder https://gist.github.com/huxaiphaer/268b94a0e7959822fa679a7523701187



Solution 1:[1]

I Think, you are not getting your external Storage directory properly.

Use This

 Uri uri = Uri.parse(Environment.getExternalStorageDirectory().getPath() + "Android/data/com.shliama.augmentedvideotutorial/files/NewVisionARVideos/test.mp4");

check your path properly dose it right and check you video also.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1