how to list all video file on my android phone?

钢 屈 371 Reputation points
2021-06-16T01:52:55.537+00:00

how to list all video file on my android phone?
My codes below, but vs2019 tell me error.
var videoFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyVideos);
DirectoryInfo dir = new DirectoryInfo(videoFolder);
var list = GetAll(dir);

private List<string> GetAll(DirectoryInfo dir)
{
List<string> fileList = new List<string>();
FileInfo[] allFile = dir.GetFiles();
foreach (FileInfo fi in allFile)
{
fileList.Add(fi.FullName);
}
DirectoryInfo[] allDir = dir.GetDirectories();
foreach (DirectoryInfo d in allDir)
{
fileList.AddRange(GetAll(d));
}
return fileList;
}

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,335 questions
{count} votes

1 answer

Sort by: Most helpful
  1. JessieZhang-MSFT 7,706 Reputation points Microsoft Vendor
    2021-06-16T10:01:25.093+00:00

    Hello,

    Welcome to our Microsoft Q&A platform!

    If you want to get all video file in your device, you can use Xamarin.Essentials: File Picker to achieve this.

    The FilePicker class lets a user pick a single or multiple files from the device.

    If you desire your user to pick multiple files you can call the FilePicker.PickMultipleAsync() method. It also takes in PickOptions as a parameter to specify additional information. The results are the same as PickAsync, but instead of a single FileResult an IEnumerable<FileResult> is returned that can be iterated over.

    You can refer to the following code:

            var pickResult = await FilePicker.PickMultipleAsync(new PickOptions  
            {  
                FileTypes = FilePickerFileType.Videos,  
                PickerTitle = "Pick video(s)"  
            });  
    
            if (pickResult != null)  
            {  
                foreach (FileResult item in pickResult)  
                {  
                    System.Diagnostics.Debug.WriteLine(" path =" + item.FullPath);  // here we can get the full path  
                }  
            }  
    

    For more details, you can check: https://learn.microsoft.com/en-us/xamarin/essentials/file-picker?context=xamarin%2Fandroid&tabs=android

    Best Regards,

    Jessie Zhang

    ---
    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our [documentation][3] to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.