I have been working on a Flex application that sends a feed from my webcam to the Flash Media server. The application connects to the server fine but for some reason the camera is not sending anything to the Media Server. I am pretty sure that the answer to my question is really simple but I need another set of eyes to llok at my code and tell me what I am doing wrong. Any help would be greatly!! GREATLY.. appreciated. I need to keep the little bit of hair I have left! here is the function... thanks again.
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://po9nawn4.rtmphost.com/Application");
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);
ns.attachCamera(camera1);
ns.publish("test", "live");
break;
case "NetStream.Play.StreamNotFound":
trace("Unable to locate video: ");
break;
开发者_如何学JAVA }
}
}
try moving netStatusHandler
outside Publisher
and btw are you connecting to the default FMS app? does fms_adminConsole.swf show your client?
upd :
package {
/**
* ...
* @author www0z0k
*/
import flash.events.NetStatusEvent;
import flash.media.Camera;
import flash.media.Video;
import flash.net.NetConnection;
import flash.net.NetStream;
import flash.display.Sprite;
[SWF(width='400', height='300', frameRate='30')]
public class NewClass extends Sprite {
private var vid:Video;
private var nc:NetConnection;
private var ns:NetStream;
private var baseUrl:String = 'rtmp://192.168.1.100/live';
private var appUrl:String = 'stream1';
private var cam:Camera;
public function NewClass() {
vid = new Video();
addChild(vid);
cam = Camera.getCamera();
vid.attachCamera(cam);
nc = new NetConnection();
nc.addEventListener(NetStatusEvent.NET_STATUS, onStatus);
nc.connect(baseUrl);
}
private function onStatus(e:NetStatusEvent):void {
switch (e.info.code) {
case "NetConnection.Connect.Success":
ns = new NetStream(nc, NetStream.CONNECT_TO_FMS);
ns.attachCamera(cam);
ns.addEventListener(NetStatusEvent.NET_STATUS, onStatus);
ns.publish(appUrl, 'live');
break;
}
}
}
}
works perfect on my dev fms
精彩评论