Symfony World blog is not maintained anymore. Check new sys.exit() programming blog.

Embedding videos in symfony projects using sfVideoPlugin

What does the plugin do?

sfVideoPlugin is a plugin created by a small international symfony developers team. It's destined to give an easy interface for online video embedding. The plugin uses flowplayer software and uses files with the flv extension.

It's so easy

sfVideoPlugin comes provided with few ways of embedding a flash video player inside you project.

including a partial

Once the plugin:publish-assets task has been run, flv files can be accessed from the web. Just include the video partial from the sfVideo module (enable it first, of course) passing one obligatory parameter - file (it's taken from the default flv directory):

include_partial('sfVideo/video', array('file' => '01.flv'));
Take a look at the plugin demo site.

video widget

Use the sfVideoWidget class inside your forms to display the player inside a form (you may use predefined sfVideoForm class which has only one widget). An example study case using video widget is uploading video files in the backend - user should have the opportunity to display the video file before publishing it online.

multiple player embedding

A simple parameter has been added to the partial mentioned above to enable displaying more than one video widget on one page. If the player parameter is not set when including a partial, the default value is "player" - you need to override the default value to display more than one player. Put the following code into an action:

$this->players = array(
  array('file' => '01.flv', 'player' => 'player01'),
  array('file' => '02.flv', 'player' => 'player02'),
  array('file' => '03.flv', 'player' => 'player03'),
and include the partial for each of defined players:
<?php foreach($players as $p): ?>
<?php include_partial('sfVideo/video', $p) ?>
<?php endforeach; ?>
Take a look at a live demo.


At now, there are four attributes defined in the app.yml file that are common for all players in the plugin. These are:

  • width
  • height
  • autoplay
  • autobuffering
The first two attributes take an integer value and the rest takes true/false values. Access them using:


Feel free to comment on the post and to contribute to develop the plugin.

No comments:

Post a Comment