As I brought up in this issue: http://drupal.org/node/341893 I would like to create an advanced FlowPlayer 3 module, which would use FP 3 JS API for embedding and provide a way to use FP 3 plugins.
I started working on the module already (see attachment) - right now you can embed a single video using the FP3 embed method. I haven't tested other scenarios yet.
Any comments, requests, and ideas are welcome! :)

CommentFileSizeAuthor
flowplayer3_advanced.zip2.19 KBphpdiva
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Stuart Greenfield’s picture

I was thinking about this, and rather than create a whole new FlowPlayer3 module, I wonder if it would work to create a hook_flowplayer3() within the current FlowPlayer3 module. Since most of the FlowPlayer3 plugins are added by chaining more things on to the JSON it should be feasible to pass the array to another module during the rendering process, and it could over-ride properties and add new elements.

That way we keep the bulk of the FlowPlayer3 code in one place, and then make it extensible by plugging in, for example, the FlowPlayer embedding method, the content plugin, etc etc

What do you think?

Stuart Greenfield’s picture

Version: 6.x-1.x-dev » 6.x-2.3

I decided to give this a go, and I think it could work quite well. On HEAD now you'll find a new version of the FlowPlayer 3 module that implements hook_flowplayer3(). To go with it is a new module - FlowPlayer3 Embed. This contains the new hook, and when it is activated it replaces the current embedding with the FlowPlayer JavaScript method. I've tested locally and I get my "normal" SWF content via my regular embedding method, and FlowPlayer3 via the $f method, and it works fine!

I took your sample module as a start, so I've not really looked at the details of the embedding code, but it seems to be working fine.

The elegant thing about this approach is that the FlowPlayer3 Embed module doesn't recreate all the stuff that's already in the main FlowPlayer3 module, it just "extends" it, so less code all round.

The new hook gets called after the FlowPlayer3 module has done its variable manipulation, and assembled the initial array of flowplayer parameters. Everything gets passed via the hook, so the called modules can manipulate both SWF Tools and FlowPlayer parameters.

E.g. the FlowPlayer3 Embed module over-writes the existing embedding method settings with those needed to call flowplayer3_embed.

In principle, if another module wanted to activate a plug-in then it could write to the $flowplayer array to set things up. I think I might try this out with the content add-in, just to see what happens.

To try out the module you need to add flowplayer-3.0.6.min.js to the shared/flowplayer3 directory. If this method is kept we'll need an admin page to make this configurable. Thinking out loud, I wonder if we can use hook_form_alter to add this setting to the main FlowPlayer admin page? Or is it better to have a separate page? Anyhow, have to stop now, it's late here!

Any thoughts on this welcome!

Stuart Greenfield’s picture

I've been messing around with this some more this evening, and just made another commit to HEAD. I think the idea of an extensible FlowPlayer3 is the way to go. I've now written a prototype module to implement the content plugin, primarily to see if this idea works.

It's all looking pretty good, but not ready for "mainstream" yet. However, I have found that using the PHP input format on a page you can create a fully scripted FlowPlayer.

Using the example of the FlowPlayer page I put the following in to a Drupal node, after activating the FlowPlayer3 - Embed and FlowPlayer3 - Content modules. What you get is a player, with a content box floating on top, and it reacts to the buttons via JavaScript.

What I'm not sure about is (a) if anyone would actually need this module, and (b) if you have to generate it via PHP then it's going to be a fairly advanced technique, in which case would users who can take advantage of it not just write their own script directly?

That said, the embed and content modules probably serve as good examples of how you COULD extend FlowPlayer, so maybe they could serve as templates for people who want to write a really customised FlowPlayer experience.

In case anyone wants to try it, the code dump below is from the page I was using to test out the modules.

<?php

// Create the options array ready for swf - we pass data to the content plugin via the key 'content'
$options = array(
  'methods' => array('action' => 'swftools_flv_display'),
  'othervars' => array(
    'stream' => 'rtmp://server/app',
    'autoBuffering' => 'true',
    'id' => 'FlowPlayer',
    'content' => array(
      'top' => 20,
      'left' => 20,
      'width' => 200,
      'height' => 100,
      'html' => '<p>Hello!</p>',
      'closeButton' => 'true',
    ),
  ),
);

// Put the content on the page
print swf('movie', $options);

?>

// This script is lifted from the FlowPlayer content example page
<script type="text/javascript">
var actions = {

	toggleStyle: function() {
		var css = (this.css && this.css.border === 0) ?
			{backgroundColor:'333333', border:'1px solid #ffffff'} :
			{backgroundColor:'295c72', border:0}
		;
		$f().getPlugin("content").css(css);
		this.css = css;
	},

	togglePlugin: function(c) {
		$f().getPlugin(c).toggle();
	},

	toggleAnimate: function() {
		var css = (this.top == 50) ?
			{top:20, left:20, width: 200, height:100, opacity:0.95} :
			{width:'75%', height:'75%', top:50, left:50, opacity:1}
		;
		$f().getPlugin("content").animate(css, 2000);
		this.top = css.top;
	}

};

</script>

<p id="actions">
	<button type="button" onClick="actions.togglePlugin('content')">
		Toggle visibility
	</button>
	<button type="button" onClick="actions.toggleStyle()">
		Toggle style
	</button>
	<button type="button" onClick="actions.toggleAnimate()">
		Animate
	</button>
</p>
chawl’s picture

subs

phpdiva’s picture

This looks good.

I was trying to add FP plugins to my "advanced" module, and I had to decode the JSON string, add more stuff to it, and then encode it back up, and do all the ridiculous quote replacements. I think the hook is a great idea. I'll look over what you committed in the next few days. I'll definitely be using this module for closed captioning, streaming, etc. and think this will be quite useful for others who want to use flowplayer.

I wonder if instead of creating an admin page for each plugin, it would work to just have a textarea with PHP input filter, where one could add arbitrary $options, like you have in your example? This would all get merged with the main default options, and then with more specific "local" options from nodes. I guess it would be pretty tough to implement it all with the filter - maybe tokens would have to get involved somehow. I am personally calling swf() function from hook_nodeapi(), since I need to make it "dumbed down" for the content editors.

gausarts’s picture

Subs. Any update? Thanks