Visit Superuser

Ogg extension

From Superuser Wiki

This Ogg extension will insert a Cortado Java Applet which streams an Ogg uploaded file.

You can download the Cortado Java Applet.

Contents

Demo

Tag

<ogg>uploaded filename.ogg</ogg>

or

<ogg>uploaded filename.ogg|download|width|height|video|duration</ogg>

The "download" parameter adds an icon with link to download the ogg
The "width" and "height parameters are the size of the applet
The video parameter should be either true or false. False if you are just playing audio.
The "duration" parameter is so the file will be seekable.

<ogg>Juggling_jack01.ogg|download|320|240|true|14</ogg>

Requisits

  • cortado.jar in the $wgScriptPath/extensions directory
  • download.png in the images ($wgUploadPath) directory : an image of your choice

Install instructions

  1. Include it at the end of your LocalSettings.php :
    include("extensions/ogg.php");
  2. If you want to accept ogg uploads, add .ogg in the extension list :
    $wgFileExtensions = array('png','gif',...,'ogg');

PHP code (copy from here!)

Copy/paste into your editor, save it to extentions/ogg.php, and then upload it to your site.

<?php
# Stream Ogg with Cortado
# 
# http://chris.superuser.com.au
# About the licence of the Cortado : GNU GPL
# 
# Tag :
#   <ogg>uploaded filename.ogg or URL</ogg>
#   <ogg>uploaded filename.ogg or URL|download</ogg> adds an icon with link to download the ogg
# Requires :
#   cortado.jar in the $wgScriptPath/extensions directory
#   download.png in the images ($wgUploadPath) directory : an image of your choice
# 
# To activate the extension :
# - include it at the end of your LocalSettings.php : include("extensions/ogg.php");
# - add .ogg in the extension list if you want to allow ogg uploads :
#   $wgFileExtensions = array('png','gif',...,'ogg');
# 
# Enjoy !

$wgExtensionFunctions[] = 'wfOgg';
$wgExtensionCredits['parserhook'][] = array(
        'name' => 'ogg',
        'description' => '[http://chris.superuser.com.au ' .
                        'Cortado Ogg player] is light and streams your ogg',
        'author' => 'Chris Harvey',
        'url' => 'http://meta.wikimedia.org/wiki/Ogg'
);

function wfOgg() {
        global $wgParser;
        $wgParser->setHook('ogg', 'renderOgg');
}

# The callback function for converting the input text to HTML output
function renderOgg($input) {
        global $wgScriptPath, $wgUploadPath;
        //$input = "filename.ogg"
        $arr = explode('|', trim($input));
        $addDLlink = isset($arr[1]) && ($arr[1] == 'download');
        $input = $arr[0];
        $img = Image::newFromName($input);
        $ogg = '';
	$apwid = $arr[2];
	$aphig = $arr[3];
	$video = $arr[4];
	$durat = $arr[5];
        $bgcolor = 'FFF8DC'; //You can change it, of course :-)
        
        //The parameters for object and embed
        # File uploaded or external link ?
        if (!$img->exists()) {
                //Must be http://... URL
                if (substr($input,0,7) == 'http://')
                        $ogg = $input;
        } else
                $ogg = $img->getURL();
        if ($ogg == '')
                return '<div class="noprint">Needs to be : '.$input.'<br />'
                        .'Missing ressource: '.$input.'</div>';
        unset($img);
        
        $output = '<applet code="com.fluendo.player.Cortado.class" archive="'.$wgScriptPath.'/extensions/cortado.jar" width="'.$apwid.'" height="'.$aphig.'"> '
        . '<param name="url" value="'.$ogg.'"/> '
        . '<param name="framerate" value="25"/> '                                         
	. '<param name="keepAspect" value="true"/> '                                      
	. '<param name="video" value="'.$video.'"/> '                                            
	. '<param name="audio" value="true"/> '                                           
	. '<param name="bufferSize" value="200"/> '  
	. '<param name="seekable" value="true"/> '
	. '<param name="duration" value="'.$durat.'"/> '                                   
	. '</applet> ';
        if ($addDLlink) {
                $output .= '<a href="'.$ogg.'" title="Download">'
                        .'<img src="'.$wgUploadPath.'/download.png" alt="Download" />'
                        .'</a>';
        }
        return $output;
}
?>