How to add a call back to a stream

It has recently been brought to our attention that you can add callbacks to streams that may be useful.

Wowza Streaming Engine allows you to hook up callbacks to streams when the onStreamCreate function is called when a stream is created. The basic function is

	public void onStreamCreate(IMediaStream stream)
	{
	}

You can then add a callback to the stream object. You have two choices here, i) a specific call back registration or ii) a generic registration for all callbacks.

	public void onStreamCreate(IMediaStream stream)
	{
	//stream.registerCallback("onFI", new DataHandler()); // Specific Registration
	//stream.addCalbackListener(new DataHandler()); // For all callbacks
	}

The first method has the first parameter is the call back expected, in our example we are looking for onFI and then the class to handle the callback. The onFI message is received when WireCast or Flash Media Live Encoder have ‘send time codes’ enabled.
The second method allows all callbacks to be processed. This can be useful for debugging however it is best practice to only register the callbacks you are interested in processing.

The below code just outputs the data sent over.

	class DataHandler implements IMediaStreamCallback
	{

		public DataHandler()
		{
		}
		@Override
		public void onCallback(IMediaStream stream, RequestFunction function, AMFDataList params)
		{
			getLogger().info("Params are "+params+"");
		}
		
	}

The output from this code just prints the parameters provided in the callback, but the stream is also provided.


Comments are closed.