1

I am trying to implement video player feature in my Unity3D-Android app. Would like to know that how to access all video files present on device storage. So far I could get list of MP4 files on Application.persistentDataPath using this :

private List<string> DirSearch(string sDir)
{
    List<string> files = new List<string>();
    try
    {
        foreach (string f in Directory.GetFiles(sDir,"*.mp4"))
        {
            files.Add(f);
        }
        foreach (string d in Directory.GetDirectories(sDir))
        {
            files.AddRange(DirSearch(d));
        }
    }
    catch (Exception ex)
    {
        Debug.LogError(ex.Message);
    }

    return files;
}

To use the same piece of code for entire device storage and SD card, Where should I start my search from?

EDIT :

Please note that I am working in Unity3D with C# and above code works fine. So a java code would not be helpful. Instead I need absolute path on android device storage for which I can call above method like this: DirSearch(needThisPathAddressForAndroidRootFolder)

Thanks

Umair M
  • 10,298
  • 6
  • 42
  • 74
  • Possible duplicate of [How to list all video files on device](https://stackoverflow.com/questions/39399361/how-to-list-all-video-files-on-device) – Mick Mar 05 '18 at 23:22
  • @Mick This question is for unity3D c# whereas your linked question is for native android. – Umair M Mar 06 '18 at 08:34
  • Hi, did you find an answer to this? I have the same problem now. – piotrb92 Oct 22 '19 at 21:01
  • This is a rather old question, I don't have the exact solution but you need a plugin to get the path. Have a look at [this question](https://answers.unity.com/questions/946029/get-sdcard-root-path.html) – Umair M Oct 23 '19 at 11:59

1 Answers1

-1

Query the MediaStore content provider

http://developer.android.com/reference/android/provider/MediaStore.html

An example could be

public static void printNamesToLogCat(Context context) {
    Uri uri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
    String[] projection = { MediaStore.Video.VideoColumns.DATA };
    Cursor c = context.getContentResolver().query(uri, projection, null, null, null);
    int vidsCount = 0;
    if (c != null) {
        vidsCount = c.getCount();
        while (c.moveToNext()) {
            Log.d("VIDEO", c.getString(0));
        }
        c.close();
    }
}

Thank you slartibartfast

Referenced By

Community
  • 1
  • 1
Kalu Singh Rao
  • 1,671
  • 1
  • 16
  • 21