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.

有帮助吗?

解决方案

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.

其他提示

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));
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top