videojs.module in Video.js (HTML5 Video Player) 7
Same filename and directory in other branches
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.moduleView 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.
*/
/**
* Implements hook_menu().
*/
function videojs_menu() {
$items = array();
$items['admin/config/media/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;
}
/**
* Implements hook_theme().
*/
function videojs_theme() {
return array(
'videojs' => array(
'variables' => array(
'items' => NULL,
'player_id' => NULL,
'attributes' => NULL,
),
'template' => 'theme/videojs',
'file' => 'includes/videojs.theme.inc',
),
'videojs_view' => array(
'variables' => array(
'items' => NULL,
'player_id' => NULL,
'attributes' => NULL,
),
'template' => 'theme/videojs',
'file' => 'includes/videojs.theme.inc',
),
);
}
/**
* Implements hook_views_api().
*/
function videojs_views_api() {
return array(
'api' => 2,
'path' => drupal_get_path('module', 'videojs') . '/includes',
);
}
/**
* Implements hook_field_formatter_info().
*/
function videojs_field_formatter_info() {
return array(
'videojs' => array(
'label' => t('Video.js : HTML5 Video Player'),
'field types' => array(
'file',
'video',
'media',
),
'description' => t('Display a video file as an HTML5-compatible with Flash-fallback video player.'),
),
);
}
/**
* Implements hook_field_formatter_view().
*/
function videojs_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
if ($display['type'] != 'videojs') {
return array();
}
list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);
return array(
array(
'#theme' => 'videojs',
'#items' => $items,
'#player_id' => 'videojs-' . $id . '-' . str_replace('_', '-', $instance['field_name']),
'#attached' => videojs_add(FALSE),
),
);
}
/**
* Add the Video.js library to the page.
*
* @param $add
* By default this function will add videojs 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) {
static $added = FALSE;
$directory = variable_get('videojs_directory', 'sites/all/libraries/video-js');
$return = FALSE;
if (file_exists($directory . '/video.js')) {
$filepath = $directory . '/video.js';
$filepath_css = $directory . '/video-js.css';
}
if (isset($filepath)) {
$videojs_js = drupal_get_path('module', 'videojs') . '/theme/videojs.js';
$videojs_css = drupal_get_path('module', 'videojs') . '/theme/videojs.css';
$settings = array(
'videojs' => array(
'autoPlay' => (int) variable_get('videojs_autoplay', ''),
),
);
if ($add) {
drupal_add_js($filepath, array(
'group' => JS_LIBRARY,
));
drupal_add_css($filepath_css);
drupal_add_js($videojs_js, array(
'group' => JS_DEFAULT,
));
drupal_add_css($videojs_css);
if (!$added) {
drupal_add_js($settings, array(
'type' => 'setting',
));
$added = TRUE;
}
}
$return = array(
'js' => array(
$filepath => array(
'group' => JS_LIBRARY,
),
$videojs_js => array(
'group' => JS_DEFAULT,
),
array(
'data' => $settings,
'type' => 'setting',
),
),
'css' => array(
$filepath_css,
$videojs_css,
$directory . '/skins/hu.css',
$directory . '/skins/tube.css',
$directory . '/skins/vim.css',
),
);
}
return $return;
}
/**
* 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 = variable_get('videojs_directory', 'sites/all/libraries/video-js');
}
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
Name | Description |
---|---|
videojs_add | Add the Video.js library to the page. |
videojs_field_formatter_info | Implements hook_field_formatter_info(). |
videojs_field_formatter_view | Implements hook_field_formatter_view(). |
videojs_get_version | Return the version of Video.js installed. |
videojs_menu | Implements hook_menu(). |
videojs_theme | Implements hook_theme(). |
videojs_views_api | Implements hook_views_api(). |