WordPress.org

Make WordPress Core

Opened 20 months ago

Closed 12 months ago

Last modified 6 months ago

#25243 closed enhancement (fixed)

Allow more nuanced control over mediaelement.js elements

Reported by: ericlewis Owned by: wonderboymusic
Milestone: 4.0 Priority: normal
Severity: normal Version:
Component: Media Keywords: has-patch
Focuses: Cc:

Description

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 13 months ago.

Download all attachments as: .zip

Change History (7)

comment:1 @wraithkenny18 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. :-/

@Otto4213 months ago

comment:2 @Otto4213 months 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 @Otto4213 months 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.

comment:4 @wonderboymusic12 months ago

  • Owner set to wonderboymusic
  • Resolution set to fixed
  • Status changed from new to closed

In 28370:

Allow users to set overrides for MediaElement instances by always passing _wpmejsSettings instead of just _wpmejsSettings.pluginPath.

Props Otto42 for the initial patch.
Fixes #25243.

comment:5 @wonderboymusic12 months ago

  • Keywords dev-feedback 2nd-opinion removed
  • Milestone changed from Awaiting Review to 4.0

comment:6 @michael.heuberger6 months ago

I need my own success callback very badly here. Wish it was something like this instead:

settings.success = settings.success = function (mejs) {
	...
};

Like that I can define my own success callback through _wpmejsSettings !

Note: See TracTickets for help on using tickets.