When multiple files are uploaded to a single filefield, the template is called multiple times.

This results in multiple lines of each of the three possible sources you have in the template file. While using the template is nice and provides flexibility, you might want to process the files within your preprocess function and simply pass in a $var item.

When a webm is not supplied (which is my use case) you are rendering a path into the source for webm that does not match. The only sources which should be rendered are those which have content.

Comments

mattman’s picture

I've fixed this for myself. It's more of hack and not really how it should be solved, but it's working for me for now.

I created a static in the tpl file (yes, ugly) to account for the multiple calls. Here's the code. Not doing a patch because this doesn't seem like the right solution - it's just temporary.

Do you have your module on github? I could clone and then make pull requests if you want help with the mod.

<?php
// $Id: videojs.tpl.php,v 1.1.2.2 2010/10/31 09:09:40 heshanmw Exp $

/**
 * Provide the HTML output of the videojs audio player.
 */
?>
 <!-- Begin VideoJS -->
  <div class="video-js-box" id="<?php print $player_id; ?>">
    <!-- Using the Video for Everybody Embed Code http://camendesign.com/code/video_for_everybody -->
    <video id="<?php print $player_id; ?>" class="video-js" width="<?php print(variable_get('videojs_width', 640))?>" height="<?php print(variable_get('videojs_height', 264))?>" controls="controls" preload="auto" poster="">
      <?php //dd($items); ?>
      <?php static $videojs_sources; ?>
      <?php $codecs = array('video/mp4' => 'avc1.42E01E, mp4a.40.2', 'video/webm' =>  'vp8, vorbis', 'video/ogg' => 'theora, vorbis' ); ?>
      <?php foreach ($items as $item):?>
        <?php $filepath = file_create_url($item['filepath']); ?>
        <?php $mimetype = $item['filemime']; ?>
        <?php $videojs_sources .= "<source src=\"$filepath\" type='$mimetype; codecs=\"" . $codecs[$mimetype] . "\"' />"; ?>
      <?php endforeach; ?>
      <?php print $videojs_sources; ?>
      <!-- Flash Fallback. Use any flash video player here. Make sure to keep the vjs-flash-fallback class. -->
      <!-- @TODO: Add Flowplayer on SWFTools or Flowplayer API modules -->
    </video>
  </div>
  <!-- End VideoJS -->
heshanlk’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.