Streaming FLV videos #3

Dec 29, 2008 by Samantha Halfon · Leave a Comment ·
Filed under: Computing, Internet 

I’ve described in an earlier post how we play videos on our site using the JW Media Player. We created a playlist that begins with our animated logo then shows some of our latest videos. The logo animation will play automatically when the page loads. The user is then presented a menu allowing him to watch the videos.


Jw Media Player on WWA

This menu only displays a sample of our videos, which means that some of our movies are not available from our main page. This is something I intend to fix shortly. The real limitation of this system was that we could not provide a direct link to any of these videos to people who might want to easily play a given movie or link to it from their own website. To handle direct links, I wrote a PHP script which generates the playlist.xml file used by the jw media player. If a movie is requested via the url, it will be the first one in the playlist and will automatically play, the other videos of the default playlist are added to the playlist.

If you wish to create a similar feature for your site, here are the main steps of the procedure :

  • Create your PHP script file (for example playlistgenerator.php).
  • In this file, declare an array that will contain the information about each video of the playlist. Here is an example of the array structure  I used:
$videos = array (
0 => array (
“default” => 1,
“name” => “wwa logo”,
“title” => “World Wide Angle animation logo”,
“url” => “world_wide_angle.flv”,
“thumbnail” => “thumbnails/world_wide_angle.jpg”,
“author” => “World Wide Angle”,
“date” => “”,
“description” => “World Wide Angle animation logo”,
“link” => “”
1 => array (
“default” => 1,
“name” => “second_video_title”,
“title” => “Title of the second video”,
“url” => “second_video.flv”,
“thumbnail” => “thumbnails/second_video.jpg”,
“author” => “World Wide Angle”,
“date” => “September 20, 2008″,
“description” => “description of the second video”,
“link” => “”

I use the default attribute (value is 1 or 0) to define whether the video should be added to the playlist at all times, or only when it has been requested. If you want all your videos to always be in the playlist, set this attribute to 1.

Next, copy (and feel free to adapt) the following code in your script:

function appendVideoToXml($video, &$xml) {
$xml .= ‘<item>’;
$xml .= ‘<title>’.$video["title"].’</title>’;
$xml .= ‘<media:content url=”‘.$video["url"].’” type=”video/flv” start=”00:00″ />’;
$xml .= ‘<media:thumbnail url=”‘.$video["thumbnail"].’” />’;
$xml .= ‘<author>’.$video["author"].’</author>’;
$xml .= ‘<description>’.$video["description"].’</description>’;
$xml .= ‘<link>’.$video["link"].’</link>’;
$xml .= ‘</item>’;
}$xmlheader = ‘<rss version=”2.0″ xmlns:media=””><channel><title>World Wide Angle video gallery</title><link></link>’;
$xmlfooter .= ‘</channel></rss>’;
$selected = $_GET["title"];
$xmlselected = “”;
$xmldefault = “”;
foreach ($videos as $video) {
if ($video["name"] == $selected) {
appendVideoToXml($video, $xmlselected);
} else {
if ($video["default"] == 1)
appendVideoToXml($video, $xmldefault);
$xmlcontent = $xmlheader . $xmlselected . $xmldefault . $xmlfooter;
file_put_contents(“jwmediaplayer/playlist_custom.xml”, $xmlcontent);

As it is, the script expects the video name to be passed as the “title” parameter.

  • The script being PHP, you need to be sure that your server can run PHP, if so, upload the script to your server, and you can get the costs for this at
  • In your main page, call the script in order to generate the playlist
  • Finally, modify the page containing the player in order to use the generated playlist instead of the hard coded one
function initMediaPlayer() {
var so = new SWFObject(‘jwmediaplayer/player.swf’,'mpl’,’560′,’420′,’9′);

That’s it, it worked for us and allowed us to give artists a direct link to their videos that they could add on their own website: to see the scrcipt in action, you can follow the links below to discover the videos about Michael Johnston an Nassim Al Amin vernissages we filmed last month at chezGrace.

Hope this will help some of you out there.

First time on World Wide Angle, you may want to subscribe to our RSS feed. Thanks for visiting!



Speak Your Mind

Tell us what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!