Skip to content

Instantly share code, notes, and snippets.

@dmlap
dmlap / ad-type.js
Created April 28, 2014 17:51
Proposed ad type parameter. Analytics plugins may wish to report the type of advertisement that is currently playing.
// when an ad is playing, ads.type would expose the type of linear ad
player.ads.type; // undefined, "preroll", "midroll", or "postroll"
// this property is somewhat duplicative of info that is already exposed by the plugin
// you could figure out the type of ad yourself something like this:
var adType = function(player) {
if (player.ads.snapshot.currentTime < 0.1) {
return "preroll";
} else if (player.ads.snapshot.currentTime < duration - 0.1) {
return "midroll";
try { __flash__toXML(videojs.players["vjs_video_3"].trigger("adsready")) ; } catch (e) { "<undefined/>"; }
@dmlap
dmlap / videojs-hls.cpuprofile
Last active August 29, 2015 13:59
A Javascript profile run in Chrome 33/OS X running the video.js HLS plugin. The majority of the time is idle but note the percentage spent in `vjs_play` <- `currentTime` <- `K`.
{"head":{"functionName":"(root)","scriptId":"0","url":"","lineNumber":0,"columnNumber":0,"hitCount":0,"callUID":102868226,"children":[{"functionName":"(program)","scriptId":"0","url":"","lineNumber":0,"columnNumber":0,"hitCount":3905,"callUID":411222278,"children":[],"deoptReason":"","id":2},{"functionName":"(idle)","scriptId":"0","url":"","lineNumber":0,"columnNumber":0,"hitCount":163271,"callUID":1234597172,"children":[],"deoptReason":"","id":3},{"functionName":"e","scriptId":"6371","url":"http://localhost:9999/node_modules/video.js/dist/video-js/video.js","lineNumber":13,"columnNumber":34,"hitCount":3,"callUID":3864617514,"children":[{"functionName":"(anonymous function)","scriptId":"6371","url":"http://localhost:9999/node_modules/video.js/dist/video-js/video.js","lineNumber":49,"columnNumber":434,"hitCount":1,"callUID":1247461525,"children":[{"functionName":"t.buffered","scriptId":"6371","url":"http://localhost:9999/node_modules/video.js/dist/video-js/video.js","lineNumber":54,"columnNumber":20,"hitCount"
@dmlap
dmlap / appendbuffer-perf.md
Last active August 29, 2015 13:58
Results from performance testing methods of converting a UInt8Array into a base64-encoded string in Firefox 28/OS X.

Control:

Bytes Appends Elapsed Milliseconds
1000 10000 2898
1000 10000 2898
1000 10000 2899

Converting the Uint8Array to a "binary string" with String.fromCharCode and then using btoa:

@dmlap
dmlap / gist:9808865
Created March 27, 2014 14:33
Trigger `play()` based on a message from a parent page.
videojs.plugin('iframePlay', function(options) {
var player = this;
options = options || {};
window.addEventListener('message', function(event) {
if (!options.origin || options.origin === event.origin && event.data === 'play') {
player.play();
}
});
});
@dmlap
dmlap / version.sh
Created December 3, 2013 23:11
A quick versioning script for video.js that un-ignores the dist directory, commits a release, and then cleans up the dist directory afterwards.
#! /bin/sh
# stop immediately if any errors are encountered
set -o errexit
if [ "$#" -ne 1 ]; then
echo "Usage: version.sh [<newversion> | major | minor | patch | build]"
exit 1
fi
@dmlap
dmlap / analytics-player-config
Last active December 27, 2015 00:29
A minimal player configuration that include the Brigthcove analytics plugin.
{
"media": {
"sources": [
{
"src": "http://vjs.zencdn.net/v/oceans.mp4",
"type": "video/mp4"
}
],
"width": "240vh",
"height": "41.6667vw",
@dmlap
dmlap / gist:7140421
Created October 24, 2013 16:30
Send an ajax request with an arraybuffer response
var req = new XMLHttpRequest();
req.open('GET', segmentUrl, true);
req.responseType = 'arraybuffer';
req.onload = function(response) {
self.onSegmentLoadComplete(new Uint8Array(req.response));
};
req.send(null);
@dmlap
dmlap / gist:6066087
Created July 23, 2013 20:56
Test case for the `ended` event on Android for Chrome. Running this example should pop up an alert dialog when the video finishes but it does not on Android 4.0.4 with Chrome 28.0.1500.94 on an HTC One X
<!doctype html>
<html>
<head>
<title>No ended event on Android Chrome</title>
</head>
<video width=600 height=300 src="http://vjs.zencdn.net/v/oceans.mp4" controls>
<script>
var video = document.querySelector('video');
video.addEventListener('ended', function() {
alert('ended');
@dmlap
dmlap / tiny-video.html
Created May 24, 2013 13:44
A ~1kB MP4 embedded into a video tag as a data URI.
<!doctype html>
<html>
<head>
<title>A Very Tiny MP4</title>
</head>
<body>
<video src="data:video/mp4;base64,AAAAIGZ0eXBpc29tAAACAGlzb21pc28yYXZjMW1wNDEAAAAIZnJlZQAAAr9tZGF0AAACoAYF//+c3EXpvebZSLeWLNgg2SPu73gyNjQgLSBjb3JlIDEyNSAtIEguMjY0L01QRUctNCBBVkMgY29kZWMgLSBDb3B5bGVmdCAyMDAzLTIwMTIgLSBodHRwOi8vd3d3LnZpZGVvbGFuLm9yZy94MjY0Lmh0bWwgLSBvcHRpb25zOiBjYWJhYz0xIHJlZj0zIGRlYmxvY2s9MTowOjAgYW5hbHlzZT0weDM6MHgxMTMgbWU9aGV4IHN1Ym1lPTcgcHN5PTEgcHN5X3JkPTEuMDA6MC4wMCBtaXhlZF9yZWY9MSBtZV9yYW5nZT0xNiBjaHJvbWFfbWU9MSB0cmVsbGlzPTEgOHg4ZGN0PTEgY3FtPTAgZGVhZHpvbmU9MjEsMTEgZmFzdF9wc2tpcD0xIGNocm9tYV9xcF9vZmZzZXQ9LTIgdGhyZWFkcz02IGxvb2thaGVhZF90aHJlYWRzPTEgc2xpY2VkX3RocmVhZHM9MCBucj0wIGRlY2ltYXRlPTEgaW50ZXJsYWNlZD0wIGJsdXJheV9jb21wYXQ9MCBjb25zdHJhaW5lZF9pbnRyYT0wIGJmcmFtZXM9MyBiX3B5cmFtaWQ9MiBiX2FkYXB0PTEgYl9iaWFzPTAgZGlyZWN0PTEgd2VpZ2h0Yj0xIG9wZW5fZ29wPTAgd2VpZ2h0cD0yIGtleWludD0yNTAga2V5aW50X21pbj0yNCBzY2VuZWN1dD00MCBpbnRyYV9yZWZyZXNoPTAgcmNfbG9va2FoZWFkPTQwIHJjPWNyZiBtYnRyZWU9MSBjcmY9MjMuMCBxY29tcD0wLjYwIHFwbWluPTAgcXBtYX