I have a use case where I have multiple videos that can be uploaded to one field, so using the embed code by nid isn't ideal.

I'm trying to work out a solution, if I find one I'll post it here.

Comments

dlumberg’s picture

Not really the drupal way but it was the quickest way to what I needed to accomplish.

/**
 * Menu callback : embed/video/[fid]
 */
function MYMODULE_embed_video($fid, $dim=null) {

  // Get a node that is using our file
  $nid = db_query("SELECT entity_id FROM field_data_field_video WHERE field_video_fid=:fid LIMIT 1", array(':fid'=>$fid))->fetchField();
  $node = node_load($nid);

  // Get a list of fields for the node type
  $fields = field_info_instances('node', $node->type);

  // Loop through the fields until we find a video field
  foreach ($fields as $field_type => $field) {
    if ($field['widget']['type'] == 'video_upload') {
      $video_field = $field;
      break;
    }
  }

  // Loop through and find our field and get its delta
  foreach ($node->{$video_field['field_name']}['und'] as $key => $video) {
    $delta = $key;
    if ($video['fid'] == $fid) break;
  }
  
  // Get the unthemed field ready to render
  $fvf = field_view_field('node', $node, 'field_video');
  
  // Make some basic HTML since this is going into an iframe
  $out = '<html>
    <head>
      <link href="http://vjs.zencdn.net/c/video-js.css" rel="stylesheet">
      <script src="http://vjs.zencdn.net/c/video.js"></script>
      <style type="text/css">body { margin:0px; background-color:#000000;}</style>
	</head>';
  
  // Render our delta
  $out .= '<body>' . render( $fvf[$delta] ) . '</body>';
  $out .= '</html>';
  
  // sorry drupal
  die ($out);

}
brycefisherfleig’s picture

Issue summary: View changes
Status: Active » Postponed (maintainer needs more info)

Thanks for your contribution, dlumberg! Could you provide a more detailed explanation of how to reproduce this issue? How many videos are you uploading to video field? What embed code are you using?

I'd be willing to look at this or accept a patch once I have more information about this issue.

dlumberg’s picture

We have fields that include up to 3 different videos that are shown in a slideshow that pops up a colorbox. Due to issues with IE8 we had to use an Iframe to display the videos inside the colorbox. We also had a use case where we needed to display the videos on another site.

The native method of embedding videos through the video module is to call the embed code using /video/embed/[EntityID]/[EntityTYPE]/[Field_Name]/[Width]/[Height]

function video_file_embed($entity_id, $entity_type, $field_name, $width, $height) {

As you can see there's no argument for the Delta on the field, this creates the problem where you can only embed the first video in a field: field_video['und'][0] and not field_video['und'][1] etc...

brycefisherfleig’s picture

Status: Postponed (maintainer needs more info) » Active
Issue tags: +7.x-2.11 roadmap

Awesome! Thanks, dlumberg. Looks like I should add a delta parameter to video_file_embed with a default value of 0. That should give themers and developers a bit more flexibility without introducing a lot more complexity.

Clever solution, by the way!

hypertext200’s picture

Component: Video Players » General
Status: Active » Closed (fixed)