By default, the player will show a message when a Brid Livestream is not live at the moment.
If you want to set up your player to automatically start the moment a Brid Livestream goes live, you can add the following code to your player and bind it to the ready player event:
function waitForStream(stream, player) {
clearInterval(window.livestreamCheckIntervalID);
window.livestreamCheckIntervalID = setInterval(function(){
console.log('Check stream...');
checkIfStreamActive(stream, player);
}, 5000);
}
function checkIfStreamActive(stream, player) {
if (player.livestreamRestartInitiated) return;
var xhr = new XMLHttpRequest();
xhr.open('GET', stream, true);
xhr.onload = function (e) {
if (xhr.readyState === 4 && xhr.status === 200 && xhr.responseText.indexOf('RESOLUTION=')>0) {
restartStream(stream, player);
}
}
xhr.send(null);
}
function restartStream(stream, player) {
console.log('Player restart stream', stream);
if (Brid.Util.getChildByClass(player.el, 'brid-dialog-content')){
player.el.removeChild(Brid.Util.getChildByClass(player.el, 'brid-dialog-content'));
player.message = null;
}
if (player.livestreamRestartInitiated) return;
player.livestreamRestartInitiated = true;
player.currentSource.src = stream;
player.currentSource.error = false;
player.hasPreroll = false;
player.start();
clearInterval(window.livestreamCheckIntervalID);
}
var streamUrl = this.currentSource.src;
this.add('livestreamstopped', function() {
this.livestreamRestartInitiated = null;
waitForStream(streamUrl, this);
}.bind(this));
Example of a working implementation can be found on this link - demo.brid.tv
Comments
0 comments
Please sign in to leave a comment.