JavaScript
Article

Flowplayer sync between 2 live streams

By Sam Deering

This is some code I wrote which attempts to sync between 2 live streams in Flowplayer.

The Code

//@param stream – the name of the Flowplayer video stream object.
Flowplayer.syncStream = function(stream)
{
var syncThreshold = 5; //5 seconds max length between streams

var bufferS1 = Flowplayer.getStatusParam(priv.options.id, ‘bufferEnd’);
console.log(priv.options.stream.name + ‘ Buffer: ‘ + bufferS1 + ‘ seconds.’);

var bufferS2 = Flowplayer.getStatusParam(stream.getId(), ‘bufferEnd’);
console.log(stream.getName() + ‘ Buffer: ‘ + bufferS2 + ‘ seconds.’);

var syncDiff = bufferS2 – bufferS1;
console.log(syncDiff + ‘ seconds diff between streams.’);

if (syncDiff > syncThreshold)
{
console.log(‘attempting to sync streams…’);

//the sync magic
stream.pauseStream();
timeout = setTimeout( function() {
stream.resumeStream();
}, syncDiff);
}
}
[/cc]

Usage

liveVideoFeed.syncStreams();

Monitoring output

//output:

bufferEnd
  2.324

bufferStart
  0

muted
  false

state
  3

time
  3.148

volume
  50

No Reader comments

Recommended

Learn Coding Online
Learn Web Development

Start learning web development and design for free with SitePoint Premium!

Get the latest in JavaScript, once a week, for free.