plyr icon indicating copy to clipboard operation
plyr copied to clipboard

Extending the controls and settings options API to support adding new controls and changing the order

Open friday opened this issue 6 years ago • 8 comments

The current array options for buttons and settings has some limitation:

  • You can't exclude a button or setting. You have to specify all buttons/settings you want to include instead (more verbose and complicated).
  • It's not possible to control the order of the buttons. While it would be possible for Plyr to respect the array order (as a comment in the source code suggests), this would be a breaking change.
  • It's not possible to add a custom button using the Plyr API directly (#787). The only way to do this now is by dom manipulation

Alternative syntax (boolean to disable, number to change the order):

new Plyr(element, {
    controls: {
        playLarge: false, // disable the big play button
        mute: 4, // move mute to after volume, for some reason
        chapters: 7 // add custom button "chapters" at position 7
    }, settings: {
        speed: false // disable speed settings
    }
});

The custom button "chapters" (#1011) could work by triggering a custom event. For example "plyr-custom-chapters". This could also work with future plugin support, by letting plugin extend the Plyr defaults.

I'm not sure how to deal with svg icons, labels, toggle-states buttons or "sliders" though. It's likely we need a more complex API for custom buttons.

This is not a high prio task. I just wanted to put it out there for feedback since the second and third issues have been brought up a few times.

friday avatar Jun 18 '18 16:06 friday

Definitely agree with all of this. I had originally thought about ordering the controls based on their order in the array in the options. I guess I'm not sure which is better - defaults that you can disable or opt in/out for everything (using the array).

Creating custom buttons has been asked for before. I think passing an object in somehow would work with the title (for tooltip or hidden), icon id and callback/action/URL could possibly work.

sampotts avatar Jun 18 '18 23:06 sampotts

I think the current default button selection and order is very good and intuitive. I typically only want to make small changes to is regardless of use case, and our app uses Plyr in a video grid, modals, subtitle editor and a sharable link for the result, so it's quite versatile.

We're not everyone though, so more input is appreciated.

friday avatar Jun 18 '18 23:06 friday

I think an object might be a good idea. I presume false instead of a number would mean hide the button.

On the topic of custom stuff, besides the complex items you mention. I have a use case where I want to add a complex button to the upper right in addition to the normal buttons.

dantman avatar Aug 06 '19 22:08 dantman

+1 , don't really have an input on how it should look in terms of an API, I trust whatever you guys come up with. My use case is that I would like to add a button for 'theatre' mode, so I'd be looking to just add an icon that I can target with some JS to make the necessary DOM adjustments.

mayeaux avatar Aug 27 '20 19:08 mayeaux

I also would find custom buttons quite useful. Pass an object through containing perhaps the button image, a callback function, and any other metadata like tooltips feels intuitive enough. I suppose though some ordering mechanism would also need to be considered.

bhayward93 avatar Sep 25 '20 16:09 bhayward93

Can anyone help me add a custom button/link next to the volume button please?

inside83 avatar May 23 '21 15:05 inside83

Can anyone please help me add a toggle button and a dropdown menu like the speed or quality menu inside the settings option. this will really help my website.

Shuvadip-Ghosh avatar Mar 23 '24 17:03 Shuvadip-Ghosh

@Shuvadip-Ghosh Unfortunately Plyr never supported custom controls. If you are looking for a quick and dirty solution you can hack some additional HTML code into the player controls with JS in plyr.on('ready', ...). It makes little sense however to develop new code against Plyr; it has been unmaintained for a year now. I suggest picking a different video player library that has support for custom controls built-in.

AgentOak avatar Mar 24 '24 00:03 AgentOak