Using the Open Standard Media Player PHP Library

Included in every download of the Open Standard Media Player found at http://www.mediafront.org/project/osmplayer, is a very powerful PHP library that can be used to embed the OSM Player as a standalone player using PHP. This library acts as a functional wrapper for the OSM Player as well as enables the dynamic theming. This gives any PHP website the power to use this media player with ease outside of a Content Management System environment. This article will go into great detail how this library works and how you can fully use it within your PHP website.

Description of files

Inside of the OSM Player download, you will see the following PHP files. Their descriptions are also provided below.

  • index.php - This is a sample index.php to show basic usage of the OSM Player PHP library.
  • OSMPlayer.php - A class wrapper around all of the functionality for adding, theming, and customizing the OSM Player using PHP.
  • getplaylist.php - This is a PHP script for retrieving dynamic playlists from the playlist folder. This will be described in this article.
  • playlist/Playlist.php - A class wrapper around the dynamic building and caching of playlists within the playlist/playlists folder.

These four files provide the complete functionality behind the PHP library for the Open Standard Media Player.

Step 1: Creating the media player in code.

When you wish to add the OSM Player to your page, the first thing that you will need to do is declare the media player object. It is important to note, however, that this needs to be done before any HTML elements have been sent to the client. The simple declaration of the OSM Player ( which does nothing... ), is shown below.

<?php
  
include("OSMPlayer.php");
  
$player = new OSMPlayer();
?>

<html>
   <head>
      <title>Open Standard Media (OSM) Player: PHP Demo</title>
   </head>
   <body>
   </body>
</html>

Step 2: Adding jquery.js to your page.

Another really important aspect is to include jquery.js to your page. jQuery comes included in the OSM Player download, so to add it to your page, simply use the following line.

<?php
  
include("OSMPlayer.php");
  
$player = new OSMPlayer();
?>

<html>
   <head>
      <title>Open Standard Media (OSM) Player: PHP Demo</title>
      <script type="text/javascript" src="jquery-ui/js/jquery.js"></script>
   </head>
   <body>
   </body>
</html>

Step 3: Passing parameters to the OSM Player object.

The functionality of the OSM Player is governed by the arguments that you pass to it when it is created. There is a large number of arguments that can be used to control the functionality of the media player. But for illustration, you can pass arguments to the constructor of the OSMPlayer object using an associative array, where the key is the name of the argument and the value is the value for that argument. For example, you can pass in a file argument to the media player using the following code.

<?php
  
include("OSMPlayer.php");
  
$player = new OSMPlayer( array(
     
'file' => 'http://www.mysite.com/files/myvideo.flv'
  
));
?>

<!-- HTML CODE GOES HERE -->

Step 4: Adding the header to the HTML page.

Because the OSM Player requires javascript files to function, there is a command that needs to be called from the PHP OSM Player object within the <head> of the HTML page. This command is called getHeader() and can be implemented as follows. NOTE: THIS IS REQUIRED OR YOUR PLAYER WILL NOT WORK.

<?php
  
include("OSMPlayer.php");
  
$player = new OSMPlayer( array(
     
'file' => 'http://www.mysite.com/files/myvideo.flv'
  
));
?>

<html>
   <head>
      <title>Open Standard Media (OSM) Player: PHP Demo</title>
      <script type="text/javascript" src="jquery-ui/js/jquery.js"></script>
      <?php print $player->getHeader(); ?>
   </head>
   <body>
   </body>
</html>

Step 5: Showing the media player.

Now that you declared the player, and added the header, showing the player is easy. Just simply use the <?php print $player->getPlayer(); ?> code wherever you would like to put it, and it will show up!

<?php
  
include("OSMPlayer.php");
  
$player = new OSMPlayer( array(
     
'file' => 'http://www.mysite.com/files/myvideo.flv'
  
));
?>

<html>
   <head>
      <title>Open Standard Media (OSM) Player: PHP Demo</title>
      <script type="text/javascript" src="jquery-ui/js/jquery.js"></script>
      <?php print $player->getHeader(); ?>
   </head>
   <body>
      <h2>Open Standard Media (OSM) Player</h2><br/>
      <?php print $player->getPlayer(); ?>
   </body>
</html>

And you are now ready to use the player! Please read some more documentation to learn how to implement different use cases!

Sponsors