如何用Stream类实现一个最基本直播流发布?
转载请注明:文章来自www.wowza.cn
注意: 要访问最新的技术资料,请访问http://www.ttstream.com/wowza/
用Stream类可以实现一个最基本的直播流发布功能,并且可以实现类似电视台的按节目单发布直播流的功能。www.wowza.cn

下面是一个例子展示了如何使用Stream类
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());
		}
	}	
}
www.wowza.cn
将这个server listener添加到/conf/Server.xml的ServerListeners部分:
	<ServerListener>
		<BaseClass>com.wowza.wms.example.serverlistener.StreamPublisherDemo</BaseClass>
	</ServerListener>


播放时,用Stream1或Stream2做流的名字即可