I tried the 2 top answers here and they both worked but didn't address other problems, such as the button not showing text or an icon and missing a title.
Here's my solution:
const customInvertFilterButton: videojs.Button = this.video.controlBar.addChild('button')
customInvertFilterButton.addClass('vjs-custom-invert-filter-button')
customInvertFilterButton.addClass('vjs-icon-spinner')
customInvertFilterButton.setAttribute('title', 'Invert')
customInvertFilterButton.on('click', () => {
this.invertFilter = !this.invertFilter
customInvertFilterButton.setAttribute('title', this.invertFilter ? 'Uninvert' : 'Invert')
})
Here, the vjs-icon-spinner class is a vjs icon. All their icons are here:
https://videojs.github.io/font
Optionally, to read more about their icons check this out (I didn't find it overly useful):
https://github.com/videojs/font
Finally, the icons were rendering too small. You can adjust their size and look with this SCSS:
.vjs-custom-invert-filter-button {
cursor: pointer;
&.vjs-icon-spinner:before {
font-size: 1.8em;
line-height: 1.67;
}
}
Hope it helps. Much love in HIM! Yes, J^e^s^u^s
OPTIONAL ADDITIONAL INFO FOR MORE ICONS
The VJS icon set is a subset of the Material Icons set.
Its possible to use any Material Icon as follows:
// https://github.com/google/material-design-icons/tree/master/font
// https://google.github.io/material-design-icons/#setup-method-2-self-hosting
@font-face {
font-family: 'VJS Material Icons';
font-style: normal;
font-weight: 400;
src: local('Material Icons'), local('MaterialIcons-Regular'), url(/assets/fonts/vjs-mat-icons/MaterialIcons-Regular.ttf) format('truetype');
}
.vjs-material-icons {
font-family: 'VJS Material Icons', sans-serif;
font-weight: normal;
font-style: normal;
font-size: 24px; /* Preferred icon size but also suggests 18px, 24px, 36px, 48px */
display: inline-block;
line-height: 1;
text-transform: none;
letter-spacing: normal;
word-wrap: normal;
white-space: nowrap;
direction: ltr;
/* Support for all WebKit browsers. */
-webkit-font-smoothing: antialiased;
/* Support for Safari and Chrome. */
text-rendering: optimizeLegibility;
/* Support for Firefox. */
-moz-osx-font-smoothing: grayscale;
/* Support for IE. */
font-feature-settings: 'liga';
}
The above font file can be downloaded from https://github.com/google/material-design-icons/tree/master/font
Then to use any Material icon:
// https://fonts.google.com/icons
.vjs-custom-brightness-down-button {
cursor: pointer;
&.vjs-icon-brightness-down {
font-family: 'VJS Material Icons', serif;
font-weight: normal;
font-style: normal;
&:before {
content: "\e1ad"; // this relates to a specific icon
font-size: 1.4em;
line-height: 1.67;
}
}
}
Note that the unicode code seen in the CSS content property can be gotten from https://fonts.google.com/icons
And finally, the .ts for this:
private initCustomBrightnessDownButton() {
const customBrightnessDownButton: videojs.Button = this.video.controlBar.addChild('button')
customBrightnessDownButton.addClass('vjs-custom-brightness-down-button')
customBrightnessDownButton.addClass('vjs-material-icons')
customBrightnessDownButton.addClass('vjs-icon-brightness-down')
customBrightnessDownButton.setAttribute('title', 'Brightness -')
customBrightnessDownButton.on('click', () => {
this.brightness = this.brightness > 10 ? this.brightness - 10 : this.brightness
})
}