I want to list all the video files in sdcard and internal storage. The problem is that it is only accessing videos that are present in the root folder and not in the internal folders.Currently I only have one video in Path: /storage/emulated/0
and all the videos that are present inside these sub folders are not available.
String path = Environment.getExternalStorageDirectory().toString();
Log.e("TAG", "Path: " + path); => Path: /storage/emulated/0
File directory = new File(path);
File[] files = directory.listFiles();
assert files != null;
Log.e("TAG", "Size: "+ files.length);
for (int i = 0; i < files.length; i++)
{
if (files[i].getName().contains(".mp4")){
Log.e("TAG", "FileName:" + files[i].getName());
}
}
MediaScannerConnection.scanFile(this, new String[]{String.valueOf(getAllMedia())},
new String[]{"video/*"},
new MediaScannerConnection.OnScanCompletedListener() {
public void onScanCompleted(String path, Uri uri) {
//Do something
HashSet<String> videoItemHashSet = new HashSet<>();
String[] projection = {MediaStore.Video.VideoColumns.DATA,
MediaStore.Video.Media.DISPLAY_NAME};
Cursor cursor = getApplicationContext().getContentResolver().query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
projection, null, null, null);
try {
cursor.moveToFirst();
do {
videoItemHashSet.add((cursor.getString
(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA))));
} while (cursor.moveToNext());
cursor.close();
} catch (Exception e) {
e.printStackTrace();
}
ArrayList<String> downloadedList = new ArrayList<>(videoItemHashSet);
}
});