Skip to content

Local Overrides Sample: Network Delay Triggers Video Restart

bp2008 edited this page Dec 18, 2022 · 5 revisions

This sample causes the video stream to be restarted if network delay grows beyond a specific amount. This sample requires UI3-113 or newer due to the use of a new API method: videoPlayer.GetPlayerObject()

To learn more about ui3-local-overrides, see: Local Overrides Scripts and Styles

Put in ui3-local-overrides.js

// UI3 Local Overrides Sample - Network Delay Triggers Video Restart
var maximumNetworkDelay = 3000; // milliseconds
setInterval(function ()
{
	var h264_player = videoPlayer.GetPlayerObject();
	if (h264_player)
	{
		if (h264_player.GetNetworkDelay() > maximumNetworkDelay)
		{
			console.log("Refreshing video stream because of high network delay");
			videoPlayer.RefreshVideoStream();
		}
	}
}, 1000);

Alternative script, restarts if either player delay or network delay are past the limit.

// UI3 Local Overrides Sample - Network Delay Triggers Video Restart
var maximumNetworkDelay = 3000; // milliseconds
setInterval(function ()
{
	var h264_player = videoPlayer.GetPlayerObject();
	if (h264_player)
	{
		if (h264_player.GetNetworkDelay() > maximumNetworkDelay || h264_player.GetBufferedTime() > maximumNetworkDelay)
		{
			console.log("Refreshing video stream because of high network delay");
			videoPlayer.RefreshVideoStream();
		}
	}
}, 1000);
Clone this wiki locally