public MediaState EnqueueTracks(IEnumerable<Track> trackQueue, Track playTrack)
        {
            // NOTE: In media center we will ignore playtrack since we can't do anything with it.
            // The media center api sucks so hard.
            try
            {
                if (MyAddIn.MediaCenterHost.MediaCenterEnvironment == null)
                {
                    return null;
                }

                foreach (Track track in trackQueue)
                {
                    MyAddIn.MediaCenterHost.MediaCenterEnvironment.PlayMedia(Microsoft.MediaCenter.MediaType.Audio,
                            track.FilePath, true);
                }

                return GetMediaState();
            }
            catch (Exception ex)
            {
                LogUtility.LogException(ex);
                throw;
            }
        }
 public static Track GetTrack(this IITFileOrCDTrack track)
 {
     Track innerTrack = new Track();
     innerTrack.Title = track.Name;
     int trackNumber = track.TrackNumber;
     innerTrack.FilePath = track.Location;
     innerTrack.AlbumName = track.Album;
     innerTrack.ArtistName = track.Artist;
     innerTrack.Duration = TimeSpan.FromSeconds(track.Duration);
     return innerTrack;
 }
        public byte[] GetAlbumArtByTrack(Track track)
        {
            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 static Track GetTrack(this IWMPMedia wmpTrack)
        {
            Track track = new Track();
            track.Title = wmpTrack.getItemInfo(MediaAttributes.Title);
            int trackNumber = 0;
            if (int.TryParse(wmpTrack.getItemInfo(MediaAttributes.WMTrackNumber), out trackNumber))
            {
                track.TrackNumber = trackNumber;
            }

            track.FilePath = wmpTrack.sourceURL;
            track.AlbumName = wmpTrack.getItemInfo(MediaAttributes.WMAlbumTitle);
            track.ArtistName = wmpTrack.getItemInfo(MediaAttributes.Artist);
            double secondsDuration = 0.0d;
            if (double.TryParse(wmpTrack.getItemInfo(MediaAttributes.Duration), out secondsDuration))
            {
                track.Duration = TimeSpan.FromSeconds(secondsDuration);
            }

            return track;
        }
        public MediaState EnqueueTracks(IEnumerable<Track> trackQueue, Track playTrack)
        {
            iTunesApp iTunes = null;

            try
            {
                iTunes = new iTunesApp();

                //TODO implement

                return GetMediaState();
            }
            catch (Exception ex)
            {
                LogUtility.LogException(ex);
                throw;
            }
            finally
            {
                // Marshall.ReleaseComObject?
            }
        }
 public MediaState PlayTrack(Track track)
 {
     Console.WriteLine("Play Track");
     return GetMediaState();
 }
        public byte[] GetAlbumArtByTrack(Track track)
        {
            byte[] imageData = null;
            iTunesApp iTunes = null;

            try
            {
                iTunes = new iTunesApp();

                if (track != null && File.Exists(track.FilePath))
                {
                    using (FileStream fileStream = new FileStream(track.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[] GetAlbumArtByTrack(Track track)
        {
            WindowsMediaPlayer mediaPlayer = null;
            byte[] imageData = null;

            try
            {
                mediaPlayer = new WindowsMediaPlayer();
                IWMPPlaylist foundTracks = mediaPlayer.mediaCollection.getByName(track.Title);
                string collectionId = string.Empty;
                string albumId = string.Empty;

                //LogUtility.LogMessage("Found " + foundTracks.count + " tracks matching title " + track.Title);
                for (int i = 0; i < foundTracks.count; i++)
                {
                    IWMPMedia foundTrack = foundTracks.get_Item(i);
                    if (track.FilePath == foundTrack.sourceURL)
                    {
                        //LogUtility.LogMessage("Found a track with sourceURL matching filepath");
                        collectionId = foundTrack.getItemInfo(MediaAttributes.WMWMCollectionID);
                        albumId = foundTrack.getItemInfo(MediaAttributes.AlbumID);

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

                return imageData;

            }
            catch (Exception ex)
            {
                LogUtility.LogException(ex);
                throw;
            }
            finally
            {
                if (mediaPlayer != null)
                {
                    mediaPlayer.close();
                }
            }
        }
        private Track GetNowPlaying()
        {
            MediaExperience experience = MyAddIn.MediaCenterHost.GetMediaExperience();

            //if (experience == null ||
            //     experience.Transport == null ||
            //    (int)experience.MediaType != (int)Microsoft.MediaCenter.MediaType.Audio)

            if (experience == null ||
                experience.Transport == null)
            {
                return null;
            }

            MediaMetadata nowPlayingData = experience.MediaMetadata;
            Track nowPlaying = new Track()
            {
                ArtistName = nowPlayingData.ContainsKey("TrackArtist") ? nowPlayingData["TrackArtist"].ToString() : string.Empty,
                FilePath = nowPlayingData.ContainsKey("Uri") ? nowPlayingData["Uri"].ToString() : string.Empty,
                Title = nowPlayingData.ContainsKey("TrackTitle") ? nowPlayingData["TrackTitle"].ToString() : string.Empty,
                AlbumName = nowPlayingData.ContainsKey("AlbumTitle") ? nowPlayingData["AlbumTitle"].ToString() : string.Empty,
            };

            int trackDuration = 0;
            if (nowPlayingData.ContainsKey("TrackDuration"))
            {
                int.TryParse(nowPlayingData["TrackDuration"].ToString(), out trackDuration);
            }
            nowPlaying.Duration = new TimeSpan(0, 0, trackDuration);

            int trackNumber = 0;
            if (nowPlayingData.ContainsKey("TrackNumber"))
            {
                int.TryParse(nowPlayingData["TrackNumber"].ToString(), out trackNumber);
            }
            nowPlaying.TrackNumber = trackNumber;

            return nowPlaying;
        }