private void PopulatePreviewBox()
        {
            _video = null;
            string input = videoCode.Text.Trim();

            try
            {
                _video = VideoProviderManager.FindVideo(input);
            }
            catch (VideoUrlConvertException)
            {
                DisplayHtml(Res.Get(StringId.VideoUrlConvertError), CreateErrorHtml);
                return;
            }

            if (_video != null)
            {
                lblSize.Text    = String.Format(CultureInfo.CurrentCulture, Res.Get(StringId.Plugin_Video_Web_Video_Size), _video.Width, _video.Height);
                lblService.Text = String.Format(CultureInfo.CurrentCulture, Res.Get(StringId.Plugin_Video_Web_Video_Provider),
                                                _video.Provider != null ? _video.Provider.ServiceName : Res.Get(StringId.Plugin_Video_Unknown_Provider));

                DisplayHtml(
                    VideoProvider.GenerateEmbedHtml(_video.EditorFormat, _video.Id,
                                                    new Size(_video.Width, _video.Height)), CreateEmbedHtml);
            }
            else
            {
                DisplayHtml(Res.Get(StringId.Plugin_Video_Cannot_Parse_Url_Message), CreateErrorHtml);
                lblSize.Text    = Res.Get(StringId.Plugin_Video_Web_Video_Size_Blank);
                lblService.Text = Res.Get(StringId.Plugin_Video_Web_Video_Service_Blank);
            }
        }
Esempio n. 2
0
        private static object ReadXmlVideoProviders(XmlDocument providersDocument)
        {
            XmlNode providersNode = providersDocument.SelectSingleNode("//videoProviders");

            if (providersNode == null)
            {
                throw new Exception("Invalid videoProviders.xml file detected");
            }

            // get the list of providers from the xml
            ArrayList providers          = new ArrayList();
            HashSet   marketSupportedIds = new HashSet();

            marketSupportedIds.AddAll(
                StringHelper.Split(
                    MarketizationOptions.GetFeatureParameter(MarketizationOptions.Feature.VideoProviders, "supported"), ";"));
            XmlNodeList providerNodes = providersDocument.SelectNodes("//videoProviders/provider");

            foreach (XmlNode providerNode in providerNodes)
            {
                VideoProvider provider = VideoProviderFromXml(providerNode);
                if (marketSupportedIds.Contains(provider.ServiceId))
                {
                    providers.Add(provider);
                }
            }

            // return list of providers
            return(providers.ToArray(typeof(VideoProvider)));
        }
Esempio n. 3
0
        private string GeneratePublishVideoHtml(VideoContext context)
        {
            //check for special cases--whitelist blog providers and such
            string output;

            if (VideoProviderManager.CheckForWhitelist(context.BlogProviderId, ProviderId, Id, HtmlSize, out output))
            {
                return(String.Format(CultureInfo.InvariantCulture, "<div>{0}</div>", output));
            }

            // generate 'smart' html based on the user's preference
            AdaptiveHtmlObject adaptiveHtmlObject = new AdaptiveHtmlObject(VideoProvider.GenerateEmbedHtml(EmbedFormat, Id, HtmlSize), Url);

            if (HtmlSize != VideoSnapshotSize)
            {
                adaptiveHtmlObject.PreviewImageSize = HtmlSize;
            }
            adaptiveHtmlObject.OpenPreviewInNewWindow = OpenInNewWindow;
            HtmlType htmlType;

            //determine player style
            VideoPlayerStyle playerStyle = context.DetermineAppropriatePlayer(Url != String.Empty);

            switch (playerStyle)
            {
            case VideoPlayerStyle.Automatic:
                htmlType = HtmlType.AdaptiveHtml;
                break;

            case VideoPlayerStyle.PreviewWithLink:
                htmlType = HtmlType.PreviewHtml;
                break;

            case VideoPlayerStyle.EmbeddedInPage:
                htmlType = HtmlType.ObjectHtml;
                break;

            default:
                Trace.Fail("Unexpected PlayerStyle: " + playerStyle.ToString());
                htmlType = HtmlType.PreviewHtml;
                break;
            }

            string path = GetSnapshotPathIfNeeded(htmlType, context);

            if (!string.IsNullOrEmpty(path))
            {
                adaptiveHtmlObject.PreviewImageSrc = path;
            }
            else
            {
                htmlType = HtmlType.ObjectHtml;
            }

            return(adaptiveHtmlObject.GenerateHtml(htmlType));
        }
Esempio n. 4
0
        public Video(string id, string url, string embed, string editorFormat, VideoProvider provider, int width, int height, VideoAspectRatioType aspectRatioType)
        {
            _id             = id;
            _url            = url;
            _embed          = embed;
            _provider       = provider;
            _width          = width;
            _height         = height;
            _editorFormat   = editorFormat;
            AspectRatioType = aspectRatioType;

            if (AspectRatioType != VideoAspectRatioType.Unknown)
            {
                _height = VideoAspectRatioHelper.ResizeHeightToAspectRatio(AspectRatioType, new Size(width, height)).Height;
            }
        }
Esempio n. 5
0
        public Video(string id, string url, string embed, string editorFormat, VideoProvider provider, int width, int height, VideoAspectRatioType aspectRatioType)
        {
            _id = id;
            _url = url;
            _embed = embed;
            _provider = provider;
            _width = width;
            _height = height;
            _editorFormat = editorFormat;
            AspectRatioType = aspectRatioType;

            if (AspectRatioType != VideoAspectRatioType.Unknown)
            {
                _height = VideoAspectRatioHelper.ResizeHeightToAspectRatio(AspectRatioType, new Size(width, height)).Height;
            }
        }
Esempio n. 6
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));
            }
        }
Esempio n. 7
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)) ;
            }
        }
        bool IHandlesMultipleUrls.HasUrlMatch(string url)
        {
            VideoProvider provider = VideoProviderManager.FindProviderFromUrl(url);

            return(provider != null);
        }