• How to do basic server-side publishing with Stream class streams

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

    This is a simple example to illustrate the 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 Wowza app named "live", change the Application.xml /StreamType to "live"

    To play open:
    [install-dir]/examples/LiveVideoStreaming/FlashRTMPPlayer/player.html (Wowza Media Server 3.5 and later)
    -or-
    [install-dir]/examples/LiveVideoStreaming/client/live.html (prior version of Wowza Media Server)

    Server: rtmp://[wowza-ip-address]/live
    Stream: Stream1 (or Stream2)


    If you're having problems or want to discuss this article, post in our forum.