Media front allows me to set the mediafront preset on a per content type bases (or per view) but I have the need to do this on a per node basis.

Simple example would be to have node1 autoplay (so preset with autoplay) and node2 not autoplay but both node1&2 are the same content type.

Comments

travist’s picture

Status: Active » Fixed

You can just do this with some CCK and Content Templates.

  • Step 1: Create a CCK text select list field. We will call it mediafront_preset.
  • Step 2: Within the PHP code of the Allowed Values setting of your CCK field, put the following code...
    $presets = mediafront_preset_get_presets();
    $options = array();
    foreach( $presets as $preset ) {
       $options[$preset->name] = $preset->name;
    }
    return $options;
    
  • Step 3: Now in your node template ( using Content Templates or whatever ), you can just put the following code!
    <?php
    print mediafront_get_player( $node->field_mediafront_preset[0]['value'], array( 'node' => $node->nid ) );
    ?>
    
  • Step 4: Go create a new node and then rejoice in MediaFront! :)

Hope this helps.

Travis.

travist’s picture

Title: Select preset on a per-node basis » Select MediaFront preset on a per-node basis

Changing title for better search-ability...

that0n3guy’s picture

Travis,

Thanks for that. I didn't even think about that. I could even just put step 3 in the body of the node.

My current setup is w/ video & flowplayer modules w/ a small hack... I have it go along w/ a feature I built that makes it very simple for several clients to do this via node edit form and cck. The code above is a little over their heads. I may have to try and emulate it w/ a simple module. Thanks

Status: Fixed » Closed (fixed)

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

that0n3guy’s picture

Status: Fixed » Needs review

I thought I would post some documentation for this. It is working pretty sweeeet and exactly the way I want it to (basically). I changed to 'needs review' in case you wanted to look it over and add it to the official docs.

Setup:

- Create a content type with a filefiled and image field like you normally would.
- create a mediafront profile like you normally would
- also create a field called "video_playerpreset" (so its final machine name will be "field_video_playerpreset")
- Make it a "text" field of "select" type
- In the "PHP code" section (below the "Allowed values list") add this code:

$presets = mediafront_preset_get_presets();
$options = array();
foreach( $presets as $preset ) {
   $options[$preset->name] = $preset->name;
}
return $options;

- install the custom_formatters module (http://drupal.org/project/custom_formatters)
- create a new formatter
- user the "advanced editor"
- use this code:

  /*
   *  set all the fields
   *  DO THIS:
   *  change "field_video_playerpreset" below to your preset field name
   *  change "field_video" below to your video filefield name
   *  change "field_video_thumb" below to your thumbnail imagefield name
   */
  $presetfield = 'field_video_playerpreset';
  $videofield = 'field_video';
  $thumbnailfield = 'field_video_thumb';

/*-------no need to edit below this line------------*/
  // Extract the preset name from the formatter name.
  $preset = $element['#node']->{$presetfield}[0]['value'];
  // Get the node for this player in JSON format.
  $params['nodeObj'] = mediafront_invoke_node( $element['#node'], array() );
  // Also set the nodeId for those who cannot just use the object.
  $params['node'] = $element['#node']->nid;
  // Set the video file
  $params['file'] = "/".$element['#node']->{$videofield}[0]['filepath'];
   // Set the thumbnail file
  $params['image']['path'] = "/".$element['#node']->{$thumbnailfield}[0]['filepath'];
  //check if there is a video uploaded
  if (isset($element['#node']->{$videofield}[0]['filepath'])){
  // Return the player.
  return mediafront_get_player( $preset, $params );
  }

- Modify the fields in the code to match your video, image, and preset fields
- save your new formatter
- Go to the "Display Fields" tab (yoursite.com/admin/content/node-type/[[yourcontenttypehere]]/display)
- select your new custom formatter for you video field
- hide (Don't exclude) the thumbnail field and preset field.

Done, create a new piece of content, upload video, thumbnail (optional) and select which preset you want for the video.

EDIT 7-29-10: changed up the custom_formatters code a littel so you just add the fields at the beginning (more newbie friendly). Also, added a check to see if there was actually a video added. If not, it does nothing instead of displaying "player not available"

travist’s picture

Component: Code » Documentation
Category: feature » task
Status: Closed (fixed) » Fixed

Thanks! I added this to the http://www.mediafront.org documentation section, so hopefully it will be easy to find.

http://www.mediafront.org/documentation/drupalmediafront-osm-cms-integra...

that0n3guy’s picture

Wow that was fast.

Thanks Man!

that0n3guy’s picture

Status: Needs review » Needs work

I've been testing this some more and I noticed that my: $params['file'] or $params['image'] don't actually do anything. Its the nodeObj that is actually supplying the video info to the player.

This is ok except if I have multiple imagefields... mediafront just picks the first one w/ an image for the video thumbnail.

So my question would be, how do I specify (in my formatter) what fields I want to use?

travist’s picture

I think this is now fixed since within the fieldfields, you can just set the fields you do not wish to include as "None".

travist’s picture

Status: Needs work » Fixed

Status: Fixed » Closed (fixed)

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

thebinaryworkshop’s picture

Has anyone got documentation on how to embed the player inside a node.tpl.php? I have a whole bunch of videos and I'm a bit worried of the performance penalty if the template has to be rendered from DB each time on node load. Atleast using APC on a node.tpl.php would result in a somewhat user experience.

bsenftner’s picture

Category: task » support
Status: Closed (fixed) » Active

Does this suggestion still work? I have two MediaFront Presets defined, with Blocks and Pages that demonstrate their existence, yet Step 2's code always returns an empty array for me...

And that description for how to create a custom formatter is missing some critical information or is outdated with the current interfaces, because following it does not make sense. I've not used custom formatters before, and the creation step seems to be missing something. (Or maybe it's working, and the code from Step 2 returning an empty array is the issue...?

travist’s picture

This should still work, but you most of the preset code was moved to the mediafront.preset.inc file within the includes folder of mediafront. Because of this, you may need to include that file before calling mediafront_preset_get_presets.

include_once drupal_get_path('module', 'mediafront') . '/includes/mediafront.preset.inc';
$presets = mediafront_preset_get_presets();

Hope this helps.

Travis.

bsenftner’s picture

Still not working. I placed your suggested code, resulting in this inside the CCK 'video_playerpreset' Text selection's PHP configuration:

include_once drupal_get_path('module', 'mediafront') . '/includes/mediafront.preset.inc';
$presets = mediafront_preset_get_presets();
$options = array();
foreach( $presets as $preset ) {
   $options[$preset->name] = $preset->name;
}
return $options;

Placing this same code inside the Devel module's 'Execute PHP' form also shows the final value of $options is an empty array. I also tried including the filefield and features include files to see if that made any difference (inside the Devel module's 'Execute PHP' form), but including those additional files does not... :/

-Blake

travist’s picture

did you put some print statements within the mediafront_preset_get_presets file to make sure that it is getting called? If so, then this sounds like some good ol' fashioned debugging is in order to figure out why this function is not giving you what you want. I know for a fact this function works since I use it all over, so I am sure there is a reason why it is giving you back empty results.