Wowza Community

How many seconds user was watching video?

Hello,

I’d like to implement my own statistics sytem. I’m using this code to count how many seconds user was watching video but my tests are different then reality. For example i’m watching video and shutdown player in 10 sec. but logs show me then I was watching video 15 sec. I tested this module in RTMP, RTSP na HLS streaming but always result are bad. How can I solve this problem? Maybe someone has better method to do this?

Example below:

public void onStreamDestroy(IMediaStream stream)
	{
		getLogger().info("onStreamDestroy() - invoked");
		
		IOPerformanceCounter perf = stream.getMediaIOPerformance();
		
		Long outbytes = perf.getMessagesOutBytes();
		getLogger().info("Outbytes: " + outbytes);
		
		Double outrate = perf.getMessagesOutBytesRate();
		getLogger().info("OutRate: " + outrate);
		
		Double seconds = outbytes / outrate;
		getLogger().info("Seconds: " + seconds);	
		
	}

After 10 sec logs show:

INFO server comment - Outbytes: 2526989
INFO server comment - OutRate: 80634.0
INFO server comment - Seconds: 31.339000917727013

It’s 21 sec. mistake.

If you are looking to obtain information on a given session/client connection, you might review our serverinfo HTTP Provider source code as a starting point. There are even elapsed time and time running related functions that could be of use on a per connection basis.

You might try eliminating the global variable for iClient and utilizing the following:

stream.getClient().getElapsedTime().getTimeSeconds()

Alternatively, it may prove more precise to check this within the onDisconnect event as follows:

 public void onDisconnect(IClient client) {
  getLogger().info("onDisconnect: " + client.getElapsedTime().getTimeSeconds());
 }

Hi!

Wowza Wrench has a feature that allows you to measure the elapsed time per user. It also uses client.getElapsedTime().getTimeSeconds() under the hood. When I was investigating time differences, I found that maybe connections are administered periodically in Wowza and that’s why there is a varying difference between the time you see and the time the client object reports. There are some idle* settings in VHost.xml which might have effect on this. Would be good to get some official explanation on the inaccuracy we both saw.

Hi,

Can you explain why can may it be more precise withing onDisconnect…? And why we are seeing difference between the time we measure and what the client object reports…?

I tried use ElapsedTimer:

public void onStreamDestroy(IMediaStream stream) {
		getLogger().info("Seconds: " + iClient.getElapsedTime().getTimeSeconds());
}

but result is also wrong.