From 0ce24fea04b8b571ef887d184a7f8cdeca2d4c4a Mon Sep 17 00:00:00 2001 From: Heshan Date: Wed, 6 Apr 2011 21:47:46 +0530 Subject: #1092668 by anglo VideoJS player --- includes/conversion.inc | 7 ++- includes/video_helper.inc | 5 ++ js/video.js | 13 ++++- modules/video_ui/video.admin.inc | 15 ++++- transcoders/video_ffmpeg.inc | 1 + video.field.inc | 4 +- video.module | 35 +++++++++++- video.theme.inc | 118 +++++++++++++++++++++++++-------------- 8 files changed, 148 insertions(+), 50 deletions(-) diff --git a/includes/conversion.inc b/includes/conversion.inc index c7596e9..f35984e 100644 --- a/includes/conversion.inc +++ b/includes/conversion.inc @@ -66,7 +66,11 @@ class video_conversion { if ($video->video_status == VIDEO_RENDERING_PENDING) { return $this->transcoder->convert_video($video); } else { - $status = array(VIDEO_RENDERING_COMPLETE => 'completed', VIDEO_RENDERING_FAILED => 'failed'); + $status = array( + VIDEO_RENDERING_INQUEUE => 'in queue', + VIDEO_RENDERING_COMPLETE => 'completed', + VIDEO_RENDERING_FAILED => 'failed' + ); watchdog('transcoder', 'Video conversion has been !status. You should add video to the queue. Please check the re-queue to enable the video conversion.', array('!status' => $status[$video->video_status]), WATCHDOG_WARNING); return FALSE; @@ -105,6 +109,7 @@ class video_conversion { public function load_job($fid) { return $this->transcoder->load_job($fid); } + } ?> \ No newline at end of file diff --git a/includes/video_helper.inc b/includes/video_helper.inc index dfbb29f..41a8293 100644 --- a/includes/video_helper.inc +++ b/includes/video_helper.inc @@ -40,6 +40,7 @@ class video_helper { $video->files->{$extension}->filename = pathinfo($variables['item']['filename'], PATHINFO_FILENAME) . '.' . $extension; $video->files->{$extension}->filepath = $variables['item']['uri']; $video->files->{$extension}->url = file_create_url($variables['item']['uri']); + $video->files->{$extension}->uri = $variables['item']['uri']; $video->files->{$extension}->extension = $extension; // set the player to play $video->player = $extension; @@ -97,6 +98,10 @@ class video_helper { } $thumbnail->url = file_create_url($thumbnail->filepath); + // uri + $thumbnail->uri = $thumbnail->filepath; + //mime + $thumbnail->filemime = file_get_mimetype($thumbnail->filepath); //swftools appends sites/default/files to the front of our path... //@todo Is this a setting? Need to figure this out. diff --git a/js/video.js b/js/video.js index fc2fa7f..7a98507 100644 --- a/js/video.js +++ b/js/video.js @@ -31,10 +31,19 @@ } else { $('#flv_player_'+ext).hide(); } + if($(this).val() == 'video_play_html5') { + $('#html5_player_'+ext).show(); + } else { + $('#html5_player_'+ext).hide(); + } }); - if($('select', this).val() == 'video_play_flv') { + if($('select', this).val() == 'video_play_flv') $('#flv_player_'+ext).show(); - } + + if($('select', this).val() == 'video_play_html5') + $('#html5_player_'+ext).show(); + else + $('#html5_player_'+ext).hide(); }); if(settings.video) { diff --git a/modules/video_ui/video.admin.inc b/modules/video_ui/video.admin.inc index ed76a20..2f1c94b 100644 --- a/modules/video_ui/video.admin.inc +++ b/modules/video_ui/video.admin.inc @@ -101,6 +101,7 @@ function video_players_admin_settings() { $extensions = video_video_extensions(); $players = video_video_players(); $flv_players = video_video_flv_players(); + $html5_players = video_video_html5_players(); foreach ($extensions as $ext => $player) { $form['extensions']['video_extension_' . $ext] = array( @@ -111,7 +112,7 @@ function video_players_admin_settings() { '#prefix' => '
', '#suffix' => '
', ); - + // For flash if (!empty($flv_players)) { $form['extensions']['video_extension_' . $ext . '_flash_player'] = array( '#type' => 'radios', @@ -129,6 +130,18 @@ function video_players_admin_settings() { '#suffix' => '', ); } + // for HTML5 + if (!empty($html5_players)) { + $form['extensions']['video_extension_' . $ext . '_html5_player'] = array( + '#type' => 'radios', + '#title' => t('HTML5 Player for') . ' ' . $ext, + '#options' => $html5_players, + '#markup' => t('Additional HTML5 players module.
You can install !VideoJS.', array('!VideoJS' => l(t('Video JS'), 'http://www.drupal.org/project/videojs'))), + '#default_value' => variable_get('video_extension_' . $ext . '_html5_player', ''), + '#prefix' => '
', + '#suffix' => '
', + ); + } } return system_settings_form($form); } diff --git a/transcoders/video_ffmpeg.inc b/transcoders/video_ffmpeg.inc index e5f8c63..833b6c6 100644 --- a/transcoders/video_ffmpeg.inc +++ b/transcoders/video_ffmpeg.inc @@ -508,6 +508,7 @@ class video_ffmpeg implements transcoder_interface { $video->files->{$extension}->filepath = $value->uri; $video->files->{$extension}->filemime = file_get_mimetype($value->uri); $video->files->{$extension}->url = file_create_url($value->uri); + $video->files->{$extension}->uri = $value->uri; $video->files->{$extension}->extension = $extension; $video->player = strtolower($extension); } diff --git a/video.field.inc b/video.field.inc index 21ea62f..6a3a53d 100644 --- a/video.field.inc +++ b/video.field.inc @@ -24,8 +24,8 @@ function video_field_info() { 'file_extensions' => 'mp4 ogg avi mov wmv flv ogv webm', 'file_directory' => 'videos/original', 'max_filesize' => '', - 'default_dimensions' => '640x350', - 'default_player_dimensions' => '640x350' + 'default_dimensions' => '640x360', + 'default_player_dimensions' => '640x360' ), 'default_widget' => 'video_upload', 'default_formatter' => 'video', diff --git a/video.module b/video.module index 5a6c5a2..8b344c4 100644 --- a/video.module +++ b/video.module @@ -102,6 +102,10 @@ function video_theme() { 'variables' => array('video' => NULL), 'file' => 'video.theme.inc' ); + $theme['video_html5'] = array( + 'variables' => array('video' => NULL), + 'file' => 'video.theme.inc' + ); return $theme; } @@ -524,6 +528,21 @@ function video_video_flv_players() { return $options; } +/* + * Return our possible flash players. + */ + +function video_video_html5_players() { + $options = array(); + if (module_exists('videojs')) { + $options['videojs'] = t('VideoJS'); + } + if (module_exists('video')) { + $options['video'] = t('Default HTML5'); + } + return $options; +} + /** * Field instances settings * @param $widget @@ -629,7 +648,7 @@ function video_format_right($value) { */ function video_default_dimensions() { - return "176x144\n352x288\n704x576\n1408x1152\n128x96\n160x120\n320x240\n640x480\n800x600\n1024x768\n1600x1200\n2048x1024\n1280x1024\n2560x2048\n5120x4096\n852x480\n1366x768\n1600x1024\n1920x1200\n2560x1600\n3200x2048\n3840x2400\n6400x4096\n7680x4800\n320x200\n640x350\n852x480\n1280x720\n1920x1080"; + return "176x144\n352x288\n704x576\n1408x1152\n128x96\n160x120\n320x240\n640x480\n800x600\n1024x768\n1600x1200\n2048x1024\n1280x1024\n2560x2048\n5120x4096\n852x480\n1366x768\n1600x1024\n1920x1200\n2560x1600\n3200x2048\n3840x2400\n6400x4096\n7680x4800\n320x200\n640x350\n852x480\n1280x720\n1920x1080\n640x360\n320x180"; } /* @@ -657,4 +676,18 @@ function video_features_api() { 'file' => drupal_get_path('module', 'video') . '/video.features.inc', ), ); +} + +/** + * Helper funcations + */ +function _video_object_to_array($data) { + if (is_array($data) || is_object($data)) { + $result = array(); + foreach ($data as $key => $value) { + $result[$key] = _video_object_to_array($value); + } + return $result; + } + return $data; } \ No newline at end of file diff --git a/video.theme.inc b/video.theme.inc index 41ab5e0..c5b1d7e 100644 --- a/video.theme.inc +++ b/video.theme.inc @@ -62,11 +62,17 @@ function theme_video($variables) { $defaults = video_video_extensions(); $theme_function = variable_get('video_extension_' . $video->player, $defaults[$video->player]); - // Lets do some special handling for our flv files to accomdate multiple players. - if ($theme_function == 'video_play_flv') { - return theme('video_flv', array('video' => $video, 'themed_output' => $themed_output)); - } else { - return theme($theme_function, array('video' => $video, 'themed_output' => $themed_output)); + // Lets do some special handling for our flv files, HTML5 to accomdate multiple players. + switch ($theme_function) { + case 'video_play_flv': + return theme('video_flv', array('video' => $video, 'themed_output' => $themed_output)); + break; + case 'video_play_html5': + return theme('video_html5', array('video' => $video, 'themed_output' => $themed_output)); + break; + default: + return theme($theme_function, array('video' => $video, 'themed_output' => $themed_output)); + break; } } @@ -75,16 +81,16 @@ function theme_video($variables) { */ function theme_video_thumbnail($variables) { - // Inside a view $variables may contain null data. In that case, just return. +// Inside a view $variables may contain null data. In that case, just return. if (empty($variables['item']['fid'])) return ''; - //setup our thumbnail object +//setup our thumbnail object module_load_include('inc', 'video', '/includes/video_helper'); $video_helper = new video_helper; - // @TODO : change the object to an array +// @TODO : change the object to an array $thumbnail = (array) $video_helper->thumbnail_object($variables); - // return if no file path found for the video thumbnails and add log message +// return if no file path found for the video thumbnails and add log message if (empty($thumbnail['filepath'])) { watchdog('video', 'Unable to find the video thumbnail for the %node.', array('%node' => $variables['entity']->title), WATCHDOG_ERROR); return ''; @@ -93,7 +99,7 @@ function theme_video_thumbnail($variables) { 'path' => $thumbnail['filepath'], 'alt' => $thumbnail['alt'], ); - // Do not output an empty 'title' attribute. +// Do not output an empty 'title' attribute. if (drupal_strlen($thumbnail['title']) > 0) { $image['title'] = $thumbnail['title']; } @@ -138,9 +144,9 @@ function theme_video_thumb_style($variables) { $style_name = $variables['style_name']; $path = $variables['path']; - // theme_image() can only honor the $getsize parameter with local file paths. - // The derivative image is not created until it has been requested so the file - // may not yet exist, in this case we just fallback to the URL. +// theme_image() can only honor the $getsize parameter with local file paths. +// The derivative image is not created until it has been requested so the file +// may not yet exist, in this case we just fallback to the URL. $style_path = image_style_path($style_name, $path); if (!file_exists($style_path)) { $style_path = image_style_url($style_name, $path); @@ -169,40 +175,66 @@ function theme_video_conversion_failed() { function theme_video_flv($variables) { $video = $variables['video']; - // set the video flash player - // Moved to last to recheck incase we changed our extension above. +// set the video flash player +// Moved to last to recheck incase we changed our extension above. $video->flash_player = variable_get('video_extension_' . $video->player . '_flash_player', ''); - if ($video->flash_player == 'swftools') { - $options = array( - 'params' => array( - 'width' => $video->player_width, - 'height' => $video->player_height, - ), - 'othervars' => array( - //@todo: swftools bug, can't enable this until they fix their pathing for the images. - 'image' => $video->thumbnail->swfthumb, - ), - ); - $themed_output = swf($video->files->{$video->player}->url, $options); - } elseif ($video->flash_player == 'flowplayer') { - // kjh: use a playlist to display the thumbnail if not auto playing - if (isset($video->autoplay) && isset($video->thumbnail->url)) { + switch ($video->flash_player) { + case 'swftools': $options = array( - 'playlist' => array($video->thumbnail->url, - array('url' => urlencode($video->files->{$video->player}->url), + 'params' => array( + 'width' => $video->player_width, + 'height' => $video->player_height, + ), + 'othervars' => array( + //@todo: swftools bug, can't enable this until they fix their pathing for the images. + 'image' => $video->thumbnail->swfthumb, + ), + ); + $themed_output = swf($video->files->{$video->player}->url, $options); + break; + case 'flowplayer': + // kjh: use a playlist to display the thumbnail if not auto playing + if (isset($video->autoplay) && isset($video->thumbnail->url)) { + $options = array( + 'playlist' => array($video->thumbnail->url, + array('url' => urlencode($video->files->{$video->player}->url), + 'autoPlay' => $video->autoplay, + 'autoBuffering' => $video->autobuffering, + ),),); + } else { + $options = array( + 'clip' => array('url' => urlencode($video->files->{$video->player}->url), 'autoPlay' => $video->autoplay, 'autoBuffering' => $video->autobuffering, - ),),); - } else { - $options = array( - 'clip' => array('url' => urlencode($video->files->{$video->player}->url), - 'autoPlay' => $video->autoplay, - 'autoBuffering' => $video->autobuffering, - ),); - } - $themed_output = theme('flowplayer', array('config' => $options, 'id' => 'flowplayer-' . $video->formatter, 'attributes' => array('style' => 'width:' . $video->player_width . 'px;height:' . ($video->player_height + 24) . 'px;'))); - } else { - $themed_output = t('No flash player has been setup. ' . l(t('Please select a player to play Flash videos.'), 'admin/settings/video/players')); + ),); + } + $themed_output = theme('flowplayer', array('config' => $options, 'id' => 'flowplayer-' . $video->formatter, 'attributes' => array('style' => 'width:' . $video->player_width . 'px;height:' . ($video->player_height + 24) . 'px;'))); + break; + default: + $themed_output = t('No flash player has been setup. ' . l(t('Please select a player to play Flash videos.'), 'admin/settings/video/players')); + break; } return theme('video_play_flv', array('video' => $video, 'themed_output' => $themed_output)); +} + +/** + * Theme wrapper for HTML5 + */ +function theme_video_html5($variables) { + $themed_output = NULL; + $video = $variables['video']; + echo $video->html5_player = variable_get('video_extension_' . $video->player . '_html5_player', ''); + switch ($video->html5_player) { + case 'video': + return theme('video_play_html5', array('video' => $video, 'themed_output' => $themed_output)); + break; + case 'videojs': + $items = _video_object_to_array($video->files); + $items +=array('thumbnail' => (array) $video->thumbnail); + $attributes = array(); + $attributes['width'] = $video->width; + $attributes['height'] = $video->height; + return theme('videojs', array('items' => $items, 'player_id' => 'video-' . $video->fid, 'attributes' => $attributes)); + break; + } } \ No newline at end of file -- cgit v1.2.3