• How to switch streams using Stream class streams

    This example shows a way to use the Stream class to switch between different stream sources. Instead of switching between items in a playlist, this technique uses multiple Playlist objects each with only one item. One Stream is created, the switching is from Playlist to Playlist. Switching is very fast using this method.

    In this example there are 3 sources that can be switched

    • IP Camera: axis.stream
    • Live encoder: myStream
    • File: sample.mp4

    Note: The axis.stream file is a text file in the content folder that contains the RSTP URL to the camera. It should be started in StreamManager with MediaCaster type rtp or with /conf/StartUpStreams.xml to use it in this switch set.
    package com.wowza.wms.example.module;
    import com.wowza.wms.amf.*;
    import com.wowza.wms.application.*;
    import com.wowza.wms.client.*;
    import com.wowza.wms.module.*;
    import com.wowza.wms.request.*;
    import com.wowza.wms.stream.publish.Playlist;
    import com.wowza.wms.stream.publish.Stream;
    public class ModuleStreamSwitch extends ModuleBase {
    	public void switchPlaylist(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);
    	public void onAppStart(IApplicationInstance appInstance) {
    		appInstance.startMediaCasterStream("axis.stream", "rtp");
    		String streamName = "Stream1";
    		Playlist playlist1 = new Playlist("pl1");	
    		Playlist playlist2 = new Playlist("pl2");
    		Playlist playlist3 = new Playlist("pl3");
    		playlist1.addItem("myStream", -2, -1);
    		playlist2.addItem("axis.stream", -2, -1);
    		playlist3.addItem("mp4:sample.mp4", 0, -1);
    		Stream stream = Stream.createInstance(appInstance, streamName);
    		appInstance.getProperties().setProperty(streamName, stream);
    		appInstance.getProperties().setProperty(playlist1.getName(), playlist1);
    		appInstance.getProperties().setProperty(playlist2.getName(), playlist2);
    		appInstance.getProperties().setProperty(playlist3.getName(), playlist3);
    	public void onAppStop(IApplicationInstance appInstance) {
    Build this module in the Wowza IDE, then create a Wowza module named live with StreamType live and add this Module last in the Application.xml Modules list:
    To call this from a Flash application:
    // later

    Originally Published: 06-27-2011.

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