Source: StackOverflow, StackOverflow
Question: How to get the path of all videos stored on device.
Answer:
private String[] getAllVideoPath(Context context) {
Uri uri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
String[] projection = { MediaStore.Video.VideoColumns.DATA };
Cursor cursor = context.getContentResolver().query(uri, projection, null, null, null);
ArrayList<String> pathArrList = new ArrayList<String>();
//int vidsCount = 0;
if (cursor != null) {
//vidsCount = cursor.getCount();
//Log.d(TAG, "Total count of videos: " + vidsCount);
while (cursor.moveToNext()) {
pathArrList.add(cursor.getString(0));
//Log.d(TAG, cursor.getString(0));
}
cursor.close();
}
return pathArrList.toArray(new String[pathArrList.size()]);
}
Sorted newest Video first:
...
Uri uri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
String[] projection = { MediaStore.Video.VideoColumns.DATA };
String orderBy = android.provider.MediaStore.Video.Media.DATE_TAKEN;
Cursor cursor = context.getContentResolver().query(uri, projection, null, null, orderBy + " DESC");
...