4

How can I get a list of all videos and their path that can be found on an Android device where is my app installed?

EDIT: I am trying to make a simple video player, so the idea would be to display all the videos that can be found on the device and to play it on list item click. Only problem is that i don't know how to get that info about videos, so I would be very thankful if someone can help me.

sth4
  • 63
  • 1
  • 1
  • 4
  • I haven't tried anything, don't really know where to start.. – sth4 May 08 '12 at 20:38
  • I can't really find anything on the internet that would help me,so I haven't tried yet anything. Now I done the rest of the app,but only missing the pick video to play part. – sth4 May 08 '12 at 20:45
  • I found this in the **Related** column, over there --> http://stackoverflow.com/q/2911124/1267661 There are more useful links too, as well as Preet Sangha's. Good Luck! – Sam May 08 '12 at 20:48
  • thanks! I will check it later and ask if I stuck somewhere. – sth4 May 08 '12 at 21:06
  • 1
    possible duplicate of [How to list all media in Android?](http://stackoverflow.com/questions/4531226/how-to-list-all-media-in-android) – Greg Hewgill May 08 '12 at 21:25
  • 1
    This was very helpful -> stackoverflow.com/q/2911124/1267661 Thanks for the help,and sorry for duplicate posting. – sth4 May 10 '12 at 18:33

3 Answers3

5

If someone is still looking for answer please Try this method. This method will return list of path of all media.

public ArrayList<String> getAllMedia() {
    HashSet<String> videoItemHashSet = new HashSet<>();
    String[] projection = { MediaStore.Video.VideoColumns.DATA ,MediaStore.Video.Media.DISPLAY_NAME};
    Cursor cursor = getContext().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);
    return downloadedList;
}
Vikash Kumar Verma
  • 1,068
  • 2
  • 14
  • 30
  • not working for me if folder programmatically created stackoverflow.com/questions/48934159/… please check this – Sagar Feb 23 '18 at 05:59
2
String[] projection = { MediaStore.Video.Media._ID};
Cursor cursor = new CursorLoader(contexts, MediaStore.Video.Media.EXTERNAL_CONTENT_URI, projection, 
            null, // Return all rows
            null, null).loadInBackground();

after you have the cursor you can iterate it and get all videos using the video id.

shem
  • 4,686
  • 2
  • 32
  • 43
  • not working for me if folder programmatically created https://stackoverflow.com/questions/48934159/mediastore-not-working-when-folder-programmatically-created please check this – Sagar Feb 23 '18 at 05:58
1

Try following code.

private void getVideoList() {
    Uri uri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
    String[] projection = {MediaStore.Video.VideoColumns.DATA};
    Cursor cursor = getContentResolver().query(uri, projection, null, null, null);
    ArrayList<String> pathArrList = new ArrayList<>();
    if (cursor != null) {
        while (cursor.moveToNext()) {
            pathArrList.add(cursor.getString(0));
        }
        cursor.close();
    }
    Log.e("all path",pathArrList.toString());
}
SANJAY GUPTA
  • 1,564
  • 13
  • 21