Skip to content

Instantly share code, notes, and snippets.

@dmlap
dmlap / gist:3918603
Created October 19, 2012 14:48
Using the event logger with a BC iOS Player
/* Create an event logger for a player. Note how we attach it to the event emitter for a player. You can attach the logger to the catalog's event emitter as well! */
BCEventLogger *playerLogger = [[BCEventLogger alloc]initWithEventEmitter:player.playbackEmitter];
/* If you're in verbose mode, this string will be prepended to all the logging */
[playerLogger setLoggingPrefix:@"Player"];
/* The logger is verbose by default and prints out every event and all the properties of that event. Non-verbose mode just prints out the event name */
playerLogger.verbose = false;
/* We don't recommend leaving this on for "production" code but it can be handy to know what component sent a particular event when debugging. If you add this line, the sender will be printed out as well. */
@dmlap
dmlap / gist:5629805
Created May 22, 2013 18:32
Log out the value of the `src` attribute of a video element.
<!doctype html>
<html>
<head>
<title></title>
</head>
<body>
<video src="http://brightcove.vo.llnwd.net/e1/uds/pd/507017973001/507017973001_1247361339001_shark-1080p.mp4?playerId=558043668001&lineupId=&affiliateId=&pubId=507017973001&videoId=1247311399001"></video>
<script>
var video = document.querySelector('video');
console.log(video.src); // logs the video URL
@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
@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 / 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 / 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 / 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 / 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 / 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 / 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"