You are here

function flowplayer3_swftools_flashvars in SWF Tools 6.2

Implementation of swftools_flashvars hook(). Note that $methods and $vars are passed by reference, so the player module can manipulate them directly if necessary.

Parameters

$action: String defining the action that is to be performed, eg SWFTOOLS_FLV_DISPLAY

&$methods: Object containing two keys - player and method. Each consists of an array that defines the details of the resolved player and embedding method that is being used for this file.

&$vars: Object containing three keys - othervars, flashvars and params. These are arrays containing key/value pairs that contain all the data assigned to this file so far. Refer to swf() for more details about the $vars array.

Return value

Return an array of flashvars needed to allow the player to work.

File

flowplayer3/flowplayer3.module, line 104

Code

function flowplayer3_swftools_flashvars($action, &$methods, &$vars) {

  // Over-ride embedding to use FlowPlayer?
  if (variable_get('swftools_flowplayer3_embed', FALSE)) {
    $methods->embed['module'] = 'flowplayer3';
  }

  // Initialise array of FlowPlayer3 configuration settings
  $flowplayer = array();

  // Initialise array to hold data
  $playlist = array();

  // Initialise flag to show it this content is being streamed
  $stream = FALSE;

  // Is this file to be streamed? Check for the stream variable being set
  if (isset($vars->othervars['stream'])) {

    // Set stream flag to true
    $stream = TRUE;
  }

  // If an image was supplied to be the splash then put this first in the list
  // This code doesn't seem to be working - the player objects to { url: '' }
  if (isset($vars->othervars['image'])) {
    $playlist[] = array(
      // Get url, checking for file existence, and using a relative url if possible.
      'url' => swftools_get_media_url(swftools_get_media_path() . $vars->othervars['image']),
      'autoPlay' => 'true',
    );
  }

  // If the passed variables includes 'playlist_data' we have a playlist
  if (isset($vars->othervars['playlist_data'])) {

    // Get file paths out of the playlist_data array and add to FlowPlayer playlist
    foreach ($vars->othervars['playlist_data']['playlist'] as $play) {

      // If this is a streamed playlist, use filename, otherwise use fileurl
      if ($stream) {
        $playlist[]['url'] = $play['filename'];
      }
      else {
        $playlist[]['url'] = $play['fileurl'];
      }
    }
  }
  else {

    // Not a playlist, so populate FlowPlayer3 playlist with the file_url
    $playlist[]['url'] = $vars->othervars['file_url'];
  }

  // Attach the completed playlist to flowplayer array
  $flowplayer['playlist'] = $playlist;

  // Retrieve the current FlowPlayer3 settings
  $saved_settings = _flowplayer3_settings();

  // Scan through each setting to see if it is over-ridden in $vars->othervars
  // Unset properties that are blank to keep the resulting code 'tidy'
  foreach ($saved_settings as $category => $data) {
    foreach ($data as $property => $value) {
      if (isset($vars->othervars[$property])) {
        $saved_settings[$category][$property] = $vars->othervars[$property];
      }
      if (!$saved_settings[$category][$property]) {
        unset($saved_settings[$category][$property]);
      }
    }
  }

  // If the object doesn't have a width set then assign one
  if (!isset($vars->params['width'])) {
    $vars->params['width'] = $saved_settings['canvas']['width'];
  }

  // If the object doesn't have a height set then assign one
  if (!isset($vars->params['height'])) {
    $vars->params['height'] = $saved_settings['canvas']['height'];
  }

  // Add the properties to the flowplayer array ready for rendering
  $flowplayer['canvas'] = $saved_settings['canvas'];
  $flowplayer['clip'] = $saved_settings['clip'];

  // Configure the control bar
  $flowplayer['plugins']['controls'] = $saved_settings['controls'];

  // Assign the control bar url if required
  if (variable_get('flowplayer3_mediaplayer_controls', '')) {
    $flowplayer['plugins']['controls']['url'] = variable_get('flowplayer3_mediaplayer_controls', '');
  }

  // If we are streaming this file, add the stream plugin
  if (isset($vars->othervars['stream'])) {

    // Define the clip provider as 'stream'
    $flowplayer['clip']['provider'] = 'stream';

    // Get the name of the stream plugin
    $flowplayer['plugins']['stream']['url'] = variable_get('flowplayer3_mediaplayer_stream_plugin', FLOWPLAYER3_MEDIAPLAYER_STREAM_PLUGIN);

    // Set the path to the source of the stream
    $flowplayer['plugins']['stream']['netConnectionUrl'] = $vars->othervars['stream'];
  }

  // Add product key if it has been set
  if (variable_get('flowplayer3_product_key', '')) {
    $flowplayer['key'] = variable_get('flowplayer3_product_key', '');
  }

  // Convert flowplayer array to JSON, and assign to a flashvar called config
  $flashvars['config'] = drupal_to_js($flowplayer);

  // Replace " with ', and remove quotes from around true and false, to satisfy FlowPlayer
  $flashvars['config'] = str_replace(array(
    '"',
    "'false'",
    "'true'",
    "'[",
    "]'",
  ), array(
    "'",
    "false",
    "true",
    "[",
    "]",
  ), $flashvars['config']);

  // The ' has been escaped, so reverse it where it occurs in the playlist (it gets escaped again later!)

  //$flashvars['config'] = str_replace(array("\'"), array("'"), $flashvars['config']);

  // Return the finished array of flash variables
  return $flashvars;
}