system
June 22, 2009, 3:30pm
1
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
You can use IMediaStreamActionNotify2 interface. Take a look at this post .
Richard
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");
}
}
}
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
You can use IMediaStreamActionNotify2 interface. Take a look at this post .
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();
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.