You are here

function videojs_hls_preprocess_videojs in Video.js (HTML5 Video Player) 7.3

Same name and namespace in other branches
  1. 7.2 modules/videojs_hls/videojs_hls.module \videojs_hls_preprocess_videojs()

Implements hook_preprocess_videojs().

File

modules/videojs_hls/videojs_hls.module, line 29
Provides bandwidth switching for the Video.js player.

Code

function videojs_hls_preprocess_videojs(&$vars) {
  $m3u8items = array();
  $singleitem = NULL;
  foreach ($vars['items'] as $k => $item) {
    if ($item['videotype'] != 'application/vnd.apple.mpegurl') {
      continue;
    }
    unset($vars['items'][$k]);
    $m3u8items[] = $item['uri'];
    $singleitem = $item;
  }

  // If there are no m3u8 files, return now.
  if (empty($m3u8items)) {
    return;
  }

  // If there is just one m3u8 item, don't create an alternates file.
  if (count($m3u8items) == 1) {
    $vars['items'][] = $singleitem;
    return;
  }
  if (variable_get('videojs_hls_delivery_type', 'dynamic') === 'dynamic') {
    $file = url('m3u8/' . rawurlencode(implode('|', $m3u8items)));
  }
  else {
    module_load_include('pages.inc', 'videojs_hls');
    $file = videojs_hls_create_static_file($m3u8items);
  }
  array_unshift($vars['items'], array(
    'uri' => $file,
    'videotype' => 'application/vnd.apple.mpegurl',
  ));
}