Skip to content

Instantly share code, notes, and snippets.

View gkatsev's full-sized avatar

Gary Katsevman gkatsev

View GitHub Profile
@gkatsev
gkatsev / process-all.js
Last active November 4, 2022 18:03
Simple captions with vtt.js and a sample video.
var video = document.querySelector('video');
var caption = video.querySelector('track[kind=captions]');
var captionsArea = document.querySelector('.captions-area');
var captionsDisplay = document.querySelector('.captions-display');
var xhr = new XMLHttpRequest();
xhr.open('GET', caption.src);
xhr.onreadystatechange = function() {
if (xhr.readyState === 4) {
vjs.EventEmitter = function() {
};
vjs.EventEmitter.prototype.allowedEvents_ = {
};
vjs.EventEmitter.prototype.on = function(type, fn) {
vjs.on(this, type, fn);
};
@gkatsev
gkatsev / prop.md
Created December 8, 2014 19:58
proposals for new/additional APIs for text tracks
  • Available API

    • addTextTrack(kind [, label [, language]]);
  • Additional API

    • removeTrack(track);
  • proposals

    • addRemoteTrack(options);
  • options

@gkatsev
gkatsev / index.js
Created December 19, 2014 17:11
requirebin sketch
var vjs = require('video.js');
var doc = require('global/document');
var video = doc.createElement('video');
video.src = 'http://vjs.zencdn.net/v/oceans.mp4';
var link = doc.createElment('link');
link.href = 'http://vjs.zencdn.net/4.11/video-js.css';
link.rel = 'stylesheet';
function bar(x) {
"use strict";
switch (x) {
case 1:
let foo = 5;
console.log(foo);
case 2:
foo = 6;
return console.log(foo);
@gkatsev
gkatsev / computedStyle.js
Created May 18, 2015 19:58
getComputedStyle shim
computedStyle = function(el, prop) {
if (typeof getComputedStyle === 'function') {
return getComputedStyle(el)[prop];
} else {
return el.currentStyle[prop];
}
}
Steps to reproduce the problem:
1. create a page with a video element
2. include a subtitle or caption track
3. make sure that the track from above is not marked as `default`
What is the expected behavior?
the subtitles or captions should show up only if they are marked as default, or if the user selects them.
What is the actual behavior?
If the user has not previously selected any captions, the first caption in the caption list shows up, regardless or whether that track is in the user locale's or whether the default audio is in the user's locale or not.
@gkatsev
gkatsev / index.js
Created August 30, 2015 22:24
requirebin sketch
// require() some stuff from npm (like you were using browserify)
// and then hit Run Code to run it on the right
var table = require('html-table-stream');
var concat = require('concat-stream');
var xhr = require('xhr');
xhr('http://crossorigin.me/http://www.transithistory.org/roster/', function(err, res, body) {
if (err) {
return document.body.innerHTML = err.message;
var async = require('async');
var swap = function(f) {
return function(callback) {
f(function(e, a) {
callback(a, e);
})
};
};
module.exports = function tryAll(tasks, callback) {

Plugins

Plugins mostly have not changed from how they worked in Videojs 4.x. You still register and use them the same way. The only major change is that if you are instantiating a plugin inside the config of a player, this plugin will get run before the player is ready. This is so that if plugins are doing some UI work or adding themselves as children of the player they can do so early on. This means that plugins that require the player to be ready would need to handle that themselves or else not support instantiation via the player config. Ex:

videojs('my-video', {
 plugins: {