A useful API function would be mediaelement_render($file, Array $options = array()).
It could be used to replace
$settings = array(
'#a-unique-id' => array(
'controls' => TRUE,
'opts' => array(),
),
);
// Requires patch from drupal.org/node/1132746
mediaelement_add_js($settings);
$variables = array(
'attributes' => array(
'src' => $file,
'id' => 'a-unique-id',
),
'settings' => array(
'download_link' => FALSE,
),
);
$output = theme('mediaelement_audio', $variables);
with something like
$output = mediaelement_render($file);
It would also take a parameter for optional settings. I suggest the following;
id; Optionally set the unique ID. Otherwise MediaElement module creates a unique one using astaticcount variable.width; Width of the player in pixels or percentage.height; Height of the player in pixels or percentage.controls; Disable or enable the controls.opts; MediaElement.js API options.attributes; Override defaults fortheme_mediaelement_audio().settings; Override defaults fortheme_mediaelement_audio().type;videooraudio. Otherwise MediaElement module determines it by the file extension of$file.
The first parameter $file would become $attributes['src']. $options['id'] would become $attributes['id']. $options['width'] and $options['height'] would be handled similarly. $options['controls'], $options['opts'], $options['attributes'], $options['settings'], are obviously parameters for theme_mediaelement_audio() and drupal_add_js().
$options['type'] would determine which theme function is called; theme_mediaelement_audio() or theme_mediaelement_video(). Perhaps these could be abstracted into theme_mediaelement_element() so that theme_mediaelement_audio() and theme_mediaelement_video() simply become wrapper functions for theme_mediaelement_element(), since the two functions are identical except for the keywords "video" and "audio".
Comments
Comment #1
Bevan commented#1132746: API function: mediaelement_add_js() is related.
autoplaywould also be a good option.Comment #2
mfer commentedsub
Comment #3
mfer commentedI'm looking at this and wondering how to do this as a renderable array. This is especially important when the media is presented in a block you want to cache. Same applies to _add_js issue.
Comment #4
Bevan commentedIf I recall correctly you can make up your own Form API properties, as long as they are prefixed with a hash character. You can then also set the #theme callback that is designated to rendering the element in question.
Comment #5
pbuyle commentedInstead of providing a function to generate an HTML string, what about an hook_element_info() implementation to provide (non-input) element types.
Then using the Render Array API or the Form API, one could use
Comment #6
jnettikOld ticket. Closing.