Exemplo n.º 1
0
        public byte[] ThumbnailForWMPItemAsByte(string WMPMatchAttribute, string itemID, bool useFolderArtIfFound, Thumbnail_Sizes size, out string MimeType)
        {
            Bitmap bmp = ThumbnailForWMPItem(WMPMatchAttribute, itemID, useFolderArtIfFound, size, out MimeType);
            if (bmp == null) return null;
            try
            {
                byte[] bytes = (byte[])TypeDescriptor.GetConverter(bmp).ConvertTo(bmp, typeof(byte[]));
                return bytes;
            }
            catch (Exception ex)
            {
                Functions.WriteLineToLogFile("Exception converting WMP item thumbnail to bytes:");
                Functions.WriteExceptionToLogFile(ex);
            }

            return null;
        }
Exemplo n.º 2
0
        public Bitmap ThumbnailForWMPItem(string WMPMatchAttribute, string itemID, bool useFolderArtIfFound, Thumbnail_Sizes size, out string MimeType)
        {
            // Get URL
            MimeType = "";
            string             picFileName;
            WindowsMediaPlayer WMPlayer = new WindowsMediaPlayer();

            IWMPPlaylist pl = WMPlayer.mediaCollection.getByAttribute(WMPMatchAttribute, itemID);

            if (pl.count == 0)
            {
                Functions.WriteLineToLogFile("Warning - no items found in library with ID " + itemID);
                return(null);
            }

            //if (pl.count != 1) Functions.WriteLineToLogFile("Warning - more than one item found in library with ID " + itemID);

            IWMPMedia pic = pl.get_Item(0);

            picFileName = pic.sourceURL;

            WMPlayer.close();

            if (useFolderArtIfFound)
            {
                string itemFolder  = Path.GetDirectoryName(picFileName);
                string folderArtFN = Path.Combine(itemFolder, "folder.jpg");
                if (File.Exists(folderArtFN))
                {
                    picFileName = folderArtFN;
                }
            }


            ShellHelper shellHelper = new ShellHelper();

            MimeType = "image/jpeg";
            string strLog = ""; // ignore

            switch (size)
            {
            case Thumbnail_Sizes.Small:
                return(shellHelper.ThumbnailForFile(picFileName, ThumbnailSizes.Small, ref strLog));

            case Thumbnail_Sizes.Medium:
                return(shellHelper.ThumbnailForFile(picFileName, ThumbnailSizes.Medium, ref strLog));

            case Thumbnail_Sizes.Large:
                return(shellHelper.ThumbnailForFile(picFileName, ThumbnailSizes.Large, ref strLog));

            case Thumbnail_Sizes.ExtraLarge:
                return(shellHelper.ThumbnailForFile(picFileName, ThumbnailSizes.ExtraLarge, ref strLog));

            default:
                return(shellHelper.ThumbnailForFile(picFileName, ThumbnailSizes.Small, ref strLog));
            }
        }
Exemplo n.º 3
0
        public Bitmap ThumbnailForWMPItem(string WMPMatchAttribute, string itemID, bool useFolderArtIfFound, Thumbnail_Sizes size, out string MimeType)
        {
            // Get URL
            MimeType = "";
            string picFileName;
            WindowsMediaPlayer WMPlayer = new WindowsMediaPlayer();

            IWMPPlaylist pl = WMPlayer.mediaCollection.getByAttribute(WMPMatchAttribute, itemID);
            if (pl.count == 0)
            {
                Functions.WriteLineToLogFile("Warning - no items found in library with ID " + itemID);
                return null;
            }

            //if (pl.count != 1) Functions.WriteLineToLogFile("Warning - more than one item found in library with ID " + itemID);

            IWMPMedia pic = pl.get_Item(0);

            picFileName = pic.sourceURL;

            WMPlayer.close();

            if (useFolderArtIfFound)
            {
                string itemFolder = Path.GetDirectoryName(picFileName);
                string folderArtFN = Path.Combine(itemFolder,"folder.jpg");
                if (File.Exists(folderArtFN))
                    picFileName = folderArtFN;
            }

            ShellHelper shellHelper = new ShellHelper();
            MimeType = "image/jpeg";
            string strLog = ""; // ignore
            switch (size)
            {
                case Thumbnail_Sizes.Small:
                    return shellHelper.ThumbnailForFile(picFileName, ThumbnailSizes.Small, ref strLog);

                case Thumbnail_Sizes.Medium:
                    return shellHelper.ThumbnailForFile(picFileName, ThumbnailSizes.Medium, ref strLog);

                case Thumbnail_Sizes.Large:
                    return shellHelper.ThumbnailForFile(picFileName, ThumbnailSizes.Large, ref strLog);

                case Thumbnail_Sizes.ExtraLarge:
                    return shellHelper.ThumbnailForFile(picFileName, ThumbnailSizes.ExtraLarge, ref strLog);

                default:
                    return shellHelper.ThumbnailForFile(picFileName, ThumbnailSizes.Small, ref strLog);
            }
        }
Exemplo n.º 4
0
        public byte[] ThumbnailForWMPItemAsByte(string WMPMatchAttribute, string itemID, bool useFolderArtIfFound, Thumbnail_Sizes size, out string MimeType)
        {
            Bitmap bmp = ThumbnailForWMPItem(WMPMatchAttribute, itemID, useFolderArtIfFound, size, out MimeType);

            if (bmp == null)
            {
                return(null);
            }
            try
            {
                byte[] bytes = (byte[])TypeDescriptor.GetConverter(bmp).ConvertTo(bmp, typeof(byte[]));
                return(bytes);
            }
            catch (Exception ex)
            {
                Functions.WriteLineToLogFile("Exception converting WMP item thumbnail to bytes:");
                Functions.WriteExceptionToLogFile(ex);
            }

            return(null);
        }