2
votes

I'm working with music in music library in Windows Phone 8.1 runtime. But have a problem. It's too slow. In Windows Phone 8.0 or 8.0 Silverlight, when I used Microsoft.Xna.Framework.Media, it was very fast. In WP 8.1 runtime, I can't use XNA and I have to use KnownFolders.MusicLibrary. For example:

App.listMusicFiles = await KnownFolders.MusicLibrary.GetFilesAsync(CommonFileQuery.OrderByName);

for (int i = 0; i < App.listMusicFiles.Count; i++)
{
    MusicProperties musicProperties = await App.listMusicFiles[i].Properties.GetMusicPropertiesAsync();
App.listSongs.Add(new DeviceSongModel(i, musicProperties.Title, musicProperties.Artist, App.listMusicFiles[i].Path,     App.listMusicFiles[i].ContentType, musicProperties.Album, musicProperties.Duration.Ticks, ""));

}

It very, very slow. But why?

1

1 Answers

1
votes

The issue that you are seeing is probably because of this line here:

await KnownFolders.MusicLibrary.GetFilesAsync(CommonFileQuery.OrderByName);

Under the covers it is walking through every music file on the entire device, creating an in-memory representation of each file, and marshalling the representation back to your app's process.

The better way to do this is to only grab a fixed size batch of files at a time using await KnownFolders.MusicLibrary.GetFilesAsync(CommonFileQuery.OrderByName,index,batchSize);. This will cap the numbers of files that are returned. You can then process the returned files while in the background requesting the next batch.