You are here

genericplayers.module in SWF Tools 5

Same filename and directory in other branches
  1. 6 genericplayers.module
  2. 6.2 genericplayers.module

File

genericplayers.module
View source
<?php

/**
 *
 * Support for generic Flash player for SWF Tools
 *
 * Please note: This module does not need to be installed (hence no .info file).
 * It is included automatically by swftools.module. It is uses the ".module" naming
 * syntax because it serves as a tutorial module for creating your own Flash Player integration
 * module.
 */

/**
 * Implementation of swftools_methods hook
 * Report methods back to SWF Tools
 */
define('GENERIC_FLV', 'generic_flv');

// Play an flv file
define('GENERIC_MP3', 'generic_mp3');

// Play an mp3.
function genericplayers_swftools_methods() {
  $methods = array();
  $mp3_player = array(
    'name' => GENERIC_MP3,
    'module' => 'genericplayers',
    'file' => 'file_url',
    // Define which flashvar to assign a 'file to play' variable.
    'shared_file' => 'generic/generic_mp3.swf',
    'title' => t('Generic MP3 Player'),
  );
  $methods[SWFTOOLS_MP3_DISPLAY][GENERIC_MP3] = $mp3_player;
  $flv_player = array(
    'name' => GENERIC_FLV,
    'module' => 'genericplayers',
    'file' => 'file_url',
    // Define which flashvar to assign a 'file to play' variable.
    'shared_file' => 'generic/generic_flv.swf',
    'title' => t('Generic FLV Player'),
  );
  $methods[SWFTOOLS_FLV_DISPLAY][GENERIC_FLV] = $flv_player;
  return $methods;
}

/**
 * Implementation of hook_menu(). Items such as access control is set by swftools automatically
 */
function genericplayers_menu($may_cache) {
  $items = array();
  if ($may_cache) {
    $items[] = array(
      'path' => 'admin/media/swf/generic',
      'title' => t('Generic Players'),
      'description' => t('Basic Flash players that ship with SWF Tools'),
      'weight' => -1,
    );
  }
  return $items;
}

/**
 * Implementation of swftools_admin_hook_form. Return the system settings page.
 */
function swftools_admin_generic_form() {
  $form = array();
  $methods = swftools_methods_available(SWFTOOLS_EMBED_METHOD);
  $form['generic_mp3_autostart'] = array(
    '#type' => 'checkbox',
    '#default_value' => variable_get('generic_mp3_autostart', FALSE),
    '#title' => t('Autostart MP3'),
    '#description' => t('Automatically start playing the MP3 file.'),
  );
  $form['generic_flv_autostart'] = array(
    '#type' => 'checkbox',
    '#default_value' => variable_get('generic_flv_autostart', FALSE),
    '#title' => t('Autostart FLV'),
    '#enabled' => FALSE,
    // Haven't built the FLV Player yet.
    '#description' => t('Automatically start playing FLV file.'),
  );
  return system_settings_form($form);
}

/**
 * Implementation of swftools_flashvars hook.
 *
 */
function genericplayers_swftools_flashvars($action, &$methods, &$vars) {

  // All we need to do is assign the 'file_url' variable to our preferred place on the flashvars array.
  if ($vars->othervars['file_url']) {
    $vars->flashvars['file_url'] = $vars->othervars['file_url'];
  }
  switch ($action) {
    case SWFTOOLS_MP3_DISPLAY:
      $vars->flashvars['autostart'] = isset($vars->flashvars['autostart']) ? $vars->flashvars['autostart'] : variable_get('generic_mp3_autostart', FALSE) ? 'true' : 'false';
      break;
    case SWFTOOLS_FLV_DISPLAY:
      $vars->flashvars['autostart'] = isset($vars->flashvars['autostart']) ? $vars->flashvars['autostart'] : variable_get('generic_flv_autostart', FALSE) ? 'true' : 'false';
      break;
  }
  return $vars->flashvars;
}

Functions

Namesort descending Description
genericplayers_menu Implementation of hook_menu(). Items such as access control is set by swftools automatically
genericplayers_swftools_flashvars Implementation of swftools_flashvars hook.
genericplayers_swftools_methods
swftools_admin_generic_form Implementation of swftools_admin_hook_form. Return the system settings page.

Constants

Namesort descending Description
GENERIC_FLV Implementation of swftools_methods hook Report methods back to SWF Tools
GENERIC_MP3