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());
}
}
}
Code:
<ServerListener> <BaseClass>com.wowza.wms.example.serverlistener.StreamPublisherDemo</BaseClass> </ServerListener>
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)
- Click here, if you are having problems or would like to discuss this article.
- Leave a comment below, if there is some aspect of this article you would like to see changed or improved.


Article List
Categories
Wowza Media