Adding Flowplayer as embedded flv player in ATutor

Flowplayer is a great player for Flash video files (.flv) which we have used quite a lot the last six months, and will use a lot more in the coming months. As of ATutor 1.6.1 the media tag has improved so much that I wanted to add Flowplayer as an integrated part of the ATutor content creation process.
I've decided not to create this as a patch or module, as there are many different ways you can make use of Flowplayer in ATutor, and because we will probably improve on this integration in the future as well.
I am however describing it all in detail here, so you should be able to set this up yourself quite easily!
The first thing you have to do is download Flowplayer (this tutorial tested with version 2.2.1 of Flowplayer, but any version should work).
I unzipped and uploaded the whole folder at root level on my server, so it will always be there regardless of me upgrading ATutor or not.
The second thing you will have to do is refer to the flowplayer.min.js file in your theme's header. I'm using the Redux theme, so I edit the atutor/themes/Atutor-redux/include/header.inc.php file, and add the following within head:
<script type="text/javascript" src="/flowplayer/flashembed.min.js"></script> Note that the default path for this file in Flowplayer is /flowplayer/examples/js/flowplayer.min.js, I just moved it down a few directories.
Now, save this, and we are ready to continue. This time we first have to edit atutor/include/lib/output.inc.php to make ATutor insert the appropriate flowplayer code when wrapping a .flv file in the media tag. At around line 650, right after the 6 lines of code for the .mid format, and before the comment that reads // Executing the replace, add:
<?php
// .flv - uses Flowplayer from flowplayer.org (EXTERNAL)
preg_match_all("#\[media[0-9a-z\|]*\]http://([\w\./-]+)\.flv\[/media\]#i",$text,$media_matches[11],PREG_SET_ORDER);
$media_replace[11] ="<div id=\"flowplayerholder_##MEDIA1##\">Flash Player needed!</div>
<script type=\"text/javascript\">
// <![CDATA[
new flashembed(\"flowplayerholder_##MEDIA1##\", { src: \"http://www2.helsekompetanse.no/flowplayer/FlowPlayerLight.swf\", width: ##WIDTH##, height: ##HEIGHT## }, { config: { videoFile: \"http://##MEDIA1##.flv\", embedCode: \"can not be embedded\", initialScale: 'scale', controlsOverVideo: 'ease', loop: false, autoPlay: false } });
// ]]></script>";
// .flv - uses Flowplayer from flowplayer.org (INTERNAL)
preg_match_all("#\[media[0-9a-z\|]*\]([\w\./-]+)\.flv\[/media\]#i",$text,$media_matches[12],PREG_SET_ORDER);
$media_replace[12] ="<div id=\"flowplayerholder_##MEDIA1##\">Flash Player needed!</div>
<script type=\"text/javascript\">
// <![CDATA[
new flashembed(\"flowplayerholder_##MEDIA1##\", { src: \"http://www2.helsekompetanse.no/flowplayer/FlowPlayerLight.swf\", width: ##WIDTH##, height: ##HEIGHT## }, { config: { videoFile: \"".AT_BASE_HREF."get.php/##MEDIA1##.flv\", embedCode: \"can not be embedded\", initialScale: 'scale', controlsOverVideo: 'ease', loop: false, autoPlay: false } });
// ]]></script>";
?>(don't paste in the php start and end tag)
around 20 lines further down the code you will have to add the line
<?php
$media_input = str_replace("flowplayerholder_##MEDIA1##","flowplayerholder_".str_replace(":/","",$media[1]),$media_input);
?>so the end result is:
<?php
//replace media tags with embedded media for each media tag
$media_input = $media_replace[$i];
$media_input = str_replace("##WIDTH##","$width",$media_input);
$media_input = str_replace("##HEIGHT##","$height",$media_input);
$media_input = str_replace("flowplayerholder_##MEDIA1##","flowplayerholder_".str_replace(":/","",$media[1]),$media_input);
$media_input = str_replace("##MEDIA1##","$media[1]",$media_input);
$media_input = str_replace("##MEDIA2##","$media[2]",$media_input);
$text = str_replace($media[0],$media_input,$text);
?>This ensures that you can have more that one Flowplayer video in any content page, as they all get an unique ID.
This should add Flowplayer to ATutor, and you can test it by uploading a demo.flv file in your file manager and manually wrap it in in the media tag!
However, it's better that ATutor wraps the file in the media tag for you, and to make that happen, edit the include/html/filemanager_display.inc.php file. At around line 350 here you will see:
<?php
else if (ext == "mpg" || ext == "avi" || ext == "wmv" || ext == "mov" || ext == "swf" || ext == "mp3" || ext == "wav" || ext == "ogg" || ext == "mid") ;
?>which basically tells the filemanager to wrap the extensions listed in the media tag. Here we have to add .flv as one of these extensions, so simply add || ext == "flv" here. The end result should be something like:
<?php
else if (ext == "mpg" || ext == "avi" || ext == "wmv" || ext == "mov" || ext == "swf" || ext == "mp3" || ext == "wav" || ext == "ogg" || ext == "mid" || ext == "flv") ;
?>Assuming that you have done this, uploaded a .flv file called ubuntucast.flv to your course file manageer and clicked "insert", you would see this in your content editor:
[media]ubuntucast.flv[/media]
Assuming you wish this to display in 550 x 400 pixels rather than the default 425 x 350, you would edit this into the media tag, like:
[media|550|400]ubuntucast.flv[/media]
..and the video would show up like this in the content:
Note that this file is 22 Mb, so let me know if you cannot see it. Also note that in this example I have removed the embedCode: \"can not be embedded\", from output.inc.php, just to demonstrate how you can use Flowplayer to embed videos in other pages! (Hat tip: check the bottom right icon).
Or, check it out in an ATutor content page!
Further configuration of Flowplayer
Flowplayer is highly configurable, for instance you edit the look and feel by simply configuring which parameters to add in output.inc.php. Above I chose to have the controls over the video to start, and auto hide them by adding controlsOverVideo: 'ease' to the file. In addition there are tons of other options, including integration with streaming server and using playlists etc.
Enjoy!
Edit by Håvard Pedersen jan 09: Added support for playing flv files from external domains.
Comments
ATutor and Flash
March 23, 2009 - 03:54 — Ricardo JArdim (not verified)VEgard,
Thank you for the tutorial. I have been looking for some help, and your was the closest I could get. However, my situation is abit different.
I am trying to embed a flash player (flashmo) within a content page in ATutor. I tried all I could and a bit more, just to have an empty page. All possible path combinations have been attempted also. Here is the code:
-----------------------------------------
<script type="text/javascript"><!--
AC_FL_RunContent = 0;
// --></script>
<script src="http://www.lingocentre.com/flashmo/timemachine/AC_RunActiveContent.js"></script>
</p>
<!--url's used in the movie-->
<!--text used in the movie-->
<!--
<p align="left"><font face="Verdana" size="11" color="#000000" letterSpacing="0.000000" kerning="1">artist name</font></p>
<p align="left"><font face="Verdana" size="11" color="#000000" letterSpacing="0.000000" kerning="1">album title</font></p>
<p align="left"><font face="Verdana" size="11" color="#000000" letterSpacing="0.000000" kerning="1">track title</font></p>
<p align="right"><font face="Verdana" size="11" color="#000000" letterSpacing="0.000000" kerning="1">00:00 / 00:00</font></p>
<p align="right"><font face="Verdana" size="11" color="#000000" letterSpacing="0.000000" kerning="1">Track 00 of 00</font></p>
<p align="right"><font face="Verdana" size="11" color="#000000" letterSpacing="0.000000" kerning="1">loading 100%</font></p>
-->
<!-- saved from url=(0013)about:internet -->
<p>
<script type="text/javascript"><!--
if (AC_FL_RunContent == 0) {
alert("This page requires AC_RunActiveContent.js.");
} else {
AC_FL_RunContent(
'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0',
'width', '600',
'height', '200',
'src', 'flashmo_058_mp3_player_xml',
'quality', 'high',
'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
'align', 'middle',
'play', 'true',
'loop', 'true',
'scale', 'showall',
'wmode', 'window',
'devicefont', 'false',
'id', 'flashmo_058_mp3_player_xml',
'bgcolor', '#ffffff',
'name', 'flashmo_058_mp3_player_xml',
'menu', 'true',
'allowFullScreen', 'false',
'allowScriptAccess','sameDomain',
'movie', 'flashmo_058_mp3_player_xml',
'salign', ''
); //end AC code
}
// --></script>
</p>
<noscript>
&amp;lt;span class="mceItemObject" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="600" height="200" id="flashmo_058_mp3_player_xml" align="middle"&amp;gt;
&amp;lt;span name="allowScriptAccess" value="sameDomain" class="mceItemParam"&amp;gt;&amp;lt;/span&amp;gt;
&amp;lt;span name="allowFullScreen" value="false" class="mceItemParam"&amp;gt;&amp;lt;/span&amp;gt;
&amp;lt;span name="movie" value="http://www.lingocentre.com/flashmo/timemachine/flashmo_058_mp3_player_xml.swf" class="mceItemParam"&amp;gt;&amp;lt;/span&amp;gt;&amp;lt;span name="quality" value="high" class="mceItemParam"&amp;gt;&amp;lt;/span&amp;gt;&amp;lt;span name="bgcolor" value="#ffffff" class="mceItemParam"&amp;gt;&amp;lt;/span&amp;gt; &amp;lt;span class="mceItemEmbed" src="http://www.lingocentre.com/flashmo/timemachine/flashmo_058_mp3_player_xml.swf" mce_src="http://www.lingocentre.com/flashmo/timemachine/flashmo_058_mp3_player_xml.swf" quality="high" bgcolor="#ffffff" width="600" height="200" name="flashmo_058_mp3_player_xml" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /&amp;gt;
&amp;lt;/span&amp;gt;
</noscript>
-----------------------------------------
Please help. I really cannot see what is wrong with the code.
Thank you
Re: ATutor and Flash
March 23, 2009 - 21:07 — Vegard A. JohansenHi Ricardo, I cannot say what is wrong with this page without testing it, but have you:
a) tested the same code on a page *outside* an ATutor installation (that is just uploaded it to a server and viewed it)? If that does not work the cause does not lie in ATutor.
if that does work I do believe it must be either a path problem (try placing the files outside the content directory, and link to them with the full URL), or it's the editor that strips out certain tags that are needed.
I did however try to include one of the .swf files via the media tag, like this:
[media]http://www.lingocentre.com/flashmo/timemachine/flashmo_058_mp3_player_xml.swf[/media]which worked fine except that it didn't find the data (which also makes sense as I didn't specify where it could find them). Try that, and try to place all the js above here in the Custom Head section for that page, not within the content of the page itself.
Post new comment