I can capture all other events but not the injection of metadata. I am certain that the metadata is passed , since the flex AS3 viewer(developed in house) that displays this stream is able to read the metadata from the stream. Here is my module:
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 ModuleStreamStats extends ModuleBase {
public void onStreamCreate(IMediaStream stream) {
getLogger().info("MODULE STREAM STATS 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("MODULE STREAM STATS 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("MODULE STREAM STATS removeClientListener: "+stream.getSrc());
}
}
}
import com.xxxxxx.util.MetadataPropertyUtil;
import com.wowza.util.IOPerformanceCounter;
import com.wowza.wms.amf.AMFPacket;
import com.wowza.wms.application.IApplicationInstance;
import com.wowza.wms.logging.WMSLoggerFactory;
import com.wowza.wms.stream.IMediaStream;
import com.wowza.wms.stream.IMediaStreamActionNotify2;
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
/**
* Created by IntelliJ IDEA.
* User: u0107567
* Date: 1/17/12
* Time: 3:06 PM
* To change this template use File | Settings | File Templates.
*/
public class StreamListener implements IMediaStreamActionNotify2 {
private static String SYNCH_EVENT_LOG_FILE_DIRECTORY = MetadataPropertyUtil.getInstance().getProperty("synch.event.log.file.directory", "c:/temp/pptSynchEvents");
public void onPlay(IMediaStream stream, String streamName, double playStart, double playLen, int playReset) {
streamName = stream.getName();
WMSLoggerFactory.getLogger(null).info("MODULE STREAM STATS Stream Name: " + streamName);
}
public void onMetaData(IMediaStream stream, AMFPacket metaDataPacket) {
WMSLoggerFactory.getLogger(null).info("-------------------------------------------------------");
WMSLoggerFactory.getLogger(null).info("MODULE STREAM STATS INSIDE ON META DATA.......");
WMSLoggerFactory.getLogger(null).info("MODULE STREAM STATS MetaData By: " + stream.getClientId());
WMSLoggerFactory.getLogger(null).info("MODULE STREAM STATS MetaDataProvider: " + stream.getMetaDataProvider());
WMSLoggerFactory.getLogger(null).info("MODULE STREAM STATS MetaDataContent: " + metaDataPacket.getData().toString());
WMSLoggerFactory.getLogger(null).info("-------------------------------------------------------");
try{
Date eventDate = new Date();
writeSynchEventToFile(stream.getName(), "Ani Trial", metaDataPacket.getData().toString(),
Math.round(stream.getElapsedTime().getTime()), eventDate);
WMSLoggerFactory.getLogger(null).debug("MODULE STREAM STATS writeSynchEventToFileAndDatabase() - Stream: "
+ stream.getName() + ", Course Id: Ani Trial Course "
+ ", Page Number: " + metaDataPacket.getData().toString() + ", Elapsed Time: "
+ Math.round(stream.getElapsedTime().getTime()) + ", Date/Time: " + eventDate);
}catch(Exception ex){
WMSLoggerFactory.getLogger(null).error("MODULE STREAM STATS Unable to write synch event to file", ex);
}
}
public void onPauseRaw(IMediaStream stream, boolean isPause, double location) {
WMSLoggerFactory.getLogger(null).info("MODULE STREAM STATS onPauseRaw By: " + stream.getClientId());
}
public void onStop(IMediaStream stream) {
WMSLoggerFactory.getLogger(null).info("MODULE STREAM STATS onStop By: " + stream.getClientId());
}
public void onSeek(IMediaStream stream, double location) { }
public void onUnPublish(IMediaStream stream, String streamName, boolean isRecord, boolean isAppend) { }
public void onPublish(IMediaStream stream, String streamName, boolean isRecord, boolean isAppend) { }
public void onPause(IMediaStream stream, boolean isPause, double location){ }
/**
* Write synch events to local log file (one per course).
* @param streamName
* @param courseId
* @param pageNumber
* @param elapsedSeconds
* @param dateTime
* @throws java.io.IOException
* @throws java.io.FileNotFoundException
*/
private void writeSynchEventToFile(String streamName, String courseId, String pageNumber, int elapsedSeconds, Date dateTime)
throws IOException, FileNotFoundException
{
final SimpleDateFormat sdf = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z");
// Also Write Out Log to Local File (Failsafe)
File logDirectory = new File(SYNCH_EVENT_LOG_FILE_DIRECTORY);
if (!logDirectory.exists())
{
logDirectory.mkdirs();
}
File logFile = new File(logDirectory, "Course" + courseId + ".log");
BufferedWriter writer = new BufferedWriter(new FileWriter(logFile, true)); // Open in Append Mode
writer.write(sdf.format(dateTime) + ": To Page " + pageNumber + " @ " + elapsedSeconds + " ms into stream : " + streamName);
writer.newLine();
writer.close();
}
}