custom player

Adding custom flv player to AttachMax

Its pretty simple to add and use custom player with AttachMax. I'll explain it on Jeroen Wijering's player example (we are using it on AttachMax.com now).

At first, please download Jeroen player and copy mediaplayer.swf to players/amJeroenPlayer/mediaplayer.swf and add bll/Player/Players/amJeroenPlayer.php file with following content:

<?php
class amJeroenPlayer extends amPlayer
{
    var $_sourcePath;

    function amJeroenPlayer()
    {
        parent::amPlayer();
        $this->setSourcePath(AM_PLAYER_DIR . '/amJeroenPlayer/' . 
            'mediaplayer.swf');
    }

    function getAutoPlayString ()
    {
        return $this->getAutoPlay() ? 'true' : 'false';
    }

    function getSourcePath()
    {
        return $this->_sourcePath;
    }

    function setSourcePath($value)
    {
        $this->_sourcePath = $value;
    }

    function getCustomParams()
    {
        return isset($GLOBALS[__CLASS__ . '_customParams']) ?
          $GLOBALS[__CLASS__ . '_customParams'] : array();
    }

    function setCustomParams($params)
    {
        $GLOBALS[__CLASS__ . '_customParams'] = $params;
    }

    function getHtml()
    {
        $p = amJeroenPlayer::getCustomParams();

        $flashVarsString = "file=" . $this->getVideoUrl();
        if (isset($p['FlashVars']))
        {
            foreach ($p['FlashVars'] as $k => $v)
            {
                $flashVarsString .= "&$k=$v";
            }
        }
        $flashVarsString .= '&autostart=' . $this->getAutoPlayString();

        $embedString = '';
        if (isset($p['embed']))
        {
            foreach ($p['embed'] as $k => $v)
            {
                $embedString .= " $k=\"$v\"";
            }
        }
        $embedString = '<embed src="' . $this->getSourcePath() .
            '" FlashVars="' . $flashVarsString . '" width="' .
            $this->getWidth() .
            '" height="' . $this->getHeight() . '" ' .
            $embedString . '>';

        return $embedString;
    }

}

Player class is ready, only few changes remained.

Open bll/Player/amPlayerFactory.php, find "function getExtensionsToPlayers()" and change "'flv' => 'amFlvPlayer'" to 'flv' => 'amJeroenPlayer'" under it. Then open configPlayers.php file and add:

amJeroenPlayer::setCustomParams(
    array(
       'embed' => array(
            'type' => 'application/x-shockwave-flash',
            'pluginspage' => 'http://www.macromedia.com/go/getflashplayer'
        ),

        'FlashVars' => array(
        )

    )
);

Jeroen player is ready to use now. To revert old player back you need to change single line in bll/Player/amPlayerFactory.php file, as we did for Jeroen player before.

For other, than Jeroen, flv player you can use same code with minor changes.

Please let me know, if you have any questions.

Alexander Makhaev