Using the Dash Media Player with PHP

The following is a brief tutorial on how to implement the Dash Media Player in your PHP website. Although the player was designed to be used with the power and flexibility of Drupal Content Management System, you are more than welcome to use the PHP classes provided to easily implement this player in your PHP Website. If you would like more information on advanced usage for the player, simply go to TMT Digital.

Package Contents

When you download the new Dash Media Player package, you will notice the following files...

  • index.php - This file is a sample page on how you can incorporate the Dash Media Player using simply PHP.
  • dash.php - This file is used to include in your PHP file so that you can use the dashplayer_get_player API used throughout this website. To include this in your PHP page and use the dashplayer_get_player API, you would simply use the following code in your PHP page.

    <?php
    include ('/player/dash.php');
    $params['width'] = 652;
    $params['height'] = 432;
    print
    dashplayer_get_player($params);
    ?>

    Note that this may be different depending on where the dash.php file is located relative to the PHP file including the library.
  • DashPlayer.php - This is the DashPlayer class that can also be used to construct the Dash Media Player in a class like way. For example, you could show the player using the following code...

    <?php
    include('/player/DashPlayer.php');
    $params['width'] = 652;
    $params['height'] = 432;
    $player = new DashPlayer($params);
    $player->show();
    ?>
  • DashPlaylist.php - This is the playlist management class for getting and caching playlists within the playlists directory.
  • getplaylist.php - This is interface file for getting and showing any playlist using the GET method.
  • DashUtils.php - PHP helper functions used by DashPlayer.php and DashPlaylist.php.
  • dashPlayer.swf - The Dash Media Player (VERSION 1.2.1).
  • dashPlayer.js - The Dash Media Player JavaScript interface gateway. This is used for Remote Playlists as well as controlling the player from external sources.
  • skins - This directory contains all the skins to be used by the Dash Media Player as well as their respective Themes.
  • cache - This is the directory where the cached playlist XML files gets created. If you wish to rebuild your playlists, then you can simply delete the contents of this folder, and they will be regenerated.
  • playlists - This directory contains all the playlists that can be used in the Dash Media Player using the playlist parameter. Please note, that if you plan on having a lot of different playlists, it is probably worth exploring the Drupal integration which manages these playlists much more elegantly than having many different folders with playlists.

Quick Help Links

Below is a listing of some quick help topics to help you get started. If you would like to learn more, you are more then welcome to visit the Dash Media Player Documentation where you will find advanced usage topics for getting the most of the Dash Media Player.

Getting Started

  • Step 1: Copy Contents - The first thing that you will want to do is first copy all the contents from the downloaded Dash Media Player package to your server. I recommend creating a player directory in your root directory to contain all the contents of the downloaded player files.
  • Step 2: Change Permissions - Now that the files have been copied, you need to make sure that the cache folder has ALL permissions enabled (ie. 777). You can do this by right clicking on the cache folder and then select the Permissions and make sure all the check boxes are checked.
  • Step 3: Add the Music / Videos! - You can now start adding files to the default playlist directory. Each different track should be in its own folder that begins with track and followed by the track number. For example, if you wish to show a playlist with three different songs, then your directory structure would look like the following...
    • player
      • dashPlayer.swf
      • index.php
      • DashPlayer.php
      • DashPlaylist.php
      • DashUtils.php
      • getplaylist.php
      • dash.php
      • cache
      • skins
      • playlists
        • default
          • track1
            • Jack Johnson - Good People.mp3
            • AlbumArt.jpg
          • track2
            • John Mayer - Gravity.mp3
            • AlbumArt.jpg
          • track3
            • Sade - By Your Side.mp3
            • AlbumArt.jpg

Show the Dash Media Player in your PHP page

Now that you have your tracks in the directories they need to be, the next and final step is to show the player on your page. You do this using the following PHP code in your php file.

<?php
include ('player/dash.php');
$params['width'] = 652;
$params['height'] = 432;
print
dashplayer_get_player($params);
?>


It is also important to note that you can have more flexibility by using the DashPlayer class, so you can also do the same thing as above by using the following code.

<?php
include ('player/DashPlayer.php');
$params['width'] = 652;
$params['height'] = 432;
$player = new DashPlayer($params);
$player->show();
?>

After you have one of these in your PHP file, you should then be able to navigate to that page and see your playlist in the Media player!

Adding songs to the playlist...

Adding new songs to your playist is VERY easy... Simply create a new track folder in the playlists/default folder followed by the number which is the play order of the track in the playlist. For example... If I wish to add a new song that is position 4 in my playlist, then I would simply create a new folder in my default playlists folder called track4, and then place my image and media file in that directory. YES, IT IS THAT EASY!!!
It is very important to note that when you add a new track by creating a new track directory in your playlist, you need to delete the cache XML file out of the cache folder in order for that change to take effect. Then this XML file will get regenerated the next time you show the Media Player in your page.

Adding new playlists

Adding new playlists is just a simple as adding a new directory in the playlists folder, and then after that add the track folders that you normally would with the default playlist folder. Then, once you have done that, you will then add the playlist parameter to the dashplayer_get_player API, like this...

<?php
include ('player/dash.php');
$params['playlist'] = 'myplaylist';
print
dashplayer_get_player($params);
?>