Skip to main content
User Community Portal
Question

Toggle between 2 videos

  • December 16, 2025
  • 2 replies
  • 13 views

Forum|alt.badge.img

Hi Team,

 

I am looking to have a custom control which toggles between 2 video elements in Reactjs app. It adding button but not showing text. Can you please help here.

 

        window.videojs.players['myPlayerId']?.getChild('ControlBar')?.addChild('button', {

          value:'heelo',

          label:'heelo name',

          textContent: "text”

        });

 

HTML content seeing on the browser:

 

<button class="vjs-control vjs-button" type="button" aria-disabled="false"><span class="vjs-icon-placeholder" aria-hidden="true"></span><span class="vjs-control-text" aria-live="polite"></span></button>

 

 

2 replies

Forum|alt.badge.img
  • Author
  • New Participant
  • December 18, 2025

        player.getChild("ControlBar").addChild("Button", {

          controlText: `Turn ${audioDescription}audio description`,

          className: "vjs-visible-text",

          clickHandler: handleVideoChange

        });

 

this worked for me


Forum|alt.badge.img
  • New Participant
  • December 19, 2025

Hi! The reason your text isn’t showing is that video.js’s built-in button component doesn’t render textContent directly. You need to extend the Button component and override the buildCSSClass or controlText methods, or use el().innerText after creating it.

 

const VjsButton = videojs.getComponent('Button');
const MyButton = videojs.extend(VjsButton, {
  constructor: function(player, options) {
    VjsButton.call(this, player, options);
    this.controlText('hello name'); // sets the aria text
  },
  handleClick: function() {
    console.log('Button clicked!');
  }
});

window.videojs.players['myPlayerId']
  ?.getChild('ControlBar')
  ?.addChild(new MyButton(window.videojs.players['myPlayerId']));

This will properly set the label and display the text in the control.