# onMetaData event not triggered.

**URL:** <https://community.wowza.com/t/onmetadata-event-not-triggered/38027>\
**Category:** Wowza Developer Dojo\
**Tags:** wowza-streaming-server-java-api\
**Created:** [January 19, 2012, 12:25pm UTC](https://community.wowza.com/t/onmetadata-event-not-triggered/38027 "2012-01-19T12:25:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aniruddha\_Deshpande](https://avatars.discourse-cdn.com/v4/letter/a/ac8455/32.png) [@Aniruddha\_Deshpande](https://community.wowza.com/u/Aniruddha_Deshpande)\
**Post date:** [January 19, 2012, 12:25pm UTC](https://community.wowza.com/t/onmetadata-event-not-triggered/38027/1 "2012-01-19T12:25:11Z")

</div>

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:

```auto
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());
		}
	}
}

```

* * *

```auto
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();
    }
}

```

---

<div class="post-metadata">

**Author:** ![Aniruddha\_Deshpande](https://avatars.discourse-cdn.com/v4/letter/a/ac8455/32.png) [@Aniruddha\_Deshpande](https://community.wowza.com/u/Aniruddha_Deshpande)\
**Post date:** [January 24, 2012, 12:58pm UTC](https://community.wowza.com/t/onmetadata-event-not-triggered/38027/2 "2012-01-24T12:58:33Z")

</div>

Hi,

Could someone please look at my code and see what I may be missing? Is there any method in there that is version specific for the WOWZA server?

---

<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:** [January 26, 2012, 12:26am UTC](https://community.wowza.com/t/onmetadata-event-not-triggered/38027/3 "2012-01-26T00:26:00Z")

</div>

Take a look at this example, which shows how to implement IMediaStreamActionNotify2 interface, which includes onMetaData event handler:

[https://www.wowza.com/docs/how-to-use-imediastreamactionnotify3-interface-to-listen-for-rtmp-stream-events-includes-codec-info](https://www.wowza.com/docs/how-to-use-imediastreamactionnotify3-interface-to-listen-for-rtmp-stream-events-includes-codec-info)

Richard
