I am trying to display all music files (Mp3) that is in the Music folder in Windows IoT Core on startup of the app in my ListView.
What I have at the moment is:
public MainPage()
{
this.InitializeComponent();
InitGPIO();
ListfilesAsync();
Unloaded += MainPage_Unloaded;
}
private async Task ListfilesAsync()
{
var folderPicker = new Windows.Storage.Pickers.FolderPicker();
folderPicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.MusicLibrary;
folderPicker.FileTypeFilter.Add("*.mp3");
StorageFolder folder = await folderPicker.PickSingleFolderAsync();
List<string> fileTypeFilter = new List<string>();
fileTypeFilter.Add(".mp3");
if (folder != null)
{
QueryOptions queryOptions = new QueryOptions(CommonFileQuery.OrderByDate, fileTypeFilter);
StorageFileQueryResult results = folder.CreateFileQueryWithOptions(queryOptions);
IReadOnlyList<StorageFile> sortedFiles = await results.GetFilesAsync();
foreach (StorageFile item in sortedFiles)
{
AudioFilesLV.Items.Add(item.Path.ToString());
}
}
}
The app starts with no errors but there is nothing displayed in the ListView?
Not sure if it is being initialized correctly or there is fault with my code?
Thanks
FolderPicker and FolderOpenPicker can not work on Windows IoT Core. You can use KnownFolders.MusicLibrary to list the file in music library.
Please note that, you need to specify the Music Library capability in Package.appxmanifest.