コード例 #1
0
        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?
            }
        }
コード例 #2
0
        public static IZuneTagContainer GetContainer(string path)
        {
            if (!File.Exists(path))
                throw new FileNotFoundException(String.Format("File does not exist: {0}",path), path);

            string extension = Path.GetExtension(path);

            if (extension.ToLower() == ".mp3")
            {
                try
                {
                    var tagManager = new Id3TagManager();

                    //TODO: app crashes here when a file is loaded from a remote directory, i.e. on network
                    FileState status = tagManager.GetTagsStatus(path);

                    //if we just have id3v1.1 tags
                    if (status.Id3V1TagFound && !status.Id3V2TagFound)
                        throw new Id3TagException("cannot read id3v1.1");

                    return new ZuneMP3TagContainer(tagManager.ReadV2Tag(path),path);
                }
                catch (Id3TagException ex)
                {
                    if (ex.InnerException != null)
                        throw new AudioFileReadException(ex.InnerException.Message, ex.InnerException);

                    throw new AudioFileReadException(ex.Message);
                }
            }

            if (extension.ToLower() == ".wma")
            {
                try
                {
                    return new ZuneWMATagContainer(ASFTagManager.ReadTag(path),path);
                }
                catch (Exception ex)
                {
                    throw new AudioFileReadException(ex.Message,ex);
                }
            }

            throw new AudioFileReadException("The " + Path.GetExtension(path) +
                " file extension is not supported with zune social tagger.");
        }
コード例 #3
0
        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?
            }
        }
コード例 #4
0
        private byte[] GetTrackArt(WindowsMediaPlayer player, IWMPMedia track, string collectionId)
        {
            byte[] imageData = null;
            if (!string.IsNullOrEmpty(track.sourceURL) && File.Exists(track.sourceURL))
            {
                // Try and find the album art that WMP, WMC, Zune creates. I'd much rather read from
                // a local JPEG than try to read from media that's currently playing and probably locked
                FileInfo pathInfo = new FileInfo(track.sourceURL);
                //LogUtility.LogMessage(pathInfo.FullName + " exists");
                FileInfo albumArtInfo = new FileInfo(string.Format("{0}{1}AlbumArt_{2}_Large.jpg",
                    pathInfo.DirectoryName, Path.DirectorySeparatorChar, collectionId));

                if (!albumArtInfo.Exists)
                {
                    albumArtInfo = new FileInfo(string.Format("{0}{1}AlbumArt_{2}_Small.jpg",
                       pathInfo.DirectoryName, Path.DirectorySeparatorChar, collectionId));
                }

                if (!albumArtInfo.Exists)
                {
                    albumArtInfo = new FileInfo(string.Format("{0}{1}ZuneAlbumArt.jpg",
                       pathInfo.DirectoryName, Path.DirectorySeparatorChar));
                }

                //LogUtility.LogMessage("Album art path is " + albumArtInfo.FullName);
                if (albumArtInfo.Exists)
                {
                    //LogUtility.LogMessage("Album art exists");
                    using (FileStream artStream = albumArtInfo.OpenRead())
                    {
                        byte[] artInfo = new byte[artStream.Length];
                        artStream.Read(artInfo, 0, (int)artStream.Length);
                        imageData = artInfo;
                    }
                }
            }

            // Couldn't get the art from the folder.jpg, so now try to read the id3 tag
            if (File.Exists(track.sourceURL))
            {
                using (FileStream fileStream = new FileStream(track.sourceURL, 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;
        }