<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
Keyboard Shortcuts
Shortcut | Action |
---|---|
ctrl + [num] | Toggle nth panel |
ctrl + 0 | Close focused panel |
ctrl + enter | Re-render output. If console visible: run JS in console |
Ctrl + l | Clear the console |
ctrl + / | Toggle comment on selected lines |
ctrl + ] | Indents selected lines |
ctrl + [ | Unindents selected lines |
tab | Code complete & Emmet expand |
ctrl + shift + L | Beautify code in active panel |
ctrl + s | Save & lock current Bin from further changes |
ctrl + shift + s | Open the share options |
ctrl + y | Archive Bin |
Complete list of JS Bin shortcuts |
JS Bin URLs
URL | Action |
---|---|
/ | Show the full rendered output. This content will update in real time as it's updated from the /edit url. |
/edit | Edit the current bin |
/watch | Follow a Code Casting session |
/embed | Create an embeddable version of the bin |
/latest | Load the very latest bin (/latest goes in place of the revision) |
/[username]/last | View the last edited bin for this user |
/[username]/last/edit | Edit the last edited bin for this user |
/[username]/last/watch | Follow the Code Casting session for the latest bin for this user |
/quiet | Remove analytics and edit button from rendered output |
.js | Load only the JavaScript for a bin |
.css | Load only the CSS for a bin |
Except for username prefixed urls, the url may start with http://jsbin.com/abc and the url fragments can be added to the url to view it differently. |