JavaScript - - By Sam Deering

Flowplayer sync between 2 live streams

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
Sponsors