Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Steve 472 posts 1216 karma points
    Apr 17, 2013 @ 23:02
    Steve
    0

    Multiple Flowplayers on the same page

    I have a problem with a page with more than one Flowplayer on it here. It only displays the first video on the page.

    https://edit-wwwprep.rose-hulman.edu/admissions-financial-aid/get-to-know-rose-hulman.aspx

    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"
        exclude-result-prefixes="msxml umbraco.library">
    
    <xsl:output method="html" omit-xml-declaration="yes"/>
    
    <xsl:param name="currentPage"/>
    <xsl:variable name="videonode" select="/macro/videoNode"/>
    <xsl:variable name="videoid" select="generate-id($videonode)"/>
    <xsl:variable name="videopath" select="$videonode/File/umbracoFile"/>
    <xsl:variable name="videoheight" select="/macro/VideoHeight"/>
    <xsl:variable name="videowidth" select="/macro/VideoWidth"/>
    
    
    
    <!-- ============================================================= -->
    
    <xsl:template match="/">
    
    
    <script type="text/javascript" src="/scripts/flowplayer-3.1.4.min.js"></script> 
    <a class="videoid">
        <div class="video">
        <xsl:attribute name="href">
            <xsl:value-of select="$videopath" />  
        </xsl:attribute> 
        <xsl:attribute name="style">
            <xsl:text>display:block;height:</xsl:text><xsl:value-of select="$videoheight"/><xsl:text>px;width:</xsl:text><xsl:value-of select="$videowidth"/><xsl:text>px</xsl:text>
        </xsl:attribute>
        <xsl:attribute name="id">
            <xsl:value-of select="$videoid" />
        </xsl:attribute>
        </div>
    
    </a> 
    
    <script type="text/javascript">
    <![CDATA[
        var videoid = "]]><xsl:value-of select="$videoid" /><![CDATA[";
        flowplayer(videoid, "/scripts/flowplayer-3.1.4.swf", {
    plugins: {
        controls: {
    url: "/scripts/flowplayer.controls-3.1.4.swf",
    progressColor: '#a3000f',
    backgroundGradient: 'high',
    backgroundColor: 'transparent',
    buttonColor: '#a3000f',
    buttonOverColor: '#ac525b',
    bufferColor: '#bbbbbb',
    timeColor: '#ffffff',
    durationColor: '#000000',
    volumeSliderColor: '#bbbbbb',
    
    autoHide: {
            enabled: 'true',
            hideDelay: 0
               }
    }
         }
    
    }
    );
    ]]>
    </script>
    
    </xsl:template>
    </xsl:stylesheet>

     

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Apr 17, 2013 @ 23:30
    Chriztian Steinmeier
    0

    Hi Steve,

    That's because (I bet) they end up with the same ID - and IDs must be unique on a page.

    The generate-id() function you're using guarantees that in a single XML document, you won't get any duplicates, but they way it's used here, it actually ends up being called for what is essentially the same node over and over again.

    To fix it, use the node's @id attribute instead, like this (IDs are also required to start with a non-digit character):

    <xsl:variable name="videoid" select="concat('ID', $videonode/File/@id)"/>

    Let me know if it doesn't work,

    /Chriztian

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Apr 17, 2013 @ 23:40
    Chriztian Steinmeier
    0

    Another thing:

    <xsl:attribute> (and its cousin <xsl:element>) are really meant for when you need to conditionally add an attribute/element, or when you need to take its name from a variable or similar.

    The a + div can be much easier created (and subsequently read the day after) if you use curly braces (or "Attribute Value Templates" as they're officially called) for the attributes:

    <a class="videoid">
        <div id="{$videoid}"
            class="video"
            href="{$videopath}"
            style="display:block;height:{$videoheight}px;width:{$videowidth}px">
        </div>
    </a> 
    

    /Chriztian

  • Steve 472 posts 1216 karma points
    Apr 19, 2013 @ 20:01
    Steve
    0

    Thanks Chriztian! It works now. I could use some more help though. I have created a parameter in my macro and assigned the variable to the player controls like this: (so I could have one play and all other not auto play)

    <script type="text/javascript">
    <![CDATA[
        var autoplay = "]]><xsl:value-of select="$autoplay" /><![CDATA[";
        var videoid = "]]><xsl:value-of select="$videoid" /><![CDATA[";
        flowplayer(videoid, "/scripts/flowplayer-3.1.4.swf", {
    clip: {
        autoPlay: '$autoplay'
                }
    plugins: {
        controls: {
    url: "/scripts/flowplayer.controls-3.1.4.swf",
    progressColor: '#a3000f',
    backgroundGradient: 'high',
    backgroundColor: 'transparent',
    buttonColor: '#a3000f',
    buttonOverColor: '#ac525b',
    bufferColor: '#bbbbbb',
    timeColor: '#ffffff',
    durationColor: '#000000',
    volumeSliderColor: '#bbbbbb',
    
    autoHide: {
            enabled: 'true',
            hideDelay: 0
               }
    }
     }
    
    
    }
    );
    ]]>
    </script>
  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Apr 19, 2013 @ 22:52
    Chriztian Steinmeier
    0

    Hi Steve,

    This seems to be because you're starting to get confused whether you're in XSLT or in JavaScript - happens a lot when you generate JavaScript like this :-)

    Try this:

    <scripttype="text/javascript">
           
    var autoplay ="<xsl:value-of select="$autoplay"/>";
           
    var videoid ="<xsl:value-of select="$videoid" />";<![CDATA[
            flowplayer
    (videoid,"/scripts/flowplayer-3.1.4.swf",{
                   
    clip:{ autoPlay: autoplay },
                    plugins
    :{
                            controls
    :{
                                    url
    :"/scripts/flowplayer.controls-3.1.4.swf",
                                    progressColor
    :'#a3000f',
                                    backgroundGradient
    :'high',
                                    backgroundColor
    :'transparent',
                                    buttonColor
    :'#a3000f',
                                    buttonOverColor
    :'#ac525b',
                                    bufferColor
    :'#bbbbbb',
                                    timeColor
    :'#ffffff',
                                    durationColor
    :'#000000',
                                    volumeSliderColor
    :'#bbbbbb',
                                    autoHide
    :{
                                            enabled
    :'true',
                                            hideDelay
    :0
                                   
    }
                           
    }
                   
    }
           
    });]]>
    </script>

    I can only recommend getting your JavaScript out in a separate file - and then just render some classes or data-attributes on the HTML for the JS to target. Makes it so much easier to maintain. 

    /Chriztian

  • Steve 472 posts 1216 karma points
    Apr 22, 2013 @ 14:33
    Steve
    0

    Chrizitian,

    I am getting an error on this line:   , Also, I believe I need the value of select for autoplay to be converted to a string instead of a boolean that is outputted from the parameter. Correct? How would I do this?

    Error occured

    Error in XSLT at line 48, char 18
    46:      <script type="text/javascript">
    47:      
    48: >>>   var autoplay = "<xsl:value-of select='$autoPlay' />"; <<<
    49:       var videoid = "<xsl:value-of select='$videoid' />";
    50:       <![CDATA[

     

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Apr 22, 2013 @ 19:47
    Chriztian Steinmeier
    0

    Hi Steve,

    Have you got the casing right for the $autoplay variable? In your first example it's all lowercase (except for the JavaScript key) - the erroneous code use the pascalCased version...

    XSLT will always convert to a string when using value-of - but doesn't the autoPlay key in JavaScript expect a JavaScript boolean? Like this:

    clip: { autoPlay: true } // not autoPlay: "true" right?

    How is your /macro/autoplay parameter set up? Is it a text or a boolean?

    /Chriztian

  • Steve 472 posts 1216 karma points
    Apr 22, 2013 @ 19:57
    Steve
    0

    You were right it was my variable, Sorry. Also, my parameter is set as a boolean, but I have seen it return a 1 or 0 for the variable within the page and I thought it would have to be true or false. 

    Edit:

    Just tried it out again. It autoplays both videos and the output in the code is showing a autoPlay = "1" and autoPlay = 0" for the other.

    Edit: 

    Tried changing the macro to "text". It still plays both. Confusing. Any suggestions?

    Below is the browser output:

     var autoplay = "0";
     var videoid = "ID20750";
    
     flowplayer(videoid, "/scripts/flowplayer-3.1.4.swf", {
    clip: {autoPlay:autoplay},
    
    plugins: {
        controls: {
    url: "/scripts/flowplayer.controls-3.1.4.swf",
    progressColor: '#a3000f',
    backgroundGradient: 'high',
    backgroundColor: 'transparent',
    buttonColor: '#a3000f',
    buttonOverColor: '#ac525b',
    bufferColor: '#bbbbbb',
    timeColor: '#ffffff',
    durationColor: '#000000',
    volumeSliderColor: '#bbbbbb',
    
    
    
    autoHide: {
            enabled: 'true',
            hideDelay: 0
               }
    
    
    }
         }
    
    
    }
    );
    
    
  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Apr 22, 2013 @ 20:09
    Chriztian Steinmeier
    0

    Hi Steve,

    Okay - so do you get any other detailes in the error message? Maybe the variable is out of scope?

    To get the word true (or false) when outputting the variable, just define it using the boolean() function, e.g.:

    <xsl:variable name="autoPlay" select="boolean(/macro/autoplay)" />

    Then you'll get true/false when it's converted by the value-of instruction.

    /Chriztian

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Apr 22, 2013 @ 20:12
    Chriztian Steinmeier
    100

    Great,

    Regarding the "1", "0", "true" & "false" thing:

    Drop the quotes - in JavaScript, Boolean("0") returns true - because it's a non-empty string.

    So like this:

    var autoplay = <xsl:value-of select="$autoplay"/>; // No quotes around...

    /Chriztian

  • Steve 472 posts 1216 karma points
    Apr 22, 2013 @ 20:44
    Steve
    0

    Chriztian, 

    Thanks for the help! It's working!!! (after removing the quotes from the value-of-select). Did you have any ideas as to why when the autoHide is enabled and it moves off the movie to hide, it leves a black bar underneath the movie?

    Example:

    http://www.rose-hulman.edu/admissions-financial-aid/get-to-know-rose-hulman.aspx

Please Sign in or register to post replies

Write your reply to:

Draft