我在让我的flex代码工作时遇到了问题,下面是我的代码,我试图对网络摄像头进行网络流传输并接收它,并为此使用2个函数。任何flex大师都可以帮助我修复这些功能?
function onNetConnectionPublish():void {
StatusMessage("onNetConnectionPublish called");
ncNetStream = new NetStream(nc, NetStream.DIRECT_CONNECTIONS);
ncNetStream.addEventListener(NetStatusEvent.NET_STATUS, sendNetStreamHandler);
ncNetStream.publish("media");
ncNetStream.attachAudio(Microphone.getMicrophone());
ncNetStream.attachCamera(Camera.getCamera());
}
和:
function connectToRemote(remoteId:String) {
StatusMessage("connectToRemote(" + remoteId + ")");
ncNetStream = new NetStream(nc, remoteId);
ncNetStream.addEventListener(NetStatusEvent.NET_STATUS, receiveNetStreamHandler);
ncNetStream.play("media");
}
显示视频:
发行商应用程序:
private function Publisher():void{
var camera1:Camera = Camera.getCamera();
var video:Video = new Video(285, 254);
if (camera1)
{
video.attachCamera(camera1);
VideoDisplay1.addChild(video);
camera1.addEventListener(ActivityEvent.ACTIVITY, camera_activity);
camera1.addEventListener(StatusEvent.STATUS, camera_status);
}
var nc:NetConnection = new NetConnection();
nc.connect("rtmp://your/stream/url");
nc.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
function netStatusHandler(event:NetStatusEvent):void {
switch (event.info.code) {
case "NetConnection.Connect.Success":
var ns:NetStream = new NetStream(nc,NetStream.CONNECT_TO_FMS);
ns.attachCamera(camera1);
ns.publish("videofeed", "live");
break;
case "NetStream.Play.StreamNotFound":
trace("Unable to locate video: ");
break;
}
}
}
Reciver应用程序:
import mx.utils.ObjectUtil;
private var nc:NetConnection;
private var ns:NetStream;
private var video:Video;
private var meta:Object;
private function init():void {
var nsClient:Object = {};
nsClient.onMetaData = ns_onMetaData;
nsClient.onCuePoint = ns_onCuePoint;
nc = new NetConnection();
nc.connect(null);
ns = new NetStream(nc);
ns.play("http://www.helpexamples.com/flash/video/cuepoints.flv");
ns.client = nsClient;
video = new Video();
video.attachNetStream(ns);
uic.addChild(video);
}
private function ns_onMetaData(item:Object):void {
trace("meta");
meta = item;
// Resize Video object to same size as meta data.
video.width = item.width;
video.height = item.height;
// Resize UIComponent to same size as Video object.
uic.width = video.width;
uic.height = video.height;
panel.title = "framerate: " + item.framerate;
panel.visible = true;
trace(ObjectUtil.toString(item));
}
private function ns_onCuePoint(item:Object):void {
trace("cue");
}
接收器mxml代码:
<mx:Panel id="panel" visible="false">
<mx:UIComponent id="uic" />
<mx:ControlBar>
<mx:Button label="Play/Pause" click="ns.togglePause();" />
<mx:Button label="Rewind" click="ns.seek(0); ns.pause();" />
</mx:ControlBar>
</mx:Panel>