public static Album GetAlbum(this IITFileOrCDTrack track)
        {
            Album album = new Album();
            album.Title = track.Album;
            if (!string.IsNullOrEmpty(track.AlbumArtist))
            {
                album.ArtistName = track.AlbumArtist;
            }
            else
            {
                album.ArtistName = track.Artist;
            }
            album.Genre = track.Genre;
            // Should be somewhat unique, iTunes doesn't have an album id concept
            album.ID = album.ArtistName + album.Title;

            string releaseYear = track.Year.ToString();
            if (!string.IsNullOrEmpty(releaseYear))
            {
                DateTime releaseDate;
                if (DateTime.TryParseExact(releaseYear, new string[] { "yyyy" },
                    CultureInfo.CurrentCulture.NumberFormat,
                    DateTimeStyles.None, out releaseDate))
                {
                    album.ReleaseYear = releaseDate;
                }
            }

            return album;
        }
        public byte[] GetAlbumArtByAlbum(Album album)
        {
            byte[] imageData = null;
            Track foundTrack = null;
            iTunesApp iTunes = null;

            try
            {
                iTunes = new iTunesApp();

                foreach (IITFileOrCDTrack track in iTunes.LibraryPlaylist.Search(album.Title,
                    ITPlaylistSearchField.ITPlaylistSearchFieldAlbums))
                {
                    if (!string.Equals(track.Artist, album.ArtistName))
                    {
                        continue;
                    }

                    foundTrack = track.GetTrack();
                    break;
                }

                if (foundTrack != null && File.Exists(foundTrack.FilePath))
                {
                    using (FileStream fileStream = new FileStream(foundTrack.FilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                    {
                        try
                        {
                            TagContainer tags = new Id3TagManager().ReadV2Tag(fileStream);
                            if (tags != null)
                            {
                                IFrame apicFrame = tags.SearchFrame("APIC");
                                if (apicFrame != null)
                                {
                                    PictureFrame pictureFrame = FrameUtilities.ConvertToPictureFrame(apicFrame);
                                    imageData = pictureFrame.PictureData.ToArray<byte>();
                                }
                            }
                        }
                        catch (Id3TagException) { /* Do nothing */}
                    }
                }

                return imageData;
            }
            catch (Exception ex)
            {
                LogUtility.LogException(ex);
                throw;
            }
            finally
            {
                // Marshall.ReleaseComObject?
            }
        }
        public byte[] GetAlbumArtByAlbum(Album album)
        {
            FileInfo albumArtInfo = new FileInfo(@"Images\merdenoms.jpg");
            if (albumArtInfo.Exists)
            {
                using (FileStream artStream = albumArtInfo.OpenRead())
                {
                    byte[] artInfo = new byte[artStream.Length];
                    artStream.Read(artInfo, 0, (int)artStream.Length);
                    return artInfo;
                }
            }

            return null;
        }
        public byte[] GetAlbumArtByAlbum(Album album)
        {
            WindowsMediaPlayer mediaPlayer = null;
            byte[] imageData = null;

            try
            {
                mediaPlayer = new WindowsMediaPlayer();
                IWMPPlaylist foundTracks = mediaPlayer.mediaCollection.getByAttribute(MediaAttributes.AlbumID, album.ID);
                string collectionId = string.Empty;
                string albumId = string.Empty;

                if (foundTracks.count == 0)
                {
                    return null;
                }

                IWMPMedia foundTrack = foundTracks.get_Item(0);
                collectionId = foundTrack.getItemInfo(MediaAttributes.WMWMCollectionID);
                albumId = foundTrack.getItemInfo(MediaAttributes.AlbumID);

                if (!ThumbnailCache.TryGetThumbnail(albumId, out imageData))
                {
                    imageData = GetTrackArt(mediaPlayer, foundTrack, collectionId);
                }

                return imageData;
            }
            catch (Exception ex)
            {
                LogUtility.LogException(ex);
                throw;
            }
            finally
            {
                if (mediaPlayer != null)
                {
                    mediaPlayer.close();
                }
            }
        }
        public static Album GetAlbum(this IWMPMedia wmpTrack)
        {
            Album album = new Album();
            album.Title = wmpTrack.getItemInfo(MediaAttributes.WMAlbumTitle);
            album.ArtistName = wmpTrack.getItemInfo(MediaAttributes.WMAlbumArtist);
            album.Genre = wmpTrack.getItemInfo(MediaAttributes.WMGenre);
            album.ID = wmpTrack.getItemInfo(MediaAttributes.AlbumID);

            string releaseYear = wmpTrack.getItemInfo(MediaAttributes.ReleaseDateYear);
            if (!string.IsNullOrEmpty(releaseYear))
            {
                DateTime releaseDate;
                if (DateTime.TryParseExact(releaseYear, new string[] { "yyyy" },
                    CultureInfo.CurrentCulture.NumberFormat,
                    DateTimeStyles.None, out releaseDate))
                {
                    album.ReleaseYear = releaseDate;
                }
            }

            return album;
        }
 public MediaState PlayAlbum(Album album, bool enqueue)
 {
     throw new NotImplementedException();
 }
        public IEnumerable<Track> GetTracks(Album album)
        {
            List<Track> returnedTracks = new List<Track>();
            iTunesApp iTunes = null;

            try
            {
                iTunes = new iTunesApp();

                foreach (IITFileOrCDTrack track in iTunes.LibraryPlaylist.Search(album.Title, ITPlaylistSearchField.ITPlaylistSearchFieldArtists))
                {
                    if (!string.Equals(track.AlbumArtist, album.ArtistName))
                    {
                        continue;
                    }

                    returnedTracks.Add(track.GetTrack());
                }
            }
            catch (Exception ex)
            {
                LogUtility.LogException(ex);
                throw;
            }
            finally
            {
                // Marshall.ReleaseComObject?
            }

            return returnedTracks;
        }
 public MediaState PlayAlbum(Album album, bool enqueue)
 {
     MediaLibraryService service = new MediaLibraryService();
     return PlayTracks(service.GetTracks(album), enqueue);
 }
        private static void CacheAlbums(WindowsMediaPlayer mediaPlayer)
        {
            // Get the album titles
                IWMPStringCollection albumTitles = mediaPlayer.mediaCollection
                    .getAttributeStringCollection(MediaAttributes.WMAlbumTitle, MediaType.Audio);

                for (int i = 0; i < albumTitles.count; i++)
                {
                    if (!_albumCache.ContainsKey(albumTitles.Item(i).ToLower()))
                    {
                        string albumTitle = albumTitles.Item(i);
                        if (albumTitle != null && !string.IsNullOrEmpty(albumTitle))
                        {
                            IWMPPlaylist albumPlaylist = mediaPlayer.mediaCollection.getByAlbum(albumTitle);

                            Album album = new Album();
                            album.Title = albumTitle;

                            if (albumPlaylist.count >= 1)
                            {
                                IWMPMedia albumMedia = albumPlaylist.get_Item(0);
                                album.ArtistName = albumMedia.getItemInfo(MediaAttributes.WMAlbumArtist);
                                album.Genre = albumMedia.getItemInfo(MediaAttributes.WMGenre);
                                album.ID = albumMedia.getItemInfo(MediaAttributes.AlbumID);

                                string releaseYear = albumMedia.getItemInfo(MediaAttributes.ReleaseDateYear);
                                if (!string.IsNullOrEmpty(releaseYear))
                                {
                                    DateTime releaseDate;
                                    if (DateTime.TryParseExact(releaseYear, new string[] { "yyyy" },
                                        CultureInfo.CurrentCulture.NumberFormat,
                                        DateTimeStyles.None, out releaseDate))
                                    {
                                        album.ReleaseYear = releaseDate;
                                    }
                                }
                            }

                            _albumCache.Add(album.Title.ToLower(), album);
                        }
                    }
                }
        }
        public IEnumerable<Track> GetTracks(Album album)
        {
            List<Track> returnedTracks = new List<Track>();
            WindowsMediaPlayer mediaPlayer = null;

            try
            {
                mediaPlayer = new WindowsMediaPlayer();

                IWMPPlaylist albumTracks = mediaPlayer.mediaCollection.getByAttribute(MediaAttributes.AlbumID, album.ID);

                for (int i = 0; i < albumTracks.count; i++)
                {
                    IWMPMedia trackMedia = albumTracks.get_Item(i);
                    returnedTracks.Add(trackMedia.GetTrack());
                }

                return returnedTracks;
            }
            catch (Exception ex)
            {
                LogUtility.LogException(ex);
                throw;
            }
            finally
            {
                if (mediaPlayer != null)
                {
                    mediaPlayer.close();
                }
            }
        }
 public IEnumerable<Track> GetTracks(Album album)
 {
     throw new NotImplementedException();
 }