Posted by mrfelton on April 22, 2009 at 3:09pm
| Project: | FLV Media Player |
| Version: | 6.x-1.0-beta3 |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed (fixed) |
Issue Summary
I want to generate my own player code from within my theme. I do this like so:
<?php
$display_profile = 'default';
$playlist_height = 200;
$config = flvmediaplayer_profile_get_config($display_profile);
$data = flvmediaplayer_profile_parse_configuration_values($config);
// add our own data
$data['flashvars']['file'] = url('channels/'. arg(1) .'/10/xspf', array('absolute' => TRUE));
$data['flashvars']['playlistsize'] = $playlist_height;
$data['flashvars']['playlist'] = 'bottom';
$data['params']['height'] += $data['flashvars']['playlistsize'];
print theme('flvmediaplayer_render_player', $data['flvmp']['player_path'], $data['params'], $data['flashvars']);
?>In order to get all the configuration data for a profile, without a reference to a node, I wrote a function flvmediaplayer_profile_parse_configuration_values which was simply extracted from flvmediaplayer_configuration_values:
<?php
// extracted from flvmediaplayer_configuration_values()
function flvmediaplayer_profile_parse_configuration_values($config) {
$data = array();
// loop through all the form data and strip out form prefixes
foreach ($config as $name => $value) {
// get the params out
if (strstr($name, 'param_')) {
$data['params'][str_replace('param_', '', $name)] = $value;
}
// get the flashvars out
if (strstr($name, 'flashvar_')) {
$data['flashvars'][str_replace('flashvar_', '', $name)] = $value;
}
// store the rest of the data
if (strstr($name, 'flvmp_')) {
$data['flvmp'][str_replace('flvmp_', '', $name)] = $value;
}
}
// now add some data back in
$data['name'] = $config['flvmp_name'];
$data['pid'] = $config['flvmp_pid'];
return $data;
}
?>Perhaps you could refactor flvmediaplayer_configuration_values (which is printed below for reference) to enable other people to do the same more easily :)
<?php
/**
* this determins what data to build the configuration for a specified player from
* override by: parameters, requested profile, node data, default node type data
* @param array $node_configuration
* data from $node->flvmediaplayer
* @param array $params
* flvmediaplayer configuration attached to a node
* @param string $profile_name
* name of a profile
* @param boolean $embed
* is this an embed request?
* @return array
*/
function flvmediaplayer_configuration_values($node = null, $profile_name = null, $params = array()) {
// check to see if this configuration allows override
if (variable_get('flvmp_'. $node->type .'_override', false)) {
// check to see if we have any data for this node
$config = unserialize(db_result(db_query('SELECT config FROM {flvmediaplayer_node} WHERE nid = %d', $node->nid)));
}
// If a profile was requested get the profile configuration data that was requested
// only if there was no node override data
if (! $config && $profile_name) {
// make sure that we have a profile name that was requested
if (! $config = flvmediaplayer_profile_get_config($profile_name)) {
watchdog('FLV Media Player', 'A profile was requested that does not exist.', null, WATCHDOG_ERROR);
return false;
}
}
// no data yet, get the default for this node type, if
// we do not find data, return
elseif (! $config) {
if (! $config = flvmediaplayer_profile_get_config(variable_get('flvmp_'. $node->type .'_profile', false))) {
return false;
}
}
// If paramters are passed in, merge these with the set values
if (count($params)) {
$config = array_merge($config, $params);
}
// @TODO do this before merging the params in, merge params AFTER
// Now take the configuration data and put it into a structured array
$data = array();
// loop through all the form data and strip out form prefixes
foreach ($config as $name => $value) {
// get the params out
if (strstr($name, 'param_')) {
$data['params'][str_replace('param_', '', $name)] = $value;
}
// get the flashvars out
if (strstr($name, 'flashvar_')) {
$data['flashvars'][str_replace('flashvar_', '', $name)] = $value;
}
// store the rest of the data
if (strstr($name, 'flvmp_')) {
$data['flvmp'][str_replace('flvmp_', '', $name)] = $value;
}
}
// now add some data back in
$data['name'] = $config['flvmp_name'];
$data['pid'] = $config['flvmp_pid'];
// merge the values and return
return $data;
}
?>
Comments
#1
#2
Yeah, that is a good idea. Since most of my work revolved around using the xspf hook, I didn't really consider this to much. If you submit a patch (hint hint) I'll try to get it in.
#3
#4
I took a slightly different approach, but utilize the majority of your code. Tried to simplify the call a bit. Let me know what you think.
#5
at first glance...
there is a mismatch of variable names ($profile is passed in, but then you reference $display_profile within the function)... I'll try and test it properly later on.
#6
#7
#8
Woops
#9
ok, yeah... but you not going to actually use it in
flvmediaplayer_configuration_valuestoo?!And... just a sugestion... perhaps
flvmediaplayer_configuration_valueswould be better namedflvmediaplayer_node_configuration_valuesleaving you with:
flvmediaplayer_profile_configuration_valueswhich gets configuration_values from a profile
and:
flvmediaplayer_node_configuration_valueswhich gets configuration_values from a node
#10
oh no, I see what you've done... you actually added getting the config object into
flvmediaplayer_profile_configuration_values... Only thing about that is that now you have this large chunk of duplicated code. If your going to do it that way, then I'd suggest re-factoring it even further to remove the duplication. A new function to do the hard work, andflvmediaplayer_profile_configuration_valueswould just be a wrapper around it for easy access... If you follow?!#11
Yeah, I think that makes sense. I think the flvmediaplayer_build_player_data() function is still a bit weird, but I agree that the two different configuration functions should be a bit clearer. I've taken your suggestions from above and rolled a new patch.
#12
patch fails to apply to what is in CVS
#13
sorry, try this
#14
I'm not sure what that patch does, but it seems to be very different from al the others.
#15
Here is an updated version of the path at #11. This one applies to CVS and seems to be working nicely
#16
This is actually all in the dev branch already. I'm going to close this unless there other items along this issue that need to get addressed.
#17
#18
Automatically closed -- issue fixed for 2 weeks with no activity.