Make WordPress Core

Opened 10 years ago

Closed 10 years ago

#30850 closed enhancement (fixed)

Audio/video previews for media controls in the Customizer

Reported by: celloexpressions's profile celloexpressions Owned by: ocean90's profile ocean90
Milestone: 4.2 Priority: normal
Severity: normal Version: 4.1
Component: Customize Keywords: has-patch
Focuses: javascript Cc:

Description

These were mostly in place but missing whatever's needed to trigger MediaElement.js, so they got pulled in [30712]. Turns out we just need to do something along the lines of control.container.find('audio,video').mediaelementplayer(_wpmejsSettings ); after rendering it from the JS template.

Attachments (5)

30850.png (6.9 KB) - added by celloexpressions 10 years ago.
30850.diff (2.9 KB) - added by celloexpressions 10 years ago.
Implement audio & video control previewing.
30850.2.patch (2.7 KB) - added by Fab1en 10 years ago.
30850.3.patch (3.4 KB) - added by Fab1en 10 years ago.
Introduce the triggering of 'expanded' and 'collapsed' events on a section
30850.2.diff (6.2 KB) - added by wonderboymusic 10 years ago.

Download all attachments as: .zip

Change History (21)

This ticket was mentioned in Slack in #core-customize by celloexpressions. View the logs.


10 years ago

@celloexpressions
10 years ago

Implement audio & video control previewing.

#2 @celloexpressions
10 years ago

  • Keywords has-patch added; needs-patch removed
  • Milestone changed from Future Release to 4.2

This is a nice quick improvement. Design improvements beyond this can happen in #30618.

#3 @ocean90
10 years ago

  • Keywords needs-patch added; has-patch removed

After the media is saved and doing a page refresh the preview doesn't work anymore. You will see a gray box with a download link.

#4 @celloexpressions
10 years ago

I think that means that MediaElement.js is having issues detecting browser support for the players, so it's using the fallback (a download link). Maybe it's trying to load them too early? I have no idea why it would do that, and didn't see that issue in my testing...

@wonderboymusic - any insights here?

#5 @Fab1en
10 years ago

I played a bit with @celloexpressions patch, and I found two issues :

  1. When the customizer is loaded with a media already present in the Upload control, mediaelement.js already handles it. So calling mediaelementplayer again breaks it.
  2. When mediaelementplayer is first run, the section is closed so the player inside the control is not visible. This causes the player control bar width to be set to a wrong value. setControlsSize mediaelement method should be called as soon as the player is made visible to restore the right control bar width

I have modified the patch to correct both issues, but I was not able to find the proper events to bind into. I put a 5s delay, so if you open the section where upload control is within 5s after loading, it works.

Is there an event that is triggered upon section opening, so that I can do something like

control.section().on( 'open', function() { /* do something */ } );

?

@Fab1en
10 years ago

#6 @celloexpressions
10 years ago

  • Keywords has-patch needs-refresh added; needs-patch removed

@Fab1en: the function you're looking for is api.Section.onChangeExpanded(). I believe there's a hook to bind in there but if there isn't we can add one. Or may be able to do something like control.section().bind...

#7 @westonruter
10 years ago

I think what you're looking for is:

wp.customize.section( control.section() ).expanded.bind( function ( expanded ) {
    if ( expanded ) {
        // it is open
    } else {
        // it is closed
    }
} )

#8 follow-up: @Fab1en
10 years ago

@westonruter : that's almost this, but the expanded event fires when the section start its expansion. I need an event that fires after the expansion is finished. In fact, what I need is called defaultExpandedArguments.completeCallback but I can't find a way to set it only for the proper control. Any hints ?

#9 in reply to: ↑ 8 @Aniruddh
10 years ago

Replying to Fab1en:

@westonruter : that's almost this, but the expanded event fires when the section start its expansion. I need an event that fires after the expansion is finished. In fact, what I need is called defaultExpandedArguments.completeCallback but I can't find a way to set it only for the proper control. Any hints ?

I think a patch of customizer-controls.js should be added where we change the defaultExpandedArguments.completeCallback from jQuery.noop to an actual function where we trigger an expanded event.

This will allow us to do something like this:

wp.customize.section( theSection ).on( 'expanded', function() {
    //do something
} );

And I think this event can be very useful.

#10 @westonruter
10 years ago

Yes, having an expanded (and collapsed) event for Sections would align with what widget form controls in the Customizer are doing. But in the mean time of not having it in Core, by the power of JavaScript you can have it now, by adding the following to some plugin code that gets enqueued after customize-controls.js:

var oldToggleExpanded = wp.customize.Section.prototype._toggleExpanded;
wp.customize.Section.prototype._toggleExpanded = function ( expanded, params ) {
        params = params || {};
        var section = this, previousCompleteCallback = params.completeCallback;
        params.completeCallback = function () {
                if ( previousCompleteCallback ) {
                        previousCompleteCallback.apply( section, arguments );
                }
                if ( expanded ) {
                        section.container.trigger( 'expanded' );
                } else {
                        section.container.trigger( 'collapsed' );
                }
        }
        oldToggleExpanded.call( this, expanded, params );
};

Note that as with widget form controls, the event is triggered on the DOM element itself, so that's what you listen on.

@Fab1en
10 years ago

Introduce the triggering of 'expanded' and 'collapsed' events on a section

#11 @Fab1en
10 years ago

  • Keywords needs-refresh removed

30850.3.patch includes @westonruter code above (without the monkey patch because, hey, we are in core !) and uses it to refresh the player controls once the panel is open.

I think we now have something pretty close to a good fix to this ticket.

This ticket was mentioned in Slack in #core by fab1en. View the logs.


10 years ago

#13 @Fab1en
10 years ago

Here is a simple way to test this : edit the inc/customizer.php file in the twentyfifteen theme, and add an upload control to the list :

$wp_customize->add_setting( 'upload_test', array(
	'default'           => '',
) );
$wp_customize->add_control( new WP_Customize_Upload_Control( $wp_customize, 'upload_test', array(
	'label'       => 'Upload test',
	'section'     => 'header_image',
) ) );

#14 @ocean90
10 years ago

For testing:

function test_customize_media( $wp_customize ) {
	$wp_customize->add_section( 'media', array( 'title' => 'Media', 'priority' => 0 ) );
	$wp_customize->add_setting( 'upload_control', array(
		'default' => 'https://make.wordpress.org/files/2011/06/wordpress-community-summit1.jpg',
	) );
	$wp_customize->add_control( new WP_Customize_Upload_Control( $wp_customize, 'upload_control', array(
		'label' => 'Upload Control',
		'section' => 'media',
		'priority' => 1,
	) ) );
}
add_action( 'customize_register', 'test_customize_media' );

Edit: Sorry @Fab1en, haven't seen you comment…

Last edited 10 years ago by ocean90 (previous) (diff)

#16 @ocean90
10 years ago

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

In 31661:

Customizer: Add audio/video previews for upload controls.

props celloexpressions, Fab1en, wonderboymusic.
fixes #30850.

Note: See TracTickets for help on using tickets.