We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 8323
    • 14 Posts
    Hello everyone,

    Here is my first snippet (and first php code ever actually). It does basically what subject name says - easily puts video html5 tag with multiple file formats (mp4, ogg, webm, flv) and adds code for Flash fall back for older browsers.

    The code is surely not the most perfect one so all advice is appreciated smiley But it works how I need. If anyone likes feel it free to modify and/or use.

    Here is the example:
    http://thelikeable.com/projects/motion/redisend

    And snippet call which generates that:
    [[html5Player? &ogg=`rediSend_promotional_video.ogg` &flv=`rediSend_promotional_video.flv` &width=`800` &height=`512` &image=`rediSend_splash.jpg`]]



    And here is the code for the snippet itself (with comments). In case of any questions feel free to ask:
    <?php
    // HTML5 Video Player Snippet created by Grzegorz 'dzes' Widła
    // Based on Video JS OpenSource HTML 5 Video Player
    // Version 0.9 June 2010
    
    // For full player templating capabilities go here: http://videojs.com/
    // Download package and apply css and javascript files responsible for styling.
    // If you prefer to keep it simple just erase few lines of the snippet below line 63 (check comments there)
    // Style div.wrap-video for alignement of the player.
    
    // Example usage:
    // [[html5Player? &mp4=`fileurl.mp4` &image=`splash.png` &width=`640` &height=`360`]]
    
    // Four file formats:
    // mp4, webm, ogg, flv
    // Using mp4 your video can be played on very most of devices/browsers but check AVC H.264 Licencing first.
    // Suggested are both ogg and mp4 (for all browsers support)
    
    // PARAMETERS:
    // &mp4=`fileurl.mp4`
    // &webm=`fileurl.webm`
    // &ogg=`fileurl.ogg`
    // &flv=`fileurl.flv`
    // &width=`width of the video in pixels`
    // &height=`height of the video in pixels`
    // &image=`splash image url.extension`
    
    
    
    // VIDEO FORMATS
    $mp4Code = '<source src="'. $mp4 .'" type="video/mp4">' . "\n";
    $webmCode = '<source src="'. $webm .'" type="video/webm">' . "\n";
    $oggCode = '<source src="'. $ogg .'" type="video/ogg">' . "\n";
    
    $flashFLVCode = '<param name="flashvars" value=\'config={"clip":"'. $flv .'"}\' />' . "\n";
    $flashMP4Code = '<param name="flashvars" value=\'config={"clip":"'. $mp4 .'"}\' />' . "\n";
    
    // PRINTED CODE
    echo "\n" . '<div class="wrap-video" style="width: '. $width .'px">';
    echo "\n" . '<div class="video-js-box">' . "\n";
    echo '<video class="video-js" width="'. $width .'" height="'. $height .'" poster="'. $image .'" controls preload>' . "\n";
    if (isset($mp4)) {
       echo $mp4Code;
      }
    if (isset($webm)) {
       echo $webmCode;
      }
    if (isset($ogg)) {
       echo $oggCode;
      }
    echo "\n" . '<object width="'. $width .'" height="'. $height .'" type="application/x-shockwave-flash" data="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf">
    <param name="movie" value="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf" />
    <param name="allowfullscreen" value="true" />' . "\n";
    if (isset($mp4)) {
        echo $flashMP4Code;
        }
        else {
        echo $flashFLVCode;
        }
    echo '<img src="'. $image .'" width="'. $width .'" height="'. $height .'" alt="Poster Image" title="No video playback capabilities." /> 
    </object> 
    </video>' . "\n";
            // GET RID OF THAT IF NOT USING VIDEO JS FOR STYLING
    echo '<p class="vjs-no-video"><strong>Download Video:</strong>' ."\n";
        
    if (isset($mp4)) {
        echo '<a href="'. $mp4 .'">MP4</a>  ' . "\n";
        }
    if (isset($webm)) {
        echo '<a href="'. $webm .'">WebM</a>  ' . "\n";
        }
    if (isset($ogg)) {
        echo '<a href="'. $ogg .'">Ogg</a>   ' . "\n";
        }
        if (isset($flv)) {
        echo '<a href="'. $flv .'">Flv</a>   ' . "\n";
        }
    echo '</p>' . "\n";
            // DELETE TILL HERE
    echo '</div>' . "\n";
    echo '</div>' . "\n";
    ?>
      • 25803 ☆ A M B ☆
      • 721 Posts
      This looks great and was just what we were looking to do. Thanks!

      You should release this to Extras.
        • 8323
        • 14 Posts
        Thanks, that’s encouraging smiley

        I will do so, just need to make some changes to html output so that code looks nicer.
          • 14349
          • 44 Posts
          Great Job on your first snippet

          Here is another idea for your website users that aren’t technically savvy but still need to manage videos
          (I’m using REVO but it will work with EVO too)

          Create a Template Variable for your template where your video will be. Call it videoupload your TV call will be->[[*videoupload]] or [*videoupload*] if you are using Evo
          Make the TV a file upload input and a widget or output as a String or text.
          When your client goes to edit a document that has a a videoupload TV - they will upload a video form there machine to your modx site.

          The output will be the directory of the video i.e. /assets/videos/myvideo.mp4


          In your snippit call you can do this [[html5Player? &mp4=`[[*videoupload]]` ]]

          This passes the directory string of the video location to the $mp4 variable in your snippit !

          So now managing videos is easier via the client ! - the only downside I found is inside of your snippit you have to do a php substring to rip off the first slash "/" that the TV returns

          So -> $mp4= substr($mp4, 1); returns "assets/videos/myvideo.mp4" instead of "/assets/videos/myvideo.mp4"

          Hope you found this helpful - let me know if anyone can find a workaround for the extra slash
            • 8323
            • 14 Posts
            Yeah, I know about it but it’s not applicable for using outside pre-defined space in a template (correct me if I am wrong), so user can not basically put video anywhere where he writes content (and that was basic need here).
            I know that current implementation is not the best for non-tech users and that is why I will create plug-in for CKEditor (just custom button) adding HTML5 videos with same functionality as this snippet but with context menu, files upload from interface etc. I am waiting for Revolution final release with that though (as I do not like TinyMCE and do not want to install CKEditor as a plug-in right now for few reasons).

            Thanks for your suggestions though smiley
              • 14349
              • 44 Posts
              Oh I totally agree.

              I DONT want my clients just putting video "anywhere" so I build a structure for them that directs them using TV’s.

              A plugin for CKeditor would be AWESOME - just like the "media" button. I dislike TINYMCE but its all that comes with Revo (which you should check out if you haven’t - but you might get addicted to it - haha)

              I use HTML 5 videos in everything I do now - and it’s only growing.
                • 21635
                • 81 Posts
                Hi, i just did some tests with that and changed the syntax to use it with Revo.
                If someone is interested:
                <?php
                // HTML5 Video Player Snippet originally created by Grzegorz 'dzes' Widła
                // Based on Video JS OpenSource HTML 5 Video Player
                // Changed to Revo-Compatible format by nklsf 
                // Version 0.91 August 2010
                
                // For full player templating capabilities go here: http://videojs.com/
                // Download package and apply css and javascript files responsible for styling.
                // If you prefer to keep it simple just erase few lines of the snippet below line 63 (check comments there)
                // Style div.wrap-video for alignement of the player.
                
                // Example usage:
                // [[html5Player? &mp4=`fileurl.mp4` &image=`splash.png` &width=`640` &height=`360`]]
                
                // Four file formats:
                // mp4, webm, ogg, flv
                // Using mp4 your video can be played on very most of devices/browsers but check AVC H.264 Licencing first.
                // Suggested are both ogg and mp4 (for all browsers support)
                
                // PARAMETERS:
                // &mp4=`fileurl.mp4`
                // &webm=`fileurl.webm`
                // &ogg=`fileurl.ogg`
                // &flv=`fileurl.flv`
                // &width=`width of the video in pixels`
                // &height=`height of the video in pixels`
                // &image=`splash image url.extension`
                
                $output = '';
                
                // VIDEO FORMATS
                $mp4Code = '<source src="'. $mp4 .'" type="video/mp4">' . "\n";
                $webmCode = '<source src="'. $webm .'" type="video/webm">' . "\n";
                $oggCode = '<source src="'. $ogg .'" type="video/ogg">' . "\n";
                
                $flashFLVCode = '<param name="flashvars" value=\'config={"clip":"'. $flv .'"}\' />' . "\n";
                $flashMP4Code = '<param name="flashvars" value=\'config={"clip":"'. $mp4 .'"}\' />' . "\n";
                
                // PRINTED CODE
                $output .= "\n" . '<div class="wrap-video" style="width: '. $width .'px">';
                $output .= "\n" . '<div class="video-js-box">' . "\n";
                $output .= '<video class="video-js" width="'. $width .'" height="'. $height .'" poster="'. $image .'" controls preload>' . "\n";
                if (isset($mp4)) {
                   $output .= $mp4Code;
                  }
                if (isset($webm)) {
                   $output .= $webmCode;
                  }
                if (isset($ogg)) {
                   $output .= $oggCode;
                  }
                $output .= "\n" . '<object width="'. $width .'" height="'. $height .'" type="application/x-shockwave-flash" data="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf">
                <param name="movie" value="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf" />
                <param name="allowfullscreen" value="true" />' . "\n";
                if (isset($mp4)) {
                    $output .= $flashMP4Code;
                    }
                    else {
                    $output .= $flashFLVCode;
                    }
                $output .= '<img src="'. $image .'" width="'. $width .'" height="'. $height .'" alt="Poster Image" title="No video playback capabilities." /> 
                </object> 
                </video>' . "\n";
                        // GET RID OF THAT IF NOT USING VIDEO JS FOR STYLING
                $output .= '<p class="vjs-no-video"><strong>Download Video:</strong>' ."\n";
                    
                if (isset($mp4)) {
                    $output .= '<a href="'. $mp4 .'">MP4</a>  ' . "\n";
                    }
                if (isset($webm)) {
                    $output .= '<a href="'. $webm .'">WebM</a>  ' . "\n";
                    }
                if (isset($ogg)) {
                    $output .= '<a href="'. $ogg .'">Ogg</a>   ' . "\n";
                    }
                    if (isset($flv)) {
                    $output .= '<a href="'. $flv .'">Flv</a>   ' . "\n";
                    }
                $output .= '</p>' . "\n";
                        // DELETE TILL HERE
                $output .= '</div>' . "\n";
                $output .= '</div>' . "\n";  
                
                return $output;
                ?>​

                  • 4971
                  • 964 Posts
                  Why so many if statements?

                  The HTML5 <video> tag already goes through all the statements in the <source> section
                  until it finds one that works in that browser...

                  if it is for compatibility, the Modernizer library could be used to detect compatibility
                  and code appropriately...

                  good work anyway!
                    Website: www.mercologia.com
                    MODX Revo Tutorials:  www.modxperience.com

                    MODX Professional Partner
                    • 21635
                    • 81 Posts
                    Quote from: charliez at Aug 09, 2010, 10:23 AM

                    Why so many if statements?

                    The HTML5 <video> tag already goes through all the statements in the <source> section
                    until it finds one that works in that browser...

                    if it is for compatibility, the Modernizer library could be used to detect compatibility
                    and code appropriately...

                    well, i didn’t refactor any of the code, just adapted the syntax. just wanted to check out if videoJS suited my needs.
                    now working on a solution, using jw-player’s new html5-solution (http://www.longtailvideo.com/support/jw-player/jw-player-for-html5)

                    if my code makes sense, i’ll post it back here...

                    cheers
                      • 8323
                      • 14 Posts
                      Hello,

                      Firstly, nklsf, thanks for getting it Revo compatible. I hope it helped you do HTML5 video tests.

                      Secondly, charliez, I know code is far from perfect but IFs are there because in case snippet parameter was empty (i.e. ogg=`` or was not specified at all) it put out empty ogg video tag in html ( <source src="" type="video/ogg"> ) and leaving tag on it’s own was 1) unclean, 2) confused browser who supported only this one. I hope that clears things.

                      Anyway, if I am wrong please let me know how is that and I will surely be grateful for that smiley

                      Thank you,
                      Grzegorz.