Ability to set the JavaScript Event Handlers.

Comments

robloach’s picture

Status: Active » Needs work

This will register the onLoad, onCuepoint and onSeek events. Would be great to get support for all events though.... Anyone know of a way to pass a JavaScript function through Drupal.settings or something?

    // ...
    var config = Drupal.settings.flowplayer[selector];

    // Convert any JavaScript events to function calls.
    if (typeof(config['onLoad']) == 'string') {
      config['onLoad'] = eval(config['onLoad']);
    }
    if (config['clip'] && config['clip']['onCuepoint'] && typeof(config['clip']['onCuepoint'][1]) == 'string') {
      config['clip']['onCuepoint'][1] = eval(config['clip']['onCuepoint'][1]);
    }
    if (config['clip'] && typeof(config['clip']['onSeek']) == 'string') {
      config['clip']['onSeek'] = eval(config['clip']['onSeek']);
    }

    // Create the flowplayer element on the non-processed elements.
    // ...
  echo theme('flowplayer', array(
    'url' => 'myvideo.flv',
    'onLoad' => 'playerOnLoad',
  );
// Custom JavaScript
function playerOnLoad() {
  alert('OMGZ');
}
Anonymous’s picture

Rob, I'm encountering the same problem too. Neither drupal_to_js nor json_encode (php5) are checking for strings that look like functions.

I found some guidance, but it definitely involves side-stepping drupal_to_js or json_encode.

http://solutoire.com/2008/06/12/sending-javascript-functions-over-json/

I think your method of evaluating the string is a good start. I've also seen some tips that suggest using JS Function objects.

http://www.permadi.com/tutorial/jsFunc/index.html

All of Flowplayer's events are known. Perhaps your method here should be expanded to work on all the known events on clip and player?

Anonymous’s picture

Rob, I'm encountering the same problem too. Neither drupal_to_js nor json_encode (php5) are checking for strings that look like functions.

I found some guidance, but it definitely involves side-stepping drupal_to_js or json_encode.

http://solutoire.com/2008/06/12/sending-javascript-functions-over-json/

I think your method of evaluating the string is a good start. I've also seen some tips that suggest using JS Function objects.

http://www.permadi.com/tutorial/jsFunc/index.html

All of Flowplayer's events are known. Perhaps your method here should be expanded to work on all the known events on clip and player?

robloach’s picture

Yeah, since Drupal.settings only supports arrays, integers and strings, we're limited to what we can do with it. Using eval seems like the best way to go. #374042: Default Configuration Options required onLoad, so that's in already, just need the rest of the events....

robloach’s picture

Status: Needs work » Fixed

Status: Fixed » Closed (fixed)

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

markj’s picture

Component: Code » Documentation

This issue has a 'fixed' status but it's still not clear to me how to add a callback to the flowplayer configuration in a module. The link to the commit that fixed it is broken (points to old cvs repo) so I can't take a look at the code.

Specifically, I'd like to implement the function illustrated on http://flowplayer.org/plugins/streaming/audio.html at "optional: when playback starts close the first audio playback".