Log in | Register | Lost password

Bottom
media flv api
  • Posted: 31.12.2007, 12:13
     
    Converted
    rank:
    12
    registered:
     March 2009
    Status:
    offline
    last visit:
    Posts:
    0
    Has anyone developed a media handler for FLV files yet?
  • Posted: 04.03.2008, 11:17
     
    Converted
    rank:
    12
    registered:
     March 2009
    Status:
    offline
    last visit:
    Posts:
    0
    I have updated the Flash Media Handler to also handle flv files (with the help of some others, see http://communit…opic-53776.htm). For this to work you need the JW Media Player http://www.jero…w_media_player. If you place it into any other folder than the document root, e.g. javascript/, you also need to indicate the full URL for the flv files [param name=\"flashvars\"
    value=\"file=http://yoursite.com/$url&autostart=true\" /] as flv either needs URLs relative to the player or full URLs.

    Code

    <?php

    // $Id: pnmedia_flashapi.php,v 1.6 2006/03/26 18:01:54 jornlind Exp $

    // =======================================================================

    // Mediashare by Jorn Lind-Nielsen (C) 2005.

    // ----------------------------------------------------------------------

    // For POST-NUKE Content Management System

    // Copyright (C) 2002 by the PostNuke Development Team.

    // http://www.postnuke.com/

    // ----------------------------------------------------------------------

    // LICENSE

    //

    // This program is free software; you can redistribute it and/or

    // modify it under the terms of the GNU General Public License (GPL)

    // 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.

    //

    // To read the license please visit http://www.gnu.org/copyleft/gpl.html

    // =======================================================================



    //require_once 'modules/mediashare/mediaHandler.php';





    class mediashare_flashHandler

    {

    function getTitle()

    {

    return 'Mediashare Flash Handler';

    }





    function getMediaTypes()

    {

    return array(

    array('mimeType' => 'video/x-flv', 'fileType' => 'flv',

    'foundMimeType' => 'video/x-flv', 'foundFileType' => 'flv'),

    array('mimeType' => 'application/x-shockwave-flash', 'fileType' => 'swf',

    'foundMimeType' => 'application/x-shockwave-flash', 'foundFileType' => 'swf')



    );

    }





    function createPreviews($args, $previews)

    {

    $mediaFilename = $args['mediaFilename'];

    $mimeType = $args['mimeType'];

    $mediaFileType = $args['fileType'];



    $result = array();



    foreach ($previews as $preview)

    {

    if ($preview['isThumbnail'])

    {

    copy('modules/mediashare/pnimages/logo_flash_player.png', $preview['outputFilename']);

    $imPreview = @imagecreatefrompng($preview['outputFilename']);

    $result[] = array('fileType' => 'png',

    'mimeType' => 'image/png',

    'width' => imagesx($imPreview),

    'height' => imagesy($imPreview),

    'bytes' => filesize($preview['outputFilename']));

    imagedestroy($imPreview);

    }

    else

    {

    $width = $preview['imageSize'];

    $height = $preview['imageSize'];

    if ( array_key_exists('width', $args) && (int)$args['width'] > 0

    && array_key_exists('height', $args) && (int)$args['height'] > 0)

    {

    $w = (int)$args['width'];

    $h = (int)$args['height'];



    if ($w < $width || $h < $height)

    {

    $width = $w;

    $height = $h;

    }

    else if ($w > $h)

    $height = ($h/$w) * $height;

    else

    $width = ($w/$h) * $width;

    }



    $result[] = array('fileType' => $mediaFileType,

    'mimeType' => $mimeType,

    'width' => $width,

    'height' => $height,

    'useOriginal' => true,

    'bytes' => filesize($preview['outputFilename']));

    }

    }



    $width = (array_key_exists('width', $args) && (int)$args['width'] > 0 ? (int)$args['width'] : $preview['imageSize']);

    $height = (array_key_exists('height', $args) && (int)$args['height'] > 0 ? (int)$args['height'] : $preview['imageSize']);



    $result[] = array('fileType' => $mediaFileType,

    'mimeType' => $mimeType,

    'width' => $width,

    'height' => $height,

    'bytes' => filesize($mediaFilename));



    return $result;

    }





    function getMediaDisplayHtml($url, $width, $height, $id, $args)

    {

    $widthHtml = ($width == null ? '' : " width=\"$width\"");

    $heightHtml = ($height == null ? '' : " height=\"$height\"");



    return "

    <!--[literal]--><!--[if !IE]> --><!--[/literal]-->



    <!--[literal]--><!-- <![endif]--><!--[/literal]-->



    <!--[literal]--><!--[if IE]><!--[/literal]-->



    <param name=\"movie\" value=\"javascript/mediaplayer.swf\"\">

    <!--[literal]--><!--><!----><!--[/literal]-->



    <param name=\"allowfullscreen\" value=\"true\" />

    <param name=\"allowscriptaccess\" value=\"always\" />

    <param name=\"shownavigation\" value=\"true\" />

    <param name=\"flashvars\"

    value=\"file=http://yoursite.com/$url&autostart=true\" />



    ";

    }





    // Internal functions

    };





    function mediashare_media_flashapi_buildHandler($args)

    {

    return new mediashare_flashHandler();

    }



    ?>


    As you may have noticed, I have hardcoded width and height. You may use the handler's values instead.

Template courtesy of Designs By Darren.