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

Free Guide:

7 Habits of Successful CTOs

"What makes a great CTO?" Engineering skills? Business savvy? An innate tendency to channel a mythical creature (ahem, unicorn)? All of the above? Discover the top traits of the most successful CTOs in this free guide.

No Reader comments

Recommended
Sponsors
Because We Like You
Free Ebooks!

Grab SitePoint's top 10 web dev and design ebooks, completely free!

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