Question

In my application I have the following code, which get's the phone's MediaLibrary and filters out the correct chosen Song from the MediaLibrary.Songs and plays it:

using (MediaLibrary library = new MediaLibrary())
{
    foreach (var item in library.Songs)
    {
        if (item.Name == songName)
        {
            FrameworkDispatcher.Update();
            MediaPlayer.Play(item);
        }
    }
    library.Dispose();
}  

However this takes quite a while and results in a pause. Is there a faster/more-efficient way to access a specific Song from the phone's MediaLibrary.Songs?

Thanks for your help.

Was it helpful?

Solution

Maybe you have to store the values in a XML document after you read the directory, this can save you a lot of time if the library doesn't get changed (Check the size of the whole library). If it does then you can check the library again and update your XML.

OTHER TIPS

Well this is not an efficient way at all. To find any song in MediaLibrary use LINQ. Example

MediaPlayer.Play(library.Songs.First(x=>x.Name == songName));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top