Custom Params? ie: bgcolor/wmode

Sep 6, 2009 at 11:41 PM

Hi Guys

I was wondering if there was any way to pass the embed function custom object/embed parameters?

It would be great to (for example) make the video wmode='transparent' easily from XSLT without needing to change the compiled code everytime.

Any thoughts?

Cheers
Josh

Nov 6, 2009 at 5:00 AM

hey, in case you are interested... i did update the code... to set the wmode... as i needed it on a site with dhtml nav.... here is the updated code to the xsltextension.cs

 

using System.Text.RegularExpressions;

namespace Designit.Umb.DataTypes.Video
{
    public class XsltExtension
    {
        public static string VideoEmbed(string url, int width, int height)
        {
            var youTubeUrl = new Regex(@"^http://(www\.)?youtube.com/watch\?v=(?<id>[0-9A-Za-z-_]{11})$*");
            var vimeoUrl = new Regex(@"^http://(?:www\.){0,1}vimeo\.com/(\d+)$*");
            var googleVideoUrl = new Regex(@"^http://?video.google.com/videoplay\?docid=(?<id>[0-9A-Za-z-_]{19})$*");

            if (youTubeUrl.IsMatch(url))
            {
                var urlNew = "http://www.youtube.com/v/" + youTubeUrl.Replace(url, @"${id}");
                return VideoEmbedParameters(urlNew, width, height);
            }

            if (vimeoUrl.IsMatch(url))
            {
                var urlNew = "http://vimeo.com/moogaloop.swf?clip_id=" + vimeoUrl.Replace(url, @"$1");
                return VideoEmbedParameters(urlNew, width, height);
            }

            if (googleVideoUrl.IsMatch(url))
            {
                var urlNew = "http://video.google.com/googleplayer.swf?docId=" + googleVideoUrl.Replace(url, @"$1");
                return VideoEmbedParameters(urlNew, width, height);
            }

            return "<b>ERROR:</b> video format not supported";
        }


        private static string VideoEmbedParameters(string url, int width, int height)
        {
            return "<object width=\"" + width + "\" height=\"" + height + "\"><param name=\"movie\" value=\"" + url +
                   "\"></param><param name=\"allowFullScreen\" value=\"true\"></param><param name=\"wmode\" value=\"transparent\"></param><param name=\"allowscriptaccess\" value=\"always\"></param><embed src=\"" +
                   url + "\" type=\"application/x-shockwave-flash\" allowscriptaccess=\"always\" wmode=\"transparent\" allowfullscreen=\"true\" width=\"" +
                   width + "\" height=\"" + height + "\"></embed></object>";
        }

        private static string GetYouTubeVideoId(string url)
        {
            var testYouTubeUrl = new Regex(@"(\?v=)(\w[\w|-]*)");
            if (testYouTubeUrl.IsMatch(url))
            {
                foreach (Match tempMatch in testYouTubeUrl.Matches(url))
                    return (tempMatch.Value.Substring(3, tempMatch.Value.Length - 3));
            }
            return string.Empty;
        }
    }
}

Nov 6, 2009 at 5:21 AM

okay, i updated the source again, to allow for the passing of the wmode via a document property -- which could easily be passed as a macro param as well...

using System.Text.RegularExpressions;

namespace Designit.Umb.DataTypes.Video
{
    public class XsltExtension
    {
        public static string VideoEmbed(string url, int width, int height, string wmode)
        {
            var youTubeUrl = new Regex(@"^http://(www\.)?youtube.com/watch\?v=(?<id>[0-9A-Za-z-_]{11})$*");
            var vimeoUrl = new Regex(@"^http://(?:www\.){0,1}vimeo\.com/(\d+)$*");
            var googleVideoUrl = new Regex(@"^http://?video.google.com/videoplay\?docid=(?<id>[0-9A-Za-z-_]{19})$*");

            if (youTubeUrl.IsMatch(url))
            {
                var urlNew = "http://www.youtube.com/v/" + youTubeUrl.Replace(url, @"${id}");
                return VideoEmbedParameters(urlNew, width, height, wmode);
            }

            if (vimeoUrl.IsMatch(url))
            {
                var urlNew = "http://vimeo.com/moogaloop.swf?clip_id=" + vimeoUrl.Replace(url, @"$1");
                return VideoEmbedParameters(urlNew, width, height, wmode);
            }

            if (googleVideoUrl.IsMatch(url))
            {
                var urlNew = "http://video.google.com/googleplayer.swf?docId=" + googleVideoUrl.Replace(url, @"$1");
                return VideoEmbedParameters(urlNew, width, height, wmode);
            }

            return "<b>ERROR:</b> video format not supported";
        }


        private static string VideoEmbedParameters(string url, int width, int height, string wmode)
        {
            return "<object width=\"" + width + "\" height=\"" + height + "\"><param name=\"movie\" value=\"" + url +
                   "\"></param><param name=\"allowFullScreen\" value=\"true\"></param><param name=\" wmode\" value=\"" + wmode + "\"></param><param name=\"allowscriptaccess\" value=\"always\"></param><embed src=\"" +
                   url + "\" type=\"application/x-shockwave-flash\" allowscriptaccess=\"always\" wmode=\"" + wmode + "\" allowfullscreen=\"true\" width=\"" +
                   width + "\" height=\"" + height + "\"></embed></object>";
        }

        private static string GetYouTubeVideoId(string url)
        {
            var testYouTubeUrl = new Regex(@"(\?v=)(\w[\w|-]*)");
            if (testYouTubeUrl.IsMatch(url))
            {
                foreach (Match tempMatch in testYouTubeUrl.Matches(url))
                    return (tempMatch.Value.Substring(3, tempMatch.Value.Length - 3));
            }
            return string.Empty;
        }
    }
}

and here is my xslt....

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [
  <!ENTITY nbsp "&#x00A0;">
]>
<xsl:stylesheet
	version="1.0"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:msxml="urn:schemas-microsoft-com:xslt"
	xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets" xmlns:Designit.VideoEmbed="urn:Designit.VideoEmbed"
	exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets Designit.VideoEmbed ">


  <xsl:output method="xml" omit-xml-declaration="yes"/>

  <xsl:param name="currentPage"/>
  <xsl:variable name="videoUrl" select="$currentPage/data[@alias='videoLink']" />
  <xsl:variable name="wmode" select="$currentPage/data[@alias='wmode']" />
  <xsl:variable name="videoHeight" select="number(340)" />
  <xsl:variable name="videoWidth" select="number(560)" />
  <xsl:template match="/">
    <xsl:if test="$videoUrl != ''">
        <xsl:value-of select="Designit.VideoEmbed:VideoEmbed($videoUrl, $videoWidth, $videoHeight, $wmode)" disable-output-escaping="yes"/>
    </xsl:if>
  </xsl:template>

</xsl:stylesheet>

 

Mar 21, 2010 at 1:30 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.