Skip to content

Instantly share code, notes, and snippets.

@dmlap
dmlap / dash-representations.js
Created July 26, 2017 23:23
Retrieve the active DASH representation.
// make sure your player has DASH support:
if (player.dash) {
// print the enabled representation
// this will include a `bandwidth` property if one was specified in the MPD
console.log(player.dash.representations()
.find(function(representation) { return representation.enabled; }));
}
@dmlap
dmlap / fibonnaci.js
Created June 25, 2017 22:45
Recursively generate the Fibonacci sequence. (This loops forever since javascript is eagerly evaluated)
function fibonnaci(n0, n1) {
let n2 = n0 + n1
console.log(n2)
return fibonnaci(n1, n2)
}
@dmlap
dmlap / ads-and-id3.js
Created November 30, 2016 17:09
Pseudo-code for listening to in-band ID3 tags when client-side ads may be active.
var id3Track = null;
// Step 1: listen for in-band metadata tracks to become available for new videos and
// register your listeners
player.on('loadedmetadata', function() {
for (var i = 0; i < player.textTracks().length; i++) {
var track = player.textTracks()[i];
if (track.inBandMetadataTrackDispatchType) {
id3Track = track;
@dmlap
dmlap / reload-source-on-error.md
Last active July 21, 2023 02:05
Basic instructions for the reloadSourceOnError plugin.

Using the reloadSourceOnError Plugin

Call the plugin activate it:

player.reloadSourceOnError()

Now if the player encounters a fatal error during playback, it will automatically attempt to reload the current source. If the error was caused by a transient browser or networking problem, this can allow playback to continue with a minimum of disruption to your viewers.

@dmlap
dmlap / errors-timeout.js
Created November 7, 2016 21:51
Additions to your Brightcove Player configuration to change the timeout error threshold.
// PATCH this into your player configuration to modify the threshold for PLAYER_ERR_TIMEOUT
{
"errors": {
// reduce the timeout value to 30 seconds:
"timeout": 30000
}
}
@dmlap
dmlap / listen-for-events.js
Created August 8, 2016 13:16
Listen (and stop listening) to player events.
var player = videojs('player');
// an event listener is a function that (optionally) takes an event argument
function playingListener(event) {
console.log('Look at me, I know how to listen for video events!', event);
}
// register the event listener
player.on('playing', playingListener);
@dmlap
dmlap / source-buffer-management.md
Last active March 19, 2016 19:58
Associating virtual to real SourceBuffers by examining the kinds of active video and tracks.

Media Configurations

The type, kind, and number of active tracks are enough information to figure out which SourceBuffers need to be active and what data to filter out of transmuxer output before appending.

available streams tracks kinds source buffer mime types
video+audio main video/mp2t
video+audio,audio main,alternative video/mp2t, application/octet-stream;codecs=mp4a
video,audio main,main video/mp2t;codecs=avc1, application/octet-stream;codecs=mp4a
video+audio,video,audio main,alternative,alternative video/mp2t, application/octet-stream;codecs=mp4a

We've started playing a video with multiple discontinuities. The solid line indicates content that has been downloaded and successfully appended to a SourceBuffer. Dotted lines haven't been downloaded yet.

@dmlap
dmlap / eme.json
Last active August 29, 2015 14:21
{
"src": "movie.mpd",
"type":"application/dash+xml",
"keySystemOptions": {
"com.widevine.alpha": {
"licenseUrl": "https://example.com/license"
}
}
}