Do basic server-side publishing with the Stream class and Wowza Streaming Engine Java API

Use the Stream class to publish live streams using static content. You can also publish on a schedule, like a television station.

This example illustrates basic use of the Stream class:

package com.wowza.wms.example.serverlistener;

import com.wowza.wms.logging.WMSLoggerFactory;
import com.wowza.wms.server.*;
import com.wowza.wms.vhost.*;
import com.wowza.wms.stream.publish.*;
import com.wowza.wms.application.*;

public class StreamPublisherDemo implements IServerNotify2 {

	public void onServerConfigLoaded(IServer server)
	{
	}

	public void onServerCreate(IServer server)
	{
	}

	public void onServerInit(IServer server)
	{
		IVHost vhost = VHostSingleton.getInstance(VHost.VHOST_DEFAULT);
		IApplication app = vhost.getApplication("live");
		IApplicationInstance appInstance = app.getAppInstance("_definst_");

		Stream stream1 = Stream.createInstance(vhost, "live", "Stream1");

		stream1.play("mp4:sample.mp4", 5, 5, true);
		stream1.play("mp4:sample.mp4", 50, 5, false);
		stream1.play("mp4:sample.mp4", 150, 5, false);
		stream1.addListener(new StreamListener(appInstance));

		Stream stream2 = Stream.createInstance(vhost, "live", "Stream2");

		stream2.play("mp4:sample.mp4", 0, -1, true);
		stream2.addListener(new StreamListener(appInstance));

	}

	public void onServerShutdownStart(IServer server)
	{
	}

	public void onServerShutdownComplete(IServer server)
	{
	}

	class StreamListener implements IStreamActionNotify
	{
		StreamListener(IApplicationInstance appInstance)
		{
		}
		public void onPlaylistItemStop(Stream stream, PlaylistItem item)
		{
			WMSLoggerFactory.getLogger(null).info("Item Stopped: " + item.getName() + "on Stream: " + stream.getName());
		}
		public void onPlaylistItemStart(Stream stream, PlaylistItem item) 
		{
			WMSLoggerFactory.getLogger(null).info("Item Started: " + item.getName() + "on Stream: " + stream.getName());
		}
	}
}

Add the server listener to /conf/Server.xml /ServerListeners:

	<ServerListener>
		<BaseClass>com.wowza.wms.example.serverlistener.StreamPublisherDemo</BaseClass>
	</ServerListener>

Create a live application named live (with the StreamType property in the <Streams> container element in [install-dir]/live/Application.xml set to live) if one does not already exist.