流媒体技术世界——分享技术,增值服务
如何用Stream类实现一个最基本直播流发布?
用Stream类可以实现一个最基本的直播流发布功能,并且可以实现类似电视台的按节目单发布直播流的功能。了解更多Wowza产品细节

下面是一个例子展示了如何使用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.ttstream.com
将这个server listener添加到/conf/Server.xml的ServerListeners部分:
	<ServerListener>
		<BaseClass>com.wowza.wms.example.serverlistener.StreamPublisherDemo</BaseClass>
	</ServerListener>
播放时,用Stream1或Stream2做流的名字即可


匿名用户
评论

我们的地址


北京市朝阳区管庄西里建基商务楼423室


邮编:100024

关于我们


北京联方信科信息技术有限责任公司


官网:www.ttstream.com

联系我们


王经理:phone


柳经理:phone

京ICP备14033868号-2