The National Library of Medicine, as a U.S. Government agency, must make videos as accessible as possible. To that end, I integrated it, but I'm not using the Video module which does conversion because I haven't had time in my prototype to make it work, nor to train the web contributors to do video conversion.
I made the rendering sensitive to a "field_video_transcript" field, which probably is not a good patch, because it sort of presumes on a feature of the Video module that may or may not be present. With the "transcript" tag then in the formatting, it can also be manipulated through my template, although in this case I didn't need to do so.
Patch inline:
diff --git a/sites/all/modules/contrib/jw_player/jw_player.module b/sites/all/modules/contrib/jw_player/jw_player.module
index 4ccfb94..4143942 100644
--- a/sites/all/modules/contrib/jw_player/jw_player.module
+++ b/sites/all/modules/contrib/jw_player/jw_player.module
@@ -48,6 +48,7 @@ function jw_player_theme() {
'playlist' => NULL,
'preset' => '',
'image' => '',
+ 'transcript' => '',
'html_id' => NULL,
'options' => array(),
'playlist_size' => JW_PLAYER_DEFAULT_PLAYLIST_SIZE,
@@ -273,7 +274,9 @@ function jw_player_field_formatter_view($entity_type, $entity, $field, $instance
if ($images = field_get_items($entity_type, $entity, 'field_video_thumbnail')) {
$element['#image'] = $images[0];
}
-
+ if ($transcripts = field_get_items($entity_type, $entity, 'field_video_transcript')) {
+ $element['#transcript'] = $transcripts[0];
+ }
}
return $element;
}
@@ -421,6 +424,9 @@ function template_preprocess_jw_player(&$variables) {
if (isset($variables['sources'])) {
$variables['config']['playlist'][0] = array();
$variables['config']['playlist'][0]['image'] = file_create_url($variables['image']['uri']);
+ if (isset($variables['transcript'])) {
+ $variables['config']['playlist'][0]['tracks'][] = array('file'=>file_create_url($variables['transcript']['uri']));
+ }
foreach ($variables['sources'] as $key => $source) {
$variables['config']['playlist'][0]['sources'][$key]['file'] = file_create_url($source['uri']);
if (isset($source['getid3']) && $source['getid3']['width'] > 0 && $source['getid3']['height'] > 0) {I'll follow up to see whether there is any related work in the Video module, and let them know I want this feature. There's probably a way to do it that doesn't interact quite so much with the Video module.
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | jw_player-closed_captions.png | 320.02 KB | sgdev |
Comments
Comment #1
danizen commentedThere is a transcript issue for the Video module that adds a new field to the database and a column to the database. Usually, these transcripts appear to me as VTT files, and so for me, it would be better if the transcript were a file entity reference.
Comment #2
sgdev commentedI'd like to see support added for this too, however there is an option that can allow you to include this in your code right now.
We have refactored the 7.x-2.x theming, and there is now a
hook_jw_player_build_playerfunction available. This will allow you to intercept the$optionsarray prior to rendering by JW Player, and add any extra options not currently supported by the module.As long as the format of the array matches the format needed by JW Player, this should definitely work.
Check it out... you'll probably need both of these patches to have it work correctly. I'd appreciate any feedback you might have!
* Refactor theming: https://www.drupal.org/node/2713725
* Add preset sources, sharing, mute and validation: https://www.drupal.org/node/2713701
Comment #3
sgdev commentedAlso regarding this comment, yes this is not the best approach. The right way to do this would be similar to what is now being done for adding a preview image. Need to expose all available text fields in a select menu, and allow for one to be added as an associated transcript field.
It also needs to support unlimited text fields to be matched against multi-file playlists.
Comment #4
sgdev commentedWe have created functionality in support of closed captioning for 7.x-2.x. It has a lot of similarities to the work done to add preview images to field formatters.
One key feature we have included is the ability to select a "caption type". Two options currently exist: Language and Transcript.
Language attaches multiple caption files to a playlist file, allowing for multiple languages on a single video (English, Spanish, French, etc.). Transcript attaches one caption file to one playlist file, allowing for a full captioning transcript of a multi-video playlist. More advanced options can be constructed through the API or by using the hook we have in the Refactor theming patch.
We need to get some of the other outstanding patches committed before we can post a patch for this, but we have the feature working locally.
Comment #5
acranius commentedAny news on this?
I'm currently trying to find a solution which uses the "preview image" approach.
Comment #6
sgdev commentedSee: https://www.drupal.org/node/2713725#comment-12182348