Beispiel #1
0
        public Bitmap GetVideoSnapshot(VideoProvider provider, string embedHtml, Size videoSize)
        {
            try
            {
                string videoHtml = GenerateEmbedHtml(embedHtml, videoSize);
                if (provider != null && provider.UseBackgroundColor != String.Empty)
                {
                    videoHtml = String.Format(CultureInfo.InvariantCulture, "<div style=\"background-color:{0};\">{1}</div>", provider.UseBackgroundColor, videoHtml);
                }
                HtmlScreenCapture htmlScreenCapture = new HtmlScreenCapture(videoHtml, videoSize.Width);

                if (provider != null && provider.RectangleTest != null)
                {
                    rectTest = provider.RectangleTest;
                    htmlScreenCapture.HtmlScreenCaptureAvailable += new HtmlScreenCaptureAvailableHandler(htmlScreenCapture_HtmlScreenCaptureAvailable_RectangleTest);
                }
                else if (provider != null && provider.SnapshotLoadedOrigColor != Color.Empty)
                {
                    testColor = provider.SnapshotLoadedOrigColor;
                    testPct   = provider.SnapshotLoadedColorPct;
                    htmlScreenCapture.HtmlScreenCaptureAvailable += new HtmlScreenCaptureAvailableHandler(htmlScreenCapture_HtmlScreenCaptureAvailable_ColorTest);
                }
                else
                {
                    testBitmap = null;
                    htmlScreenCapture.HtmlScreenCaptureAvailable += new HtmlScreenCaptureAvailableHandler(htmlScreenCapture_HtmlScreenCaptureAvailable_ChangeTest);
                }

                htmlScreenCapture.MaximumHeight = videoSize.Height;
                //we set our own limit to ensure a snapshot is always getting returned
                SetTimeout(DEFAULT_TIMEOUT_MS);
                Bitmap videoSnapshot = htmlScreenCapture.CaptureHtml(2 * DEFAULT_TIMEOUT_MS);

                // return the video
                return(videoSnapshot);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.ToString());
                throw new VideoPluginException(Res.Get(StringId.Plugin_Video_Snapshot_Error_Title), String.Format(Res.Get(StringId.Plugin_Video_Snapshot_Error_Message), ex.Message));
            }
        }
        public Bitmap GetVideoSnapshot(VideoProvider provider, string embedHtml, Size videoSize)
        {
            try
            {
                string videoHtml = GenerateEmbedHtml(embedHtml, videoSize);
                if (provider != null && provider.UseBackgroundColor != String.Empty)
                {
                    videoHtml = String.Format(CultureInfo.InvariantCulture, "<div style=\"background-color:{0};\">{1}</div>", provider.UseBackgroundColor, videoHtml);
                }
                HtmlScreenCapture htmlScreenCapture = new HtmlScreenCapture(videoHtml, videoSize.Width);

                if (provider != null && provider.RectangleTest != null)
                {
                    rectTest = provider.RectangleTest;
                    htmlScreenCapture.HtmlScreenCaptureAvailable += new HtmlScreenCaptureAvailableHandler(htmlScreenCapture_HtmlScreenCaptureAvailable_RectangleTest);
                }
                else if (provider != null && provider.SnapshotLoadedOrigColor != Color.Empty)
                {
                    testColor = provider.SnapshotLoadedOrigColor;
                    testPct = provider.SnapshotLoadedColorPct;
                    htmlScreenCapture.HtmlScreenCaptureAvailable +=new HtmlScreenCaptureAvailableHandler(htmlScreenCapture_HtmlScreenCaptureAvailable_ColorTest);
                }
                else
                {
                    testBitmap = null;
                    htmlScreenCapture.HtmlScreenCaptureAvailable +=new HtmlScreenCaptureAvailableHandler(htmlScreenCapture_HtmlScreenCaptureAvailable_ChangeTest);
                }

                htmlScreenCapture.MaximumHeight = videoSize.Height;
                //we set our own limit to ensure a snapshot is always getting returned
                SetTimeout(DEFAULT_TIMEOUT_MS);
                Bitmap videoSnapshot = htmlScreenCapture.CaptureHtml(2 * DEFAULT_TIMEOUT_MS);

                // return the video
                return videoSnapshot ;
            }
            catch(Exception ex)
            {
                Trace.WriteLine(ex.ToString());
                throw new VideoPluginException(Res.Get(StringId.Plugin_Video_Snapshot_Error_Title), String.Format(Res.Get(StringId.Plugin_Video_Snapshot_Error_Message), ex.Message)) ;
            }
        }