Search code examples
windows-phone-7media-playerplaylist

playlist management windows phone 7


If, for example, I only want to play a song at index 3, 5, and 9 in media library, how can I do that? My code is as follow:

private SongCollection mySongCollection;

Can I perform something like this:

mySongCollection = library.Albums[index].Songs + library.Songs[index];

Solution

  • Because SongCollection is an immutable class, you cannot directly instantiate it, add items to it and pass it to MediaPlayer. Instead, you could create an instance of IEnumerable<Song> and then iterate through it when passing the data to MediaPlayer.Play. For example, if you have two SongCollection instances, you could easily do this:

    IEnumerable<Song> ultimateCollection = collection.Concat(collection2);
    

    Where collection and collection2 are of type SongCollection.