CloudinaryDotNet.Url.AppendVideoSources C# (CSharp) Метод

AppendVideoSources() приватный Метод

private AppendVideoSources ( StringBuilder sb, string source, string sourceType ) : void
sb StringBuilder
source string
sourceType string
Результат void
        private void AppendVideoSources(StringBuilder sb, string source, string sourceType)
        {
            var sourceUrl = Clone();

            if (m_sourceTransforms != null)
            {
                Transformation sourceTransformation = null;
                if (m_sourceTransforms.TryGetValue(sourceType, out sourceTransformation) && sourceTransformation != null)
                {
                    if (sourceUrl.m_transformation == null)
                    {
                        sourceUrl.Transform(sourceTransformation.Clone());
                    }
                    else
                    {
                        sourceUrl.m_transformation.Chain();
                        var newTransform = sourceTransformation.Clone();
                        newTransform.NestedTransforms.AddRange(sourceUrl.m_transformation.NestedTransforms);
                        sourceUrl.Transform(newTransform);
                    }
                }
            }

            var src = sourceUrl.Format(sourceType).BuildUrl(source);
            var videoType = sourceType;
            if (sourceType.Equals("ogv", StringComparison.OrdinalIgnoreCase))
                videoType = "ogg";
            string mimeType = "video/" + videoType;
            sb.Append("<source src='").Append(src).Append("' type='").Append(mimeType).Append("'>");
        }

Usage Example

Пример #1
0
        public static IHtmlContent BuildVideoTag(this Url url, string source, IDictionary <string, string> options = null)
        {
            if (options == null)
            {
                options = new Dictionary <string, string>();
            }
            source = VIDEO_EXTENSION_RE.Replace(source, "", 1);
            if (string.IsNullOrEmpty(url.m_resourceType))
            {
                url.m_resourceType = "video";
            }
            var strArray = url.m_sourceTypes ?? DEFAULT_VIDEO_SOURCE_TYPES;
            var str1     = FinalizePosterUrl(url, source);

            if (!string.IsNullOrEmpty(str1))
            {
                options.Add("poster", str1);
            }
            var sb   = new StringBuilder("<video");
            var flag = strArray.Length > 1;

            if (!flag)
            {
                var str2 = url.BuildUrl(source + "." + strArray[0]);
                options.Add("src", str2);
            }
            else
            {
                url.BuildUrl(source);
            }
            if (options.ContainsKey("html_height"))
            {
                options["height"] = options.SliceValue("html_height");
            }
            else if (url.Transformation.HtmlHeight != null)
            {
                options["height"] = url.Transformation.HtmlHeight;
            }
            if (options.ContainsKey("html_width"))
            {
                options["width"] = options.SliceValue("html_width");
            }
            else if (url.Transformation.HtmlWidth != null)
            {
                options["width"] = url.Transformation.HtmlWidth;
            }
            foreach (var keyValuePair in options.OrderBy(x => x.Key))
            {
                sb.Append(" ").Append(keyValuePair.Key);
                if (keyValuePair.Value != null)
                {
                    sb.Append("='").Append(keyValuePair.Value).Append("'");
                }
            }
            sb.Append(">");
            if (flag)
            {
                foreach (var sourceType in strArray)
                {
                    url.AppendVideoSources(sb, source, sourceType);
                }
            }
            if (!string.IsNullOrEmpty(url.m_fallbackContent))
            {
                sb.Append(url.m_fallbackContent);
            }
            sb.Append("</video>");
            return(new HtmlString(sb.ToString()));
        }