{
nc = new NetConnection();
nc.connect("rtmp://localhost/LiveStreams");
nc.addEventListener(NetStatusEvent.NET_STATUS,onNetStatusHandler);
}
{
trace(evt.info.code);
if(evt.info.code=="NetConnection.Connect.Success")
{
ns=new NetStream(nc);
ns.addEventListener(NetStatusEvent.NET_STATUS,onNetStatusHandler);
ns.client=new CustomClient();
ns.attachCamera(cam);
ns.attachAudio(mic);
ns.publish(txtInput.text,"live");
}
}
{
btnPublish.label="发布视频";
btnPublish.addEventListener(MouseEvent.CLICK,onPublishClick);
//获取视频和声音,并将视频显示到Flash界面
cam = Camera.getCamera();
mic = Microphone.getMicrophone();
video = new Video(320,240);
video.attachCamera(cam);
video.x=20;
video.y=20;
addChild(video);
}
{
import flash.net.*;
import flash.events.*;
import flash.display.*;
import flash.media.*;
import fl.controls.*;
public class PublishStream extends Sprite
{
private var video:Video;
private var nc:NetConnection;
private var ns:NetStream;
private var cam:Camera;
private var mic:Microphone;
public function PublishStream():void
{
btnPublish.label="发布视频";
btnPublish.addEventListener(MouseEvent.CLICK,onPublishClick);
//获取视频和声音,并将视频显示到Flash界面
cam = Camera.getCamera();
mic = Microphone.getMicrophone();
video = new Video(320,240);
video.attachCamera(cam);
video.x=20;
video.y=20;
addChild(video);
}
private function onPublishClick(evt:MouseEvent):void
{
nc = new NetConnection();
nc.connect("rtmp://localhost/LiveStreams");
nc.addEventListener(NetStatusEvent.NET_STATUS,onNetStatusHandler);
}
private function onNetStatusHandler(evt:NetStatusEvent):void
{
trace(evt.info.code);
if(evt.info.code=="NetConnection.Connect.Success")
{
ns=new NetStream(nc);
ns.addEventListener(NetStatusEvent.NET_STATUS,onNetStatusHandler);
ns.client=new CustomClient();
ns.attachCamera(cam);
ns.attachAudio(mic);
ns.publish(txtInput.text,"live");
}
}
}
}
{
import flash.net.*;
import flash.events.*;
import flash.display.*;
import flash.media.*;
public class LiveStream extends Sprite
{
private var video:Video;
private var nc:NetConnection;
private var ns:NetStream;
public function LiveStream():void
{
nc = new NetConnection();
nc.connect("rtmp://localhost/LiveStreams");
nc.addEventListener(NetStatusEvent.NET_STATUS,onNetStatusHandler);
}
private function onNetStatusHandler(evt:NetStatusEvent):void
{
if(evt.info.code=="NetConnection.Connect.Success")
{
ns=new NetStream(nc);
ns.addEventListener(NetStatusEvent.NET_STATUS,onNetStatusHandler);
ns.client=new CustomClient();
video=new Video();
video.attachNetStream(ns);
ns.play("1111");//1111为流的名字,对应于视频流发布端的publish("1111","live").
addChild(video);
}
}
}
}