• 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
    Code:
    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:
    Code:
    	<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)


    Comments 9 Comments
    1. hockey_dave -
      1. com.wowza.wms.stream.publish.Stream public boolean play(String name, int start, int length, boolean reset) method. start/length parameters are in what units? Your documentation is not clear on this.
      2. How would we add smil files to play list?
      Stream stream2 = Stream .createInstance(vhost, "live", "Stream2");
      video = "smil:dcp.smil/manifest.f4m";
      if(!stream2.play(video, -2, -1, true))
      WMSLoggerFactory.getLoggerObj(vhost).error("failed to add to playlist: "+video);

      returns true that it was added. However, http://&#91;wowza]/wowza/examples/Simple...SMFPlayer.html

      will play this: http://localhost:1935/live/smil:dcp.smil/manifest.f4m

      but not this (returns: Stream not found)
      http://localhost:1935/live/Stream2
    1. rrlanham -
      1) The "start" and "length" parameters are seconds.

      2) I'm not sure what you are asking. Is this what you are looking for?:
      http://www.wowza.com/forums/content....-Multi-bitrate

      Richard
    1. hockey_dave -
      The article shows how you can alias a "Stream1" to a static file: mp4:Extremists.m4v

      What I want to do is to alias "Stream1" to a smil file that contains a switch for variable bit rates. This way my users can connect to Stream1, get routed to xxx.smil. Inside xxx.smil is a switch pointing to 3 streams with low, medium, and high bit rates streams: low.sdp, medium.sdp, and high.sdp

      Thanks.
    1. hockey_dave -
      Not to be a pest, but just wanted to poke again since I posted several questions yesterday on various topics and wanted to make sure that this did not get lost. Anything?
    1. rrlanham -
      "Stream1" in the Stream Class scheduler example is not an alias, it is the name of a live stream that can have a file(s) and published live streams as its source. Think TV station program.

      You could make "Stream1" an alias for a smil file. Take a look at the StreamNameAlias addon:
      http://www.wowza.com/forums/content....e-alias-module

      If you need finer control, use the IMediaStreamNameAliasProvider2 API:
      http://www.wowza.com/forums/content....der2-interface

      Richard
    1. hockey_dave -
      In the 2nd link there is a line: ... this interface instead of the StreamNameAlias package or .stream files when you need programmatic control of aliasing

      Can you please link the ".stream" file word to the documentation describing a .stream file please? The reader (like me) may have no idea what a .stream file is.
    1. rrlanham -
      A .stream file is a plain text file with a .stream extension that is an application's content folder. It may contain an RTSP url to an IP camera, or UDP url to mpegts encoder, or an RTMP url to an origin stream in the form: rtmp://[wowza-address]:/[app-name]/[stream-name]

      Make sure your text editor does not add a .txt extension to the file, it must be a .stream extension and must contain one line.

      Richard
    1. f3209485 -
      Can i pause and resume the published file stream ?
    1. rrlanham -
      You can stop it, then start it again.
      Code:
      stream.close();
      This will trigger unPublish event and notifications to Flash RTMP clients. What affect are you looking for exactly? The JW Player Livestream reconnect plugin might help.

      Richard