I'm trying to get my video files to stream from my local version of flash media server to my instance of a flex application. I'm able to connect to the server and I'm receiving the NetConnection.Connect.Success code from the server. When I debug the application, I'm finding that I'm getting NetStatusEvent objects with the codes: NetStream.Play.Reset and NetStream.Play.Start. And the info object's details property is "sample.flv" which is the video file that I have sitting in my "FMSTesting" applicaiton folder. So my video is in my application folder at: "rtmp://localhost/FMSTesting/sample.flv", and my Flex application outputs to the webroot of the flash media server "http://localhost/FMSTesting/bin-debug/FMSTesting.html"
So I'm not sure if my setup is wrong or not, but I think it's ok because I can connect to the server just fine. I just can't get my stream to play on the Video object. Here's my code, please help if you can. I also attached the code
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init();">
<mx:Script>
<![CDATA[
import mx.core.UIComponent;
import mx.rpc.events.ResultEvent;
import flash.net.NetConnection;
import flash.net.navigateToURL;
import flash.events.NetStatusEvent;
import flash.events.StatusEvent;
import flash.text.TextField;
import flash.net.NetStream;
import flash.media.Video;
public var wrap:UIComponent;
public var nc:NetConnection;
public var ns:NetStream;
public var myVid:Video;
public function init():void{
nc = new NetConnection();
nc.addEventListener(NetStatusEvent.NET_STATUS,onConnect);
nc.connect("rtmp://localhost/FMSTesting","bonnetbe");
wrap = new UIComponent();
wrap.x = 10;
wrap.y = 10;
wrap.width =210;
wrap.height = 200;
}
//public function onSayHello(
public function onConnect(event:NetStatusEvent):void{
myText.text = "The connection is "+nc.connected + event.info.code;
switch (event.info.code)
{
case "NetConnection.Connect.Success":
myText.text += ("Congratulations! you're connected" + "\n");
makeVideos();
break;
case "NetConnection.Connect.Rejected":
myText.text += ("Oops! the connection was rejected" + "\n");
break;
case "NetConnection.Connect.Closed":
myText.text += ("Thanks! the connection has been closed" + "\n");
break;
}
}
public function makeVideos():void{
ns = new NetStream(nc);
ns.addEventListener(NetStatusEvent.NET_STATUS,netStatusHandler);
ns.client = this;
ns.play("sample.flv");
myVid = new Video(200,180);
myVid.attachNetStream(ns);
myVid.opaqueBackground = true;
myVid.smoothing = true;
myVid.width = 200;
myVid.height = 180;
wrap.addChild(myVid);
myCanvas.addChild(wrap);
}
public function callClient(event:Event):void{
nc.call("magic",new Responder(myResponder,statusResponder), "World");
nc.call("moreFunc",new Responder(myResponder2,statusResponder2),"benjamin");
//myText.text+= "still connected: "+nc.connected;
}
public function netStatusHandler(event:NetStatusEvent):void{
trace(event);
trace(myVid.videoHeight+" : "+myVid.videoWidth);
}
public function myResponder(result:Object):void{
myText.text += "the result: "+result;
}
public function statusResponder(status:Object):void{
myText.text += "some status: "+status.code;
}
public function myResponder2(result:Object):void{
myText.text += "result2: "+result;
}
public function statusResponder2(status:Object):void{
myText.text += "status 2: "+status.code;
}
public function updateFunc(event:Event):void{
changeText.text = "testing: "+nc.connected;
nc.close();
}
]]>
</mx:Script>
<mx:TextArea id="myText" text="Hello Ben" width="271" height="155" x="311" y="138"/>
<mx:Text x="10" y="192" text="Text" width="144" height="67" id="changeText"/>
<mx:Button x="27" y="378" label="Button" id="funcCall" click="updateFunc(event);"/>
<mx:Button x="135" y="378" label="callFunc" id="callFunc" click="callClient(event);"/>
<mx:Canvas x="311" y="10" width="200" height="120" id="myCanvas"/>
<mx:VideoDisplay x="759" y="62" width="300" height="250" id="vidObj"/>
</mx:Application>
