Extension talk:EmbeddedVideo

From MediaWiki.org
Jump to: navigation, search

Does not work, looked through the code, some images that the code use, for example "extensions/EmbeddedVideo/video.png" and "extensions/EmbeddedVideo/PlayButton.png" doesn't even exist. I checked vPIP version 1.11 through to 1.13. The images don't exist on those packages, although I'm not sure is that the reason vpip is breaking.


I cannot get this one to work in my MediaWiki. I get the following js error: "vPIPPlay is not defined". It seems that the function loadvPIPResources() does not add the extra js code to the page output but I don't know why, can someone help? Any solution would be great! Please mail to jbouche at heine dot de


[edit] (Partial) Fix

This might get it (partially) working. (this got the video embedded, but only after clicking the link)

Instead of 
<video caption="a sample mp4">sample.mp4</video>

Use
<localvideo caption="a sample mp4">sample.mp4</localvideo>

[edit] Made it work with MW1.12

Here is the modified code that was tested on MediaWiki 1.12:

<?php
/*
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USAw
 *  
 * @author Russel Philip
 * @version 0.1
 * 
 * Changelog
 * =========
 *
 * 0.0 - Initial release
 * 0.1 - Changed the load of css and javascript to be part of the first
 *       embedded video in the body of the HTML page so that it gets
 *       cached. An alternative would be to use BeforePageDisplay hook
 *       (as recommended in MediaWiki bug 5077), but then the scripts
 *       are loaded site-wide.
 *       Also changed the tag from "video" to "localvideo" in order to
 *       distinguish from the videos embedded from external services.
 *       Paths to some of the images changed.
 *       -- Andrea Matsunaga
 */
$wgExtensionFunctions[] = 'wfEmbeddedVideo';
$wgExtensionCredits['parserhook'][] = array(
        'name' => 'Embedded Video',
        'description' => 'uses vPIP to embed videos into pages',
        'author' => 'Russel Philip, Andrea Matsunaga',
        'url' => 'http://www.mediawiki.org/wiki/Extension:EmbeddedVideo',
        'version' => '0.1'
);
 
// Indicates that there is need to include the vPIP CSS and scripts.
$wgvPIPResources = false;
 
function wfEmbeddedVideo() {
        global $wgParser;
        $wgParser->setHook('localvideo', 'embedVideo');
}
 
function embedVideo( $input, $argv ) {       
        $video = new vPIPPlayer( $input, $argv );
        $result = $video->render();
        return $result;
}
 
class vPIPPlayer{
 
        /* Constructor */
        function vPIPPlayer($input, $args) {
 
                // Default parameter values
                $this->file = trim($input);
                $this->parameters['width'] = '320';
                $this->parameters['height'] = '260';
                $this->parameters['title'] = false;
                $this->parameters['caption'] = false;
                $this->parameters['image'] = false;
                $this->parameters['type'] = "auto";
                $this->parameters['download'] = false; 
                $this->parameters['autostart'] = "true";     
                $this->parameters['controller'] = "true";            
                $this->parameters['thickbox'] = "false";     
 
                // Load user specified parameter values
                foreach ($args as $parameter => $value) {
                        $this->parameters[$parameter] = $value;
                }
 
                // Verify the media file
                if (strstr($this->file,'http://') == $this->file) {
                        $this->url = $this->file;
                } else {
                        $this->url = $this->getViewPath($this->file);
                }
 
                // Verify the image file
                if($this->parameters['image'] and !(strstr($this->parameters['image'],'http://') == $this->file ))
                        $this->parameters['image'] = $this->getViewPath($this->parameters['image']);
 
                // Set the title
                if (!$this->parameters['title']) 
                        $this->parameters['title'] = $this->file;
 
                // Set the caption
                if (!$this->parameters['caption']) 
                        $this->parameters['caption'] = $this->parameters['title'];
 
                // Determin the mimetype
                if ($this->parameters['type'] == "auto") {
                        $extension = substr($this->file, -3, 3);
                        switch (strtolower($extension)) {
                        case "mov": $this->parameters['type'] = 'type="video/quicktime"'; break;
                        case "mp4": $this->parameters['type'] = 'type="video/mp4"'; break;
                        case "m4v": $this->parameters['type'] = 'type="video/x-m4v"'; break;
                        case "mp3": $this->parameters['type'] = 'type="audio/x-mp3"'; break;
                        case "smi": $this->parameters['type'] = 'type="application/smil"'; break;
                        case "3gp": $this->parameters['type'] = 'type="video/3gpp"'; break;
                        case "avi": $this->parameters['type'] = 'type="video/x-msvideo"'; break;
                        case "wmv": $this->parameters['type'] = 'type="video/x-ms-wmv"'; break;
                        case "asf": $this->parameters['type'] = 'type="video/x-ms-asf"'; break;
                        case "wma": $this->parameters['type'] = 'type="audio/x-ms-wma"'; break;
                        case "swf": $this->parameters['type'] = 'type="application/x-shockwave-flash"'; break;
                        case "flv": $this->parameters['type'] = 'type="application/x-shockwave-flashf"'; break;
                        default:
                                $this->parameters['type'] = "";
                        }
                }
        }
 
        /* Generate final code */
        function render(){             
                $this->setHeaders();
                $this->code .= '<div class="hvlog" style="position: relative;">';
                $this->code .='<a href="'.$this->url.'" rel="enclosure" class="hVlogTarget" title="'.$this->parameters['title'].'" type="'.$this->parameters['type'].'" onclick="vPIPPlay(this, \'width='.$this->parameters['width'].', height='.$this->parameters['height'].', autostart='.$this->parameters['autostart'].', controller='.$this->parameters['controller'].', name=MyMovie, revert=true\', \'\', \'active='.$this->parameters['thickbox'].', caption='.$this->parameters['caption'].'\'); return false;">';
 
                if ($this->parameters['image'])
                        $this->code .='<img width='.$this->parameters['width'].', height='.$this->parameters['height'].' src="'.$this->parameters['image'].'" />';
                else
                     $this->code .='<img width=128, height=128 src="/wiki/extensions/EmbeddedVideo/vPIP/vPIPbutton.png" />';
 
                if ($this->parameters['caption'] and ($this->parameters['caption']!= 'none'))
                        $this->code .='<p>'.$this->parameters['caption'].'</p>';
 
                $this->code .='<div style="position:absolute; left: 5px; top: 5px; font-weight: bold;"><img src="extensions/EmbeddedVideo/vPIP/vanilla/play.png" \></div>';
                $this->code .='</a>';
 
                if ($this->parameters['download'])
                        $this->code .= '<div style="position:absolute; left: 5px; top: 60px;"><a href="'.$this->url.'"><img src="extensions/EmbeddedVideo/vPIP/SaveButton.png" \></a></div>';
 
                $this->code .= '</div>';
 
                return $this->code;
        }
 
        /* get file url */
        function getViewPath($file) {
            // Get file as Image object from its name
            $img = Image::newFromName( $file );
            // Return the partial URL to the file
            return $img->getURL();
        }
        /* Set vPIP headers if not set yet. */
        function setHeaders() {
            global $wgvPIPResources, $wgScriptPath;
            $path = $wgScriptPath."/extensions/EmbeddedVideo/vPIP";
            if (!$wgvPIPResources) {
                $this->code .= <<<JAVASCRIPT
<style type="text/css" media="all">@import "$path/vPIPBox.css";</style><script type="text/javascript" src="$path/vpip.js"></script><script type="text/javascript" src="$path/jquery.js"></script><script type="text/javascript" src="$path/vpipit.js"></script>
JAVASCRIPT;
                $wgvPIPResources = true;
            }
        }
 
}

128.227.234.138 17:58, 17 September 2008 (UTC)

[edit] sidebar

when i put this code my media wiki side bar disappear --Bluemangoa2z 06:09, 21 June 2009 (UTC)

Personal tools
Namespaces
Variants
Actions
Site
Support
Download
Development
Communication
Print/export
Toolbox