Hi,

I'm currently using JW Media Player via the SWF Tools module and would like to switch to the JW Player Module for Drupal (http://drupal.org/project/jwplayermodule).

At present I’m creating the player in my node and views using the code below and would like it to be rewritten (including the caching) so that it works with the JW Player Module for Drupal.

Node-example.tpl.php

if (isset($node))
{

    // Displays the media player with an Imagefield preview 

    if ($node-> field_video_advert[0]['filepath']!='')
    {
     print swf($node-> field_video_advert [0]['filepath'],
        array(
        'params' => array('width' => '450', 'height' =>'350'),
        'flashvars' => array(
          'image' => 'imagecache/product_pic/activity_event_images/' . ($node-> field_image_product [0]['filename'])) 
       ));
    }
    else
      print theme('imagecache', 'product_pic', $node->field_image_product[0]['filepath']);
}


views-view-field--field-video-advert-fid.tpl

// Get file ids

$fid_video = $row->{$field->field_alias};

// Find real field alias for image field

$fid_image = false;

$suffix = "field_image_product_fid";
 
foreach($row as $key => $val)
	if (substr($key, -1*strlen($suffix)) == $suffix)
		$fid_image = $val;

// If we got some data, display it.

if (!empty($fid_video) || !empty($fid_image))
{
    $node = (object)array();

    $node->field_video_advert[0] = field_file_load($fid_video);
    $node->field_image_product[0] = field_file_load($fid_image);

    // Check if we got an image

    if ($node-> field_video_advert[0]['filepath']!='')
    {
     
     // Displays the media player with an Imagefield preview 
     print swf($node-> field_video_advert [0]['filepath'],
        array(
        'params' => array('width' => '210', 'height' =>'180'),
        'flashvars' => array(
          'image' => 'imagecache/product_image/activity_event_images/' . ($node-> field_image_product [0]['filename'])
               ));
    }
    else
      print theme('imagecache', 'product_image', $node->field_image_product[0]['filepath']);
}	



Any help is appreciated!

Thanks,

Evelyn

Comments

jvizcarrondo’s picture

I have not tried, but this might work
Node-example.tpl.php

<?php
if (isset($node))
{

    // Displays the media player with an Imagefield preview

    if ($node-> field_video_advert[0]['filepath']!='')
    {
     $flash_vars['file'] = $node->field_video_advert [0]['filepath'];
     $flash_vars['image'] = 'imagecache/product_pic/activity_event_images/' . $node-> field_image_product [0]['filename'];
     $flash_vars['width'] = '450';
     $flash_vars['height'] = '350';
     print theme("jwplayermodule_render_player", 'Your video', $flash_vars);
    }
    else
      print theme('imagecache', 'product_pic', $node->field_image_product[0]['filepath']);
}
?>

views-view-field--field-video-advert-fid.tpl

<?php
// Get file ids

$fid_video = $row->{$field->field_alias};

// Find real field alias for image field

$fid_image = false;

$suffix = "field_image_product_fid";

foreach($row as $key => $val)
    if (substr($key, -1*strlen($suffix)) == $suffix)
        $fid_image = $val;

// If we got some data, display it.

if (!empty($fid_video) || !empty($fid_image))
{
    $node = (object)array();

    $node->field_video_advert[0] = field_file_load($fid_video);
    $node->field_image_product[0] = field_file_load($fid_image);

    // Check if we got an image

    if ($node-> field_video_advert[0]['filepath']!='')
    {
    
     // Displays the media player with an Imagefield preview
     $flash_vars['file'] = $node->field_video_advert [0]['filepath'];
     $flash_vars['image'] = 'imagecache/product_image/activity_event_images/' . $node-> field_image_product [0]['filename'];
     $flash_vars['width'] = '210';
     $flash_vars['height'] = '180';
     print theme("jwplayermodule_render_player", 'Your video', $flash_vars);
    }
    else
      print theme('imagecache', 'product_image', $node->field_image_product[0]['filepath']);
}   
?>

Hope that helps
Juan

nyleve101’s picture

Hi Juan,

thanks for your help. I tried your code but for some reason the player loads a 'video not found or access denied' message. To test the issue I switched back to using jwplayer using swftools and everything worked again.

Do you have any idea why this might be happening?

Thanks again,

Evelyn

jvizcarrondo’s picture

This would result

Node-example.tpl.php

<?php
global $base_path;
if (isset($node))
{

    // Displays the media player with an Imagefield preview

    if ($node-> field_video_advert[0]['filepath']!='')
    {
     $flash_vars['file'] = $base_path . $node->field_video_advert [0]['filepath'];
     $flash_vars['image'] = 'imagecache/product_pic/activity_event_images/' . $node-> field_image_product [0]['filename'];
     $flash_vars['width'] = '450';
     $flash_vars['height'] = '350';
     print theme("jwplayermodule_render_player", 'sample', $flash_vars);
    }
    else
      print theme('imagecache', 'product_pic', $node->field_image_product[0]['filepath']);
}
?>

views-view-field--field-video-advert-fid.tpl

<?php
// Get file ids
global $base_path;

$fid_video = $row->{$field->field_alias};

// Find real field alias for image field

$fid_image = false;

$suffix = "field_image_product_fid";

foreach($row as $key => $val)
    if (substr($key, -1*strlen($suffix)) == $suffix)
        $fid_image = $val;

// If we got some data, display it.

if (!empty($fid_video) || !empty($fid_image))
{
    $node = (object)array();

    $node->field_video_advert[0] = field_file_load($fid_video);
    $node->field_image_product[0] = field_file_load($fid_image);

    // Check if we got an image

    if ($node-> field_video_advert[0]['filepath']!='')
    {
   
     // Displays the media player with an Imagefield preview
     $flash_vars['file'] = $base_path . $node->field_video_advert [0]['filepath'];
     $flash_vars['image'] = 'imagecache/product_image/activity_event_images/' . $node-> field_image_product [0]['filename'];
     $flash_vars['width'] = '210';
     $flash_vars['height'] = '180';
     print theme("jwplayermodule_render_player", 'sample', $flash_vars);
    }
    else
      print theme('imagecache', 'product_image', $node->field_image_product[0]['filepath']);
}  
?>

you must verify the path imagecache

Juan

nyleve101’s picture

Hi Juan,

thanks again for your help. The video is now playing correctly- thank you! However, the preview images are not appearing, I assume it's the base path issue again, so how would I incorporate that for the images please?

Hope you're well and taking care of yourself,

Evelyn

jvizcarrondo’s picture

Now I can not test image_cache, but I think this works. You add imageche path, should change $flash_vars['image'] (use imagecache_create_url()):
in Node-example.tpl.php

     $flash_vars['image'] = 'imagecache/product_pic/activity_event_images/' . $node-> field_image_product [0]['filename'];

by

     $flash_vars['image'] = imagecache_create_url('product_pic', $node->field_image_product[0]['filepath']);

and

in views-view-field--field-video-advert-fid.tpl.php

     $flash_vars['image'] = 'imagecache/product_image/activity_event_images/' . $node-> field_image_product [0]['filename'];

by

     $flash_vars['image'] = imagecache_create_url('product_image', $node->field_image_product[0]['filepath']);

Juan

nyleve101’s picture

Juan,

thanks so much! That did the trick perfectly.

Thanks again!!

Evelyn