Currently the implemented theme functions to get the player out are hard to re-use in other cases other than a pure cck field.

Also, the dimensions of the player is hardcoded into theme_brightcove_cck_embed, which makes it almost allways needed to override it on template.php or create a new formatter duplicating functionality.

Part of these functions should be abstracted into utility functions.

Please do chip in so that we get a clear path as to how to make this module enter the next stage.

Related issues:
#1388264: Input filter for embedding videos [PATCH]
#1411458: [PATCH] Ability to configure different players

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Manuel Garcia’s picture

I will be spending the day working on this.

Join the fun in #drupal-brightcove IRC channel.

I propose we move towards a function like brightcove_embed_video($vid, $width, $height, $playerID);, which would return an html string with the absolute necessary markup for printing the video player.

Having the function take width, height, and PlayerID as parameters would give us the flexibility for implementing different players & dimensions in the future, which could be added to the field settings in a latter step. For now the function will grab the defaults if none are specified while calling the function from the standard formatter. It also means that if you call it manualy by code you could have different players etc already.

I propose we move adding <script type="text/javascript" src="http://admin.brightcove.com/js/BrightcoveExperiences.js"></script> into a hook_init() implementation. So that we can use this function within imput filters, and avoid having to worry if there's more than one video on the page, etc.

Please share your thoughts on this or other ideas you have in mind. Let's first make the module's code flexible enough then implement form elements for configuring stuf through the UI.

Manuel Garcia’s picture

Proposed funciton WIP:

/**
 * Returns a ready to print video player for the specified paramatters
 *
 * @param bgcolor
 *  Color code, defaults to transparent, #FFFFFF for white for example
 * @param width
 *   The player's width in pixels (do not prefix with px)
 * @param height
 *   The player's height in pixels (do not prefix with px)
 */
function brightcove_embed_video($type, $width, $height, $bgcolor, $playerId, $playerKey, $assetIds) {
  // Get the default player data if none are passed as arguments
  $playerId = isset($playerId) ? $playerId : variable_get('brightcove_player', '');
  $playerKey = isset($playerKey) ? $playerKey : variable_get('brightcove_player_key', '');
  if (empty($playerId)) {
    drupal_set_message('No brightcove player configured', 'error');
  }
  if (empty($playerKey)) {
    drupal_set_message('No brightcove player key configured', 'error');
  }

  $width = isset($width) ? $width : variable_get('brightcove_cck_default_video_width', BRIGHTCOVE_DEFAULT_VIDEO_WIDTH);
  $height = isset($height) ? $height : variable_get('brightcove_cck_default_video_height', BRIGHTCOVE_DEFAULT_VIDEO_HEIGHT);
  $bgcolor = isset($bgcolor) ? $bgcolor : 'transparent';
  $id = 'myExperience';


  $assetCode = '';

  if(isset($assetIds)) {
    if(is_array($assetIds)) {
      if(strtolower($type) == 'video') {
        $assetCode = '<param name="@videoPlayer" value="';
      } else {
        // TODO: Add different types than video.
      }

      foreach($assetIds as $assetId) {
        $assetCode .= $assetId . ',';
      }

      $assetCode = substr($assetCode, 0, -1);
      $assetCode .= '" />';
    } else {
      if(strtolower($type) == 'video') {
        $assetCode = '<param name="@videoPlayer" value="' . $assetIds . '" />';
      } else {
        // TODO: Add different types than video.
      }
    }
  }

  $code = '
    <object id="'. $id .'" class="BrightcoveExperience">
    <param name="bgcolor" value="'. $bgcolor .'" />
    <param name="width" value="'. $width .'" />
    <param name="height" value="'. $height .'" />
    <param name="playerID" value="'. $playerId .'" />'
    . $assetCode .'
    <param name="isVid" value="true" />
    <param name="isUI" value="true" />
    <param name="playerKey" value="'. $playerKey .'" />
    </object>';

  return $code;
}
Manuel Garcia’s picture

Status: Active » Needs review
FileSize
13.33 KB

OK, here's a first working patch.

Includes Major refactoring of player embedding process:

  1. Moved drupal_set_html_head('<script type="text/javascript" src="http://admin.brightcove.com/js/BrightcoveExperiences.js"></script>'); into brightcove_init().
  2. Killed theme_brightcove_cck_embed() function in favour of new brightcove_embed_video() function. This new function lives inside brightcove.module so that you don't need to use brightcove_cck if you don't want to (for example, if you only use an input filter). It includes functionality that was being done in different places for default configurations.
  3. Adjusted all calls to theme_brightcove_cck_embed to use the new function and removed leftover unnecessary code.
  4. theme_brightcove_cck_lightbox2_player and theme_brightcove_cck_formatter_default now use the widget settings for dimensions instead of the ugly hack.

Please do test and review. I've tested it on a local d6 site and seems to work fine.

Manuel Garcia’s picture

Here is a better version of the above patch.

Here is how the function is looking:

/**
 * Returns a ready to print video player for the specified paramatters.
 *
 * @param string $type
 *   The type of player to use.
 *   defaults to 'video'
 *    Can be 'video_list', 'playlist_tabs' or 'playlist_combo'.
 * @param $assetIds
 *   Can be either string with one video/playlist ID
 *   or an array of videos/playlists IDs. Each player type expects
 *   different values. See Brightove documentation
 *   http://support.brightcove.com/en/docs/assigning-content-players-programmatically#JS
 * @param playerId
 *   The Brightcove's player's ID. Defaults to site's default.
 * @param playerKey
 *   The Brightcove's player's KEY. Defaults to site's default.
 * @param $id
 *   String used to give the <object>'s id
 * @param width
 *   The player's width in pixels (do not prefix with px).
 * @param height
 *   The player's height in pixels (do not prefix with px).
 *  @param bgcolor
 *   Color hex code without hash, defaults to FFFFFF
 */
function brightcove_embed_video($type = 'video', $assetIds = '', $playerId = '', $playerKey = '', $id = '', $width = '', $height = '', $bgcolor = 'FFFFFF') {
  $output = '';
  // Return if no assets were passed in.
  if(empty($assetIds)) {
    return $output;
  }
  // Get the default player data if none are passed as arguments.
  $playerId = !empty($playerId) ? $playerId : variable_get('brightcove_player', '');
  $playerKey = !empty($playerKey) ? $playerKey : variable_get('brightcove_player_key', '');

  // If we don't have the necessary player info, return and set error.
  if (empty($playerId)) {
    drupal_set_message('No brightcove player configured', 'error');
    return $output;
 }
  if (empty($playerKey)) {
    drupal_set_message('No brightcove player key configured', 'error');
    return $output;
  }

  // Setup the params.
  $width = !empty($width) ? $width : 595;
  $height = !empty($height) ? $height : 380;
  $id = empty($id) ? 'myExperience' : $id;

  // Process the asssets passed in.
  $asset_values = is_array($assetIds) ? implode(',', $assetIds) : $assetIds;

  // Setup video type param name.
  $player_type = '';
  switch (strtolower($type)) {
    case 'video':
      $player_type = "@videoPlayer";
      break;
    case 'video_list':
      $player_type = "@videoList";
      break;
    case 'playlist_tabs':
      $player_type = "@playlistTabs";
      break;
    case 'playlist_combo':
      $player_type = "@playlistCombo";
      break;
  }

  // Prepare the html with the processed information.
  $output .= '
    <object id="'. $id .'" class="BrightcoveExperience">
      <param name="bgcolor" value="#'. $bgcolor .'" />
      <param name="width" value="'. $width .'" />
      <param name="height" value="'. $height .'" />
      <param name="playerID" value="'. $playerId .'" />
      <param name="'. $player_type .'"  value="'. $asset_values .'" />
      <param name="isVid" value="true" />
      <param name="isUI" value="true" />
      <param name="playerKey" value="'. $playerKey .'" />
    </object>';

  return $output;
}
Manuel Garcia’s picture

Last patch actualy was a bit broken.

This one actualy calls the new function correctly. Please test and review =)

Bill Choy’s picture

The player_type should be added to the player settings form (where you specify the id/key). A player can only handle one of these parameters at a time. So you can never assign the wrong parameter to the player. And then the code become very clean.

function theme_brightcove_field_embed($variables) {
  if (!isset($variables['player'])) {
    watchdog('brightcove', 'Video Player is missing.', array(), WATCHDOG_ERROR);
  }

  $player = brightcove_player_load($variables['player']);

  $values = array(
    'id' => 'myExperience', // should use a sric
    'bgcolor' => 'FFFFFF',
    'width' => $variables['width'],
    'height' => $variables['height'],
  );

  foreach ($values as $key => $value) {
    if (isset($variables['params'][$key])) {
      $values[$key] = $variables['params'][$key];
    }
  }

  $asset_code = '';
  if (isset($variables['video_id'])) {
    $brightcove_id = is_array($variables['video_id']) ? implode(',', $variables['video_id']) :  $variables['video_id'] ;
    // "@videoPlayer" -- for single video player.
    // "@videoList" -- for players with a List or TabList component.
    // "@playlistCombo" -- for players with combo box (dropdown) playlist selection.
    // "@playlistTabs" -- for players with tabbed playlist selection.
    $asset_code = '<param name="@'. $player->player_type.'" value="'. $brightcove_id .'" />';
  }

  $code = '
    <object id="' . $values['id'] . '" class="BrightcoveExperience">
    <param name="bgcolor" value="#' . $values['bgcolor'] . '" />
    <param name="width" value="' . $values['width'] . '" />
    <param name="height" value="' . $values['height'] . '" />
    <param name="playerID" value="' . $player->player_id . '" />
    <param name="playerKey" value="' . $player->player_key . '" />'
    . $asset_code . '
    <param name="isVid" value="true" />
    <param name="isUI" value="true" />
    </object>';

  return $code;
}
theunraveler’s picture

I would suggest marking this as a duplicate of #1990214: Playlists, which covers embedding playlists and includes support for the different embed parameters.

theunraveler’s picture

Issue summary: View changes

Updated issue summary.

k.dani’s picture

Issue summary: View changes
Status: Needs review » Postponed

We are working on the 7.x version of the module, but as soon as we have chance to check it, we review it.

k.dani’s picture

Status: Postponed » Needs review
k.dani’s picture

We don’t maintain the Drupal 6 version of the module, but apply patches (if it is in RTBC status) until the stable version of Drupal 8 is released.

jan.mashat’s picture

Status: Needs review » Closed (won't fix)