• How to dynamically control Stream class streams

    Module to control Stream class streams and playlists. Use this module to dynamically create, setup and start live Stream class streams from static and live sources, and add sources to running Streams.

    You can use this module along with the Stream class scheduler. The Streams and Playlists that you set up in the schedule can be modified and controlled using this application.

    A pre-built version of the following module is included in the Wowza Modules Collection

    Code:
    package com.wowza.wms.plugin.collection.module;
    
    import com.wowza.wms.amf.*;
    import com.wowza.wms.client.*;
    import com.wowza.wms.module.*;
    import com.wowza.wms.request.*;
    import com.wowza.wms.stream.publish.*;
    
    public class ModuleStreamControl extends ModuleBase {
    	
    	public void openPlaylistOnStream(IClient client, RequestFunction function,
    			AMFDataList params) {
    		
    		String streamName = getParamString(params, PARAM1);
    		
    		String playlistName = getParamString(params, PARAM2);
    		
    		Stream stream = (Stream)client.getAppInstance().getProperties().getProperty(streamName);
    		
    		Playlist playlist = (Playlist)client.getAppInstance().getProperties().getProperty(playlistName);
    		
    		playlist.open(stream);
    	
    	}
    	public void addItemToPlaylist(IClient client, RequestFunction function,
    			AMFDataList params) {
    
    		AMFDataObj obj = getParamObj(params, PARAM1);
    		
    		Playlist playlist = (Playlist)client.getAppInstance().getProperties().getProperty(obj.getString("playListName"));
    		
    		playlist.addItem(obj.getString("itemName"), obj.getInt("itemStart"), obj.getInt("itemDuration"));	
    	}
    	
    	
    	public void playNextPlaylistItem(IClient client, RequestFunction function,
    			AMFDataList params) {
    
    		String streamName = getParamString(params, PARAM1);
    		
    		Stream stream = (Stream)client.getAppInstance().getProperties().getProperty(streamName);
    		
    		stream.next();
    		
    	}
    	
    	public void addNewStream(IClient client, RequestFunction function,
    			AMFDataList params) {
    		
    		String streamName = getParamString(params, PARAM1);
    		
    		Stream stream = Stream.createInstance(client.getAppInstance(), streamName);
    		
    		client.getAppInstance().getProperties().put(streamName, stream);
    	
    	}
    	
    	public void addNewPlaylist(IClient client, RequestFunction function,
    			AMFDataList params) {
    		
    		String playListName = getParamString(params, PARAM1);
    		
    		Playlist playlist = new Playlist(playListName);
    		
    		playlist.setRepeat(true);
    		
    		client.getAppInstance().getProperties().put(playListName, playlist);
    		
    	}
    	public void stopStream(IClient client, RequestFunction function,
    			AMFDataList params) {
    		
    		String streamName = getParamString(params, PARAM1);
    
    		Stream stream = (Stream)client.getAppInstance().getProperties().remove(streamName);
    		if(stream != null)
    		stream.close();
    		
    	}
    }
    Actionscript 3
    (There is a modified version of the Wowza LiveVideoStreaming player with these commands here: http://www.wowzamedia.com/downloads/...assControl.zip. See below for instructions.)
    Code:
    public function addNewStream():void
    {
    	nc.call("addNewStream",null,streamName.text);			
    }
    public function addNewPlaylist():void
    {
    	nc.call("addNewPlaylist",null,playlist.text);
    }
    
    public function stopStream():void
    {
    	nc.call("stopStream",null,streamName.text);			
    }
    
    public function openPlaylistOnStream():void
    {
    	nc.call("openPlaylistOnStream",null,streamName.text,playlist.text);
    }
    public function nextItem():void
    {
    	nc.call("playNextPlaylistItem",null,streamName.text);
    }
    public function addItemToPlaylist():void
    {
    	var obj:Object = new Object();
    	obj.playListName = playlist.text;
    	obj.itemName = itemName.text;
    	obj.itemStart = itemStart.text;
    	obj.itemDuration = itemDuration.text;
    	nc.call("addItemToPlaylist",null,obj);
    }
    Add this Module last in the list Modules in your Application.xml

    Code:
    <Module>
    <Name>streamcontroller</Name>
    <Description>ModuleStreamControl</Description>
    <Class>com.wowza.wms.plugin.collection.module.ModuleStreamControl</Class>
    </Module>
    You can use this with (or without) the server listener stream scheduler. If this application module is used in the same application that the scheduler populates with Streams and Playlists, you can use this application can be used to control those Streams and Playlists. The association between Playlists and Streams in the scheduler is irrelevant in the application module -- you can start any Playlist on any Stream.

    This is a modified version of Wowza Live Player with these features.

    To operate, use the buttons and textinput below the the video display
    1. Enter a Stream (I filled in "StreamNew"), then click "add stream"
    2. Enter a Playlist (I filled in "playlistNew"), then click "add playlist"
    3. Add at least one item to the playlist (I filled in "mp4:sample.mp4" with start of 0 and length -1), click "add Item to playlist"
    4. Then click "open playlist on stream"
    5. Then in above, enter the streamname, "StreamNew" and click "Play"

    To add a new item, enter a new video name with start and length, and click "add item to playlist", then click open "open playlist on stream again". If the video is currently playing, the new item will start playing after the current one or when it cycles through to the end. You can also click "play next item"

    The Stream Control application module and client provide no feedback or listing of active streams. If you are using with the scheduler you have to know what stream name and playlist name to use.

    To add a live stream to a playlist enter "-2" for Video start. You can mix live streams and static content. You can use MediaCaster streams, but be sure to start them using /conf/StartupStreams.xml or in a application module or server listener using MediaCasterStreamManager.

    I set the buffer to 0 for the playback in the provided client app for the moment. Buffer time in the client is a big factor in what the user sees when streams switch.
    Comments 85 Comments
    1. derrick217 -
      How do you stop a Stream on the Stream class controller. I can start new streams with Stream Class Controller but I can't stop the Streams unless I restart the Wowza Server. I'm trying to stop the streams with the LiveStudio.html example file. The Stop Stream button doesn't appear to work. I continue to see the Stream looped my Server-side playlist that I created but I have no way to stop it. I appreciate you help.

      Thanks

      Derrick
    1. rrlanham -
      I tested and it works for me.

      Richard
    1. arturocalle -
      Quote Originally Posted by derrick217 View Post
      I'm trying to stop the streams with the LiveStudio.html example file. The Stop Stream button doesn't appear to work. I continue to see the Stream looped my Server-side playlist that I created but I have no way to stop it. I appreciate you help.

      I think you have to set "repeat" to false in SMIL list
    1. derrick217 -
      Richard,

      So when you click for example Stop Stream3. It stops and no longer plays at all? Weird It does work on my end. The Stream3 will stop but I continue to see the Stream3 playlist repeating. I'll follow-up the next time I'm working with the Stream controller.

      @arturocalle..I'm not talking about the Server-side playlist with SMIL but the one created with the Stream controller.

      Derrick
    1. rrlanham -
      This Stream Class Controller is a very basic example, a starting point. You should be prepared to dig-in to the client-side and server-side code. There's not that much to it.

      Richard
    1. lslamp -
      Guys,

      I feel so stupid, this looks like what I could use to get my streaming to work with a server side playlist, but I am completely lost as to what or how to do it.
      I see the code in the two top boxes, but do not know where to place the code.

      Am I supposed to copy all the contents in each box and paste it into the Application.xml file?
      Am I supposed to copy all the contents and add them to separate files?

      It might be that I am looking into the wrong places for what I am looking for, but is there a dummies step by step guide that covers explains all.

      Lawrence
    1. rrlanham -
      Lawrence,

      Take a look instead at this schedule example:
      http://www.wowzamedia.com/forums/sho...t-in-smil-file

      The scheduler creates TV programmed content using files, but streamed live. A pre-built version is included with the modules collection:
      http://www.wowzamedia.com/forums/content.php?113

      This is how to do a server-side playlist that is streamed as video on demand
      http://www.wowzamedia.com/forums/con...insert-Midroll

      Richard
    1. VSheyanov -
      There is a little mistake in the stopStream Class.
      I use:
      Stream stream = (Stream)client.getAppInstance().getProperties().ge tProperty(streamName);
      stream.close();

      insted of:
      Stream stream = Stream.createInstance(client.getAppInstance(), streamName);

      I thinks it's not a good idea to create a new instance instead of destroying it
    1. rrlanham -
      Yikes, yes, Roger pointed that out too.... I will update. I have a few things to do for the collection.

      Thanks,
      Richard
    1. jakehilton -
      Do you have to use a playlist with a Stream?.. I'm hoping I can just control and expose a stream outside of a playlist.

      Thanks,
      Jake
    1. rrlanham -
      I guess you are past this question now, Jake. As we have other threads more recent today on Stream class.

      Richard
    1. pellepelle3 -
      How trying to figure out how to add a live stream in .. it says put -2 for the start but what do u put for the playlist item .. for a vod u add eg. flv:videofilename
      but wat do u do for a stream thanks.
    1. rrlanham -
      Put the name of a stream you are publishing to that Wowza application instance, or that you have started using StreamManager. Use the exact name, e.g. "myStream"

      Richard
    1. petko3000 -
      Working like a charm. You guys are doing great job.

      Anyway, is there a way how to manage/switch between streams via shell script (on linux).

      It should work like this: each minute wowza server check some URL for configuration script (via crontab or so). If provided script has been changed from last check, some shell script will be triggered to switch appropriate stream / IPcam feed. This action should be smooth and transparent for connected clients. Nice to have function should be insert adverts between while switch. The result should be TV-like stream.
    1. rrlanham -
      It can be done, using the Stream and Playlist objects and the methods in this example. You would start the process in a ServerListener. Use Wowza HTTPUtils to check the URL.

      Richard
    1. Pytkin -
      How about security .. module works really great .. But everybody from internet can change my stream , edit/add playlists, streams, switch from one playlist, to another ..
    1. rrlanham -
      You can add security

      Richard
    1. killerwake -
      hi, rrlanham

      i'm stuck in situation: when i define the items of a playlist the first item have always reset = true, so i can't append playlists.

      My question is how i append playlists??

      thanks!
    1. killerwake -
      it would be great to have an option like "Playlist.setReset(false);"
    1. rrlanham -
      Manipulating running Playlist object is tricky. Sorry that I don't have input at the moment.

      Richard