Make WordPress Core

Opened 7 months ago

Last modified 3 weeks ago

#25243 new enhancement

Allow more nuanced control over mediaelement.js elements

Reported by: ericlewis Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Media Keywords: dev-feedback 2nd-opinion has-patch
Focuses: Cc:


The mediaelement.js implementation in 3.6 is totally rad. However, I've come across an issue.

There's not much nuanced control you have in media elements. All settings are initialized globally for all media element instances, and taking the mediaelement.js defaults, without giving developers an option to override the settings.

wp_editor() is a good model of element instances, and allowing control over each of these instances. I'd like to suggest breaking out separate element instances in this fashion, so settings can be applied to each element independently, and open up these options to end-users through the shortcode options.

Attachments (1)

25243.diff (485 bytes) - added by Otto42 3 weeks ago.

Download all attachments as: .zip

Change History (4)

comment:1 wraithkenny5 months ago

  • Cc wraithkenny added

Making the _wpmejsSettings array filterable, and using the whole thing instead of just pluginPath might be a quick and easy enhancement, to at least be able to change MediaElement settings.

Maybe this would be useful for adding a success callback in order to add analytic events. Currently, it looks like you have to deregister wp-mediaelement.js and roll your own. :-/

Otto423 weeks ago

comment:2 Otto423 weeks ago

  • Keywords has-patch added; needs-patch removed

A very simple patch would be simply to eliminate the "pluginPath" part of the wp-mediaelement.js file. This allows code to use the existing functions to pass new settings parameters to the mediaelementjs code.

25243.diff shows the simplest change that works. Using this, one could call wp_localize_script like so to give it new parameters:

wp_localize_script( 'wp-mediaelement', '_wpmejsSettings', array(
		'pluginPath' => includes_url( 'js/mediaelement/', 'relative' ),
		'features' => array( 'whatever' ),

A filter to change these parameters would be preferable so that multiple plugins don't step on each other here. But this change would be needed anyway to allow other parameters than just pluginPath to be passed to the JS.

comment:3 Otto423 weeks ago

Example use case: I want this to be able to make a button that will throw videos from my site to a chromecast device, if one is available. For this, I need to be able to modify the features array in that settings variable in order to add my new button to the player control bar.

Note: See TracTickets for help on using tickets.