(Answer the adjustment to be more clear)
If you specified in the package.appxmanifest file:
Music Library features in featuresFile Type Association in ads (I'm not sure if this is necessary if you only get access to the Music Library)
then you can receive files from the Music Library folder as follows:
StorageFolder folder = KnownFolders.MusicLibrary;
To summarize, you can use KnownFolders.MusicLibrary only files that are located either on the phone or on the SD card, but in the Music folder - their paths will be as follows:
C: \ Data \ Users \ Public \ Music \ test.mp3 - for phone
D: \ Music \ Test \ test2.mp3 - for an SD card
Remember that access to StorageFolder.GetFileAsync () works relative in StorageFolder (it will also work with the full path, see note below):
The name (or path to the current folder) of the file to extract.
In this case, to get the files above, you will use file names such as: test.mp3 and Test\test2.mp3 .
You will not be able to receive other files, such as D:\xxx.mp3 - this is not in the music library - it is on the SD card, if you want to access it, you will need to do this KnownFolders.RemovableDevices - when you added the required features then you can access this via fullpath. But also remember the remark:
Do not use this property to access the file, because some files may not have paths to the file system. For example, if a file is supported by a URI or was selected using the file collector, the file cannot guarantee the path to the file system.
In our discussion, it turns out that you are using CommonFileQuery.OrderByName to get the files. Since I checked there (IMO), there may be a slight error - the VS description says that:
The query results for deep queries include all files in all subfolders of the requested folder and sort them based on the specified metadata.
Running code code:
gave resuls:
- in the first case, 5 files that are actually located in the "Music" folder and subfolders,
- in the second case - 14 files located in: Music library, SD-card and phone
You can easily view Path in debug mode, and you will see that some of the files in the second method have D:\file.mp3 , etc. - they are not in the music library, so you cannot get them from KnownFolders.MusicLibrary . If you want to get them, you will have to use other KnownFolders - in this case the SD card:
StorageFolder externalDevices = Windows.Storage.KnownFolders.RemovableDevices; StorageFolder sdCard = (await externalDevices.GetFoldersAsync()).FirstOrDefault(); StorageFile file = await sdCard.GetFileAsync("xyz.mp3");