Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta name="description" content="A demonstration of creating a Video.js 5.x component.">
  <meta charset="utf-8">
  <link href="//vjs.zencdn.net/5.11/video-js.css" rel="stylesheet">
  <script src="//vjs.zencdn.net/5.11/video.js"></script>
</head>
<body>
  <h1>Createing Component for VideoJs</h1>
  <video id="my-player" class="video-js" controls preload="auto" width="640" height="268">
    <source src="//vjs.zencdn.net/v/oceans.mp4" type='video/mp4'>
    <source src="//vjs.zencdn.net/v/oceans.webm" type='video/webm'>
  </video>
</body>
</html>
 
.video-js .vjs-title-bar {
  background: rgba(0, 0, 0, 0.5);
  color: white;
  
  /*
    By default, do not show the title bar.
  */
  display: none;
  font-size: 2em;
  padding: .5em;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
}
/* 
  Only show the title bar after playback has begun (so as not to hide
  the big play button) and only when paused or when the user is 
  interacting with the player.
*/
.video-js.vjs-paused.vjs-has-started .vjs-title-bar,
.video-js.vjs-user-active.vjs-has-started .vjs-title-bar{
  display: block;
}
 
// Get the Component base class from Video.js
var Component = videojs.getComponent('Component');
// The videojs.extend function is used to assist with inheritance. In
// an ES6 environment, `class TitleBar extends Component` would work
// identically.
var TitleBar = videojs.extend(Component, {
  // The constructor of a component receives two arguments: the
  // player it will be associated with and an object of options.
  constructor: function(player, options) {
    // It is important to invoke the superclass before anything else, 
    // to get all the features of components out of the box!
    Component.apply(this, arguments);
    // If a `text` option was passed in, update the text content of 
    // the component.
    if (options.text) {
      this.updateTextContent(options.text);
    }
  },
  // The `createEl` function of a component creates its DOM element.
  createEl: function() {
    return videojs.createEl('div', {
      // Prefixing classes of elements within a player with "vjs-" 
      // is a convention used in Video.js.
      className: 'vjs-title-bar'
    });
  },
  // This function could be called at any time to update the text 
  // contents of the component.
  updateTextContent: function(text) {
    // If no text was provided, default to "Title Unknown"
    if (typeof text !== 'string') {
      text = 'Title Unknown';
    }
    // Use Video.js utility DOM methods to manipulate the content
    // of the component's element.
    videojs.emptyEl(this.el());
    videojs.appendContent(this.el(), text);
  }
});
// Register the component with Video.js, so it can be used in players.
videojs.registerComponent('TitleBar', TitleBar);
// Create a player.
var player = videojs('my-player');
// Add the TitleBar as a child of the player and provide it some text 
// in its options.
player.addChild('TitleBar', {text: 'The Title of The Video!'});
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers