You are here

videojs.module in Video.js (HTML5 Video Player) 6.2

Provides an HTML5-compatible with Flash-fallback video player.

This module provides functionality for loading the Video.js library and formatters for CCK FileFields.

File

videojs.module
View source
<?php

/**
 * @file
 * Provides an HTML5-compatible with Flash-fallback video player.
 *
 * This module provides functionality for loading the Video.js library and
 * formatters for CCK FileFields.
 */

/**
 * Implementation of hook_menu().
 */
function videojs_menu() {
  $items = array();
  $items['admin/settings/videojs'] = array(
    'title' => 'Video.js',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'videojs_settings_form',
    ),
    'access arguments' => array(
      'administer site configuration',
    ),
    'description' => 'Configure the settings for the Video.js module.',
    'file' => 'includes/videojs.admin.inc',
  );
  return $items;
}

/**
 * Implementation of hook_theme().
 */
function videojs_theme() {
  return array(
    'videojs_formatter_videojs' => array(
      'arguments' => array(
        'element' => NULL,
      ),
      'template' => 'theme/videojs',
      'file' => 'includes/videojs.theme.inc',
    ),
    'videojs_view' => array(
      'arguments' => array(
        'view' => NULL,
        'items' => NULL,
      ),
      'template' => 'theme/videojs',
      'file' => 'includes/videojs.theme.inc',
    ),
    'videojs' => array(
      'arguments' => array(
        'items' => NULL,
        'player_id' => NULL,
        'attributes' => NULL,
      ),
      'template' => 'theme/videojs',
      'file' => 'includes/videojs.theme.inc',
    ),
  );
}

/**
 * Implementation of Views' hook_views_api().
 */
function videojs_views_api() {
  return array(
    'api' => 2,
    'path' => drupal_get_path('module', 'videojs') . '/includes',
  );
}

/**
 * Implementation of CCK's hook_field_formatter_info().
 */
function videojs_field_formatter_info() {
  return array(
    'videojs' => array(
      'label' => t('Video.js : HTML5 Video Player'),
      'field types' => array(
        'filefield',
        'uploadfield',
        'link',
      ),
      'multiple values' => CONTENT_HANDLE_MODULE,
      'description' => t('Display a video file as an HTML5-compatible with Flash-fallback video player.'),
    ),
  );
}

/**
 * Get the path to the video.js external library.
 *
 * @return
 *   The path to the directory where video.js library is located.
 */
function videojs_get_path() {

  // Default directory path.
  $directory = 'sites/all/libraries/video-js';

  // Libraries API integration - In case VideoJS library is in multiple
  // locations (profiles/{profile_name}/libraries, sites/all/libraries,
  // sites{site_name}/libraries ) Libraries API can determine which copy should
  // take presidence...
  if (module_exists('libraries') && ($libraries_dir = libraries_get_path('video-js'))) {
    if (file_exists($libraries_dir . '/video.js')) {
      $directory = $libraries_dir;
    }
  }

  // ...However, we also give the user the opportunity to override the path.
  if ($conf_dir = variable_get('videojs_directory', NULL)) {
    if (file_exists($conf_dir . '/video.js')) {
      $directory = $conf_dir;
    }
  }
  return $directory;
}

/**
 * Add the Video.js library to the page.
 *
 * @param $add
 *   By default this function will add Video.js to the page JavaScript array
 *   directly. If wanting to store the Video.js file as an #attached property,
 *   set this to FALSE and videojs_add() will only return the needed array
 *   suitable for use as an #attached property.
 */
function videojs_add($add = TRUE) {
  $directory = videojs_get_path();
  if (!file_exists($directory . '/video.min.js')) {
    return FALSE;
  }
  $libjs = $directory . '/video.min.js';
  $libcss = $directory . '/video-js.min.css';
  if ($add) {
    drupal_add_js($libjs);
    drupal_add_css($libcss);
  }
  return array(
    'js' => array(
      array(
        'data' => $libjs,
      ),
    ),
    'css' => array(
      array(
        'data' => $libcss,
      ),
    ),
  );
}

/**
 * Return the version of Video.js installed.
 *
 * @param $directory
 *   The directory to check for a Video.js installation.
 */
function videojs_get_version($directory = NULL) {
  $version = NULL;
  if (!isset($directory)) {
    $directory = videojs_get_path();
  }
  if (!file_exists($directory . '/video.js')) {
    return NULL;
  }
  $contents = file_get_contents($directory . '/video.js');
  $matches = array();
  if (preg_match('/(?:v[ ]*|Version )([\\d.]+)/i', $contents, $matches)) {
    $version = $matches[1];
  }
  return $version;
}

Functions

Namesort descending Description
videojs_add Add the Video.js library to the page.
videojs_field_formatter_info Implementation of CCK's hook_field_formatter_info().
videojs_get_path Get the path to the video.js external library.
videojs_get_version Return the version of Video.js installed.
videojs_menu Implementation of hook_menu().
videojs_theme Implementation of hook_theme().
videojs_views_api Implementation of Views' hook_views_api().