# How to code streams events on server side API

**URL:** <https://community.wowza.com/t/how-to-code-streams-events-on-server-side-api/667>\
**Category:** Wowza Streaming Engine\
**Created:** [June 22, 2009, 3:30pm UTC](https://community.wowza.com/t/how-to-code-streams-events-on-server-side-api/667 "2009-06-22T15:30:17Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/community.wowza.com/system/32/447_2.png) [@system](https://community.wowza.com/u/system)\
**Post date:** [June 22, 2009, 3:30pm UTC](https://community.wowza.com/t/how-to-code-streams-events-on-server-side-api/667/1 "2009-06-22T15:30:17Z")

</div>

I actually code events OnAppStart, OnConnect, OnDisconnect but i dont find how to code streams events. In log i have information that events are triggered but i don’t know how to code these events… Any Clue ?

INFO stream create - -

INFO stream publish test2 -

INFO stream stop movie-test.flv -

INFO stream destroy movie-test.flv -

INFO stream stop movie-test.flv -

Thank You

---

<div class="post-metadata">

**Author:** ![Richard\_Lanham](https://avatars.discourse-cdn.com/v4/letter/r/c68b51/32.png) [@Richard\_Lanham](https://community.wowza.com/u/Richard_Lanham)\
**Post date:** [June 22, 2009, 6:36pm UTC](https://community.wowza.com/t/how-to-code-streams-events-on-server-side-api/667/2 "2009-06-22T18:36:57Z")

</div>

You can use IMediaStreamActionNotify2 interface. Take a look at this [post](https://www.wowza.com/forums/showthread.php?p=20888#post20888).

Richard

---

<div class="post-metadata">

**Author:** ![Richard\_Lanham](https://avatars.discourse-cdn.com/v4/letter/r/c68b51/32.png) [@Richard\_Lanham](https://community.wowza.com/u/Richard_Lanham)\
**Post date:** [June 22, 2009, 8:21pm UTC](https://community.wowza.com/t/how-to-code-streams-events-on-server-side-api/667/3 "2009-06-22T20:21:29Z")

</div>

```auto
package com.wowza.wms.example.module;

import com.wowza.wms.amf.AMFPacket;
import com.wowza.wms.application.WMSProperties;
import com.wowza.wms.module.*;
import com.wowza.wms.stream.IMediaStream;
import com.wowza.wms.stream.IMediaStreamActionNotify2;

public class ModuleMediaStreamActionNotify2Example extends ModuleBase {
	
	public void onStreamCreate(IMediaStream stream) {
		getLogger().info("onStreamCreate by: " + stream.getClientId());
		IMediaStreamActionNotify2 actionNotify = new StreamListener();
		
		WMSProperties props = stream.getProperties();
		synchronized(props)
		{
			props.put("streamActionNotifier", actionNotify);
		}
		stream.addClientListener(actionNotify);
	}
	public void onStreamDestroy(IMediaStream stream) {
		getLogger().info("onStreamDestroy by: " + stream.getClientId());
		
		IMediaStreamActionNotify2 actionNotify = null;
		WMSProperties props = stream.getProperties();
		synchronized(props)
		{
			actionNotify = (IMediaStreamActionNotify2)stream.getProperties().get("streamActionNotifier");
		}
		if (actionNotify != null)
		{
			stream.removeClientListener(actionNotify);
			getLogger().info("removeClientListener: "+stream.getSrc());
		}
	}
	
	class StreamListener implements IMediaStreamActionNotify2 
	{
		public void onPlay(IMediaStream stream, String streamName, double playStart, double playLen, int playReset) 
		{
			streamName = stream.getName();
			getLogger().info("Stream Name: " + streamName);
		}
		
		public void onMetaData(IMediaStream stream, AMFPacket metaDataPacket) 
		{
			getLogger().info("onMetaData By: " + stream.getClientId());
		}
		
		public void onPauseRaw(IMediaStream stream, boolean isPause, double location) 
		{
			getLogger().info("onPauseRaw By: " + stream.getClientId());
		}

		public void onSeek(IMediaStream stream, double location)
		{
			getLogger().info("onSeek");
		}
		
		public void onStop(IMediaStream stream)
		{
			getLogger().info("onStop By: " + stream.getClientId());
		}
		
		public void onUnPublish(IMediaStream stream, String streamName, boolean isRecord, boolean isAppend)
		{
			getLogger().info("onUNPublish");
		}

		public void onPublish(IMediaStream stream, String streamName, boolean isRecord, boolean isAppend)
		{
			getLogger().info("onPublish");
		}
		public void onPause(IMediaStream stream, boolean isPause, double location)
		{
			getLogger().info("onPause");
		}
	}
}

```

---

<div class="post-metadata">

**Author:** ![Richard\_Lanham](https://avatars.discourse-cdn.com/v4/letter/r/c68b51/32.png) [@Richard\_Lanham](https://community.wowza.com/u/Richard_Lanham)\
**Post date:** [December 28, 2009, 7:10pm UTC](https://community.wowza.com/t/how-to-code-streams-events-on-server-side-api/667/4 "2009-12-28T19:10:35Z")

</div>

It’s the lifetime of the stream. The listener is added to the stream when it is created and removed when it is destroyed.

Each listener is stored in the property container of the stream it is handling, separately.

Richard

---

<div class="post-metadata">

**Author:** ![Pedro\_Alves](https://avatars.discourse-cdn.com/v4/letter/p/3d9bf3/32.png) [@Pedro\_Alves](https://community.wowza.com/u/Pedro_Alves)\
**Post date:** [June 22, 2009, 5:05pm UTC](https://community.wowza.com/t/how-to-code-streams-events-on-server-side-api/667/5 "2009-06-22T17:05:52Z")

</div>

> You can use IMediaStreamActionNotify2 interface. Take a look at this [post](https://www.wowza.com/forums/showthread.php?p=20888#post20888).
> 
> Richard

i am using wowza 1.7.0… Your tip generates the following error:

_ERROR server comment - invoke(onStreamCreate): java.lang.NoClassDefFoundError: com/moebius/moebius$1StreamActionNotifier: com.moebius.moebius.onStreamCreate(moebius.java:338)_

_java.lang.NoClassDefFoundError: com/moebius/moebius$1StreamActionNotifier_

_at com.moebius.moebius.onStreamCreate(moebius.java:338)_

The line 338 is:

_IMediaStreamActionNotify streamActionNotifier = new StreamActionNotifier();_

---

<div class="post-metadata">

**Author:** ![Pedro\_Alves](https://avatars.discourse-cdn.com/v4/letter/p/3d9bf3/32.png) [@Pedro\_Alves](https://community.wowza.com/u/Pedro_Alves)\
**Post date:** [June 22, 2009, 6:00pm UTC](https://community.wowza.com/t/how-to-code-streams-events-on-server-side-api/667/6 "2009-06-22T18:00:48Z")

</div>

Thank You Richard !!!

---

<div class="post-metadata">

**Author:** ![Cristian\_Sfercoci](https://avatars.discourse-cdn.com/v4/letter/c/f0a364/32.png) [@Cristian\_Sfercoci](https://community.wowza.com/u/Cristian_Sfercoci)\
**Post date:** [December 28, 2009, 8:53pm UTC](https://community.wowza.com/t/how-to-code-streams-events-on-server-side-api/667/7 "2009-12-28T20:53:15Z")

</div>

> ```auto
> package com.wowza.wms.example.module;
> import com.wowza.wms.amf.AMFPacket;
> import com.wowza.wms.application.WMSProperties;
> import com.wowza.wms.module.*;
> import com.wowza.wms.stream.IMediaStream;
> import com.wowza.wms.stream.IMediaStreamActionNotify2;
> public class ModuleMediaStreamActionNotify2Example extends ModuleBase {
> 	
> public void onStreamCreate(IMediaStream stream) {
> getLogger().info("onStreamCreate by: " + stream.getClientId());
> [B]IMediaStreamActionNotify2 actionNotify = new StreamListener();[/B]
> 		
> WMSProperties props = stream.getProperties();
> synchronized(props)
> {
> [B]props.put("streamActionNotifier", actionNotify);[/B]
> }
> stream.addClientListener(actionNotify);
> }
> public void onStreamDestroy(IMediaStream stream) {
> getLogger().info("onStreamDestroy by: " + stream.getClientId());
> 		
> IMediaStreamActionNotify2 actionNotify = null;
> WMSProperties props = stream.getProperties();
> synchronized(props)
> {
> [B] actionNotify = (IMediaStreamActionNotify2)stream.getProperties().get("streamActionNotifier");[/B]
> }
> if (actionNotify != null)
> {
> [B] stream.removeClientListener(actionNotify);[/B]
> getLogger().info("removeClientListener: "+stream.getSrc());
> }
> }
> 	
> class StreamListener implements IMediaStreamActionNotify2 
> {
> public void onPlay(IMediaStream stream, String streamName, double playStart, double playLen, int playReset) 
> {
> streamName = stream.getName();
> getLogger().info("Stream Name: " + streamName);
> }
> 		
> .........
> }
> 
> ```

Just looked over the code above and I see that you instantiate objects and assigned to the same constant,a conclusion would be that listener are assigned but not right removed due String constant. I would be interested to know life cycle of this interface,because I wouldn’t instantiate objects to every client that publish or play a stream.
