working FlowPlayer for FlashVideo replacement

boblgum

Joined: 2009-08-07
Posts: 1
Posted: Fri, 2009-08-07 09:06

hi @ll

i've seen that some users got problems with FlowPlayer 3.*

i've modified the FlashVideo-module-code. so it uses now the (much more better looking at least) FlowPlayer. furthermore it uses the Wowza Media Server for real streaming and can be used with new f4v-videos. I'm using the FastPlay-Sample as WMS-Application.
to enable f4v you need the MIME-module to edit "video/mp4"-type. any f4v-video will be passed as an h.264-video to WowzaMS.
place the flowplayer-files in the folder:
GAL2BASE/modules/flashvideo/flowplayer/*
here ist the modified code of "FlashVideoRenderer.class" (comments are removed)

<?php

GalleryCoreApi::requireOnce('modules/core/classes/GalleryRenderer.class');

class FlashVideoRenderer extends GalleryRenderer {

    function canBeViewedInline($item) {
		return GalleryUtilities::isA($item, 'GalleryMovieItem')
			&& (
				$item->getMimeType() == 'video/x-flv' ||
				$item->getMimeType() == 'video/mp4'
				);
    }

    function render($format, $entity, $item, $params) {
		global $gallery;
		$fallback = trim(preg_replace("/[\r\n]/", '', $params['fallback']));

		if ($format != 'HTML' || (
				$entity->getMimeType() != 'video/x-flv' && 
				$entity->getMimeType() != 'video/mp4')
			) {
			return null;
		}

	$urlGenerator =& $gallery->getUrlGenerator();

	$src = $urlGenerator->generateUrl(
		array('view' => 'core.DownloadItem', 'itemId' => $entity->getId(),
		      'serialNumber' => $entity->getSerialNumber()),
		array('forceFullUrl' => true, 'forceSessionId' => true, 'htmlEntities' => false));

	list ($width, $height, $title) = array($entity->getWidth(), $entity->getHeight(), $item->getTitle());

	GalleryCoreApi::requireOnce('lib/smarty_plugins/modifier.markup.php');

	$title = smarty_modifier_markup($title, 'strip');

	

	$itemId = $item->getId();
	list ($ret, $thumbnail) = GalleryCoreApi::fetchThumbnailsByItemIds(array($itemId));
	if (!$ret && !empty($thumbnail)) {
	    $thumbUrl = $urlGenerator->generateUrl(		
		array('view' => 'core.DownloadItem', 'itemId' => $thumbnail[$itemId]->getId(),
		      'serialNumber' => $thumbnail[$itemId]->getSerialNumber()),
		array('forceFullUrl' => true, 'forceSessionId' => true, 'htmlEntities' => false));

	    //$flashVars .= '&thumbUrl=' . urlencode($thumbUrl);
		$thumb_w = $thumbnail[$itemId]->width;
		$thumb_h = $thumbnail[$itemId]->height;
	}
	list ($ret, $module) = GalleryCoreApi::loadPlugin('module', 'flashvideo');
	if ($ret) {
	    return null;
	}
	
	$jsWarning = $module->translate('JavaScript required to view this content.');

	
	$SWFObjectUrl = $urlGenerator->generateUrl(
			array('href' => './modules/flashvideo/flowplayer/flowplayer-3.1.2.min.js'),
			array('forceFullUrl' => false));
	$playerUrl = $urlGenerator->generateUrl(
			array('href' => './modules/flashvideo/flowplayer/flowplayer-3.1.2.swf'),
			array('forceFullUrl' => false));
		$pluginRtmpUrl = $urlGenerator->generateUrl(
			array('href' => './modules/flashvideo/flowplayer/flowplayer.rtmp-3.1.1.swf'),
			array('forceFullUrl' => false));;
		$controlsUrl = $urlGenerator->generateUrl(
			array('href' => './modules/flashvideo/flowplayer/flowplayer.controls-3.1.2.swf'),
			array('forceFullUrl' => false));

	$pa = implode("", $item->fetchPath());
	$pa = array_reverse(explode("/", $pa));
	$flvpath = $pa[1]."/".$pa[0];

	if ($entity->getMimeType() == 'video/mp4') {
		$flvpath = 'mp4:'.$flvpath;
	}
	$tag = sprintf(
			'<script type="text/javascript" src="%s"></script>
			<a class="flowplayer" id="fms" style="display:block;margin-left:auto;margin-right:auto;width:%dpx;height:%dpx;vertical-align:bottom;">
				<img src="%s" alt="Click To Play" 
						style="display:block;margin-left:auto;margin-right:auto;width:%dpx;height:%dpx;"/>
			</a>
			<script>
				$f("fms", "%s", { 
					clip: { 
						provider: "rtmp",
						autoBuffering: true,
						scaling: "fit",
						url: "%s"
					},
					plugins: { 
						rtmp: { 
							url: "%s", 
							netConnectionUrl: "rtmp://YOUR_WMS_SERVER:1935/fastplay" 
						},
						controls: { 
							url:"%s",
							autoHide: "always",
							hideDelay: 2000,
							width: "98%%",  
							bottom: 5, 
							left: "50%%", 
							borderRadius: 15
						}
					} 
				});
			</script>
			'
			, $SWFObjectUrl, $width, $height, $thumbUrl, $thumb_w, $thumb_h, $playerUrl, $flvpath, $pluginRtmpUrl, $controlsUrl);
	return $tag;
    }
}
?>

have fun