Download & Extend

Sample code to illustrate use of the module

Project:Embed
Component:Code
Category:task
Priority:normal
Assigned:Unassigned
Status:active

Issue Summary

The code samples here are indicative - as the module is under active development the format might change. Also, Drupal 7 isn't yet fixed and that might result in some changes. However, code samples are probably useful to get a quick overview of what is happening here.

Comments

#1

Inserting some basic flash:

<?php
// Describe the object (required)
$attributes = array(
 
'type' => 'application/x-shockwave-flash',
 
'data' => 'http://localhost/drupal7/sites/default/files/sample.swf',
 
'height' => 200,
 
'width' => 200,
);

// Define its parameters (optional)
$params = array(
 
'play' => 'true',
 
'loop' => 'true',
);

// Create an element
$element = array(
 
'#type' => 'object',
 
'#attributes' => $attributes,
 
'#parameters' => $params,
 
'#value' => 'This is the alternate content.',
);

// Render it
print drupal_render($element);
?>

The flash content is placed on the page, using the preferred handler. Currently have a choice of direct embedding, or SWF Object 2.

#2

Inserting ogg audio using the new HTML5 audio tag:

<?php
// Describe the object (required)
$attributes = array(
 
'type' => 'audio/ogg',
 
'data' => 'http://localhost/drupal7/sites/default/files/Test.ogg',
);

// Assign object data (optional)
$object_data = array(
 
'controls' => 'controls',
);

// Create an element
$element = array(
 
'#type' => 'object',
 
'#attributes' => $attributes,
 
'#object_data' => $object_data,
);

// Render it
print drupal_render($element);
?>

The audio object is placed on the page user the browser media player. Providing the controls attribute via object data causes the player controls to be shown. Note that this attribute is passed via #object_data as controls is NOT an attribute of an HTML object, only an HTML audio tag. If we were handling ogg via a different player (maybe flash) then the player might use a different name in a flashvar to represent the same concept. If we follow HTML5 and always use this attribute as part of #object_data then all possible handler modules know where to find this attribute and can behave accordingly.

#3

Complex example intended to show that it is actually relatively easy to build up complex behaviour. This uses the prototype flowplayer module to render the following series of content in flowplayer. The content is a mixture of video types. Note it uses the poster attribute (HTML5 video) in #object_data to set a thumbnail. It also uses the stream attribute to set some streamed content.

<?php
// Describe element #1 (stream with a thumbnail)
$element[1] = array(
 
'#attributes' => array(
   
'type' => 'video/x-flv',
   
'data' => 'video_1',
   
'poster' => 'http://localhost/drupal7/sites/default/files/sample.jpg',
  ),
 
'#object_data' => array(
   
'stream' => 'rtmp:/vod',
  ),
);

// Describe element #2 (stream)
$element[2] = array(
 
'#attributes' => array(
   
'type' => 'video/x-flv',
   
'data' => 'video_2',
  ),
 
'#object_data' => array(
   
'stream' => 'rtmp:/vod',
  ),
);

// Describe element #3 (non streamed)
$element[3] = array(
 
'#attributes' => array(
   
'type' => 'video/x-flv',
   
'data' => 'http://localhost/drupal7/sites/default/files/test.flv',
  ),
);

// Create an element
$element = array(
 
'#type' => 'object',
 
'1' => $element[1],
 
'2' => $element[2],
 
'3' => $element[3],
 
'#value' => 'Alternate content',
);

// Render it
print drupal_render($element);
?>

Result is the content rendered in to a flowplayer playlist. This is arguably what SWF Tools does now, but that relies on the use of either an input filter, or a call to the swf() function. This new approach could handle objects coming from any provider - all the provider has to do is describe an object.

#4

looks good -- we should leverage this for remote php stream wrappers

nobody click here