-
Stuck connecting to FMS
Hi, I`m trying to capture video from the webcam and record it on the FMS folder (localhost/vod), but in the nc.connect below, my code won`t connect. I don`t know what I`m doing wrong. Plese tell me what could be or where I should start looking.
Thanks.
Code:
import flash.net.NetStream;
var RTMP:String = "rtmp://localhost/vod";
var nTimer:Number;
var cam:Camera = Camera.getCamera();
//oVideo1 is a linked video in the stage.
oVideo1.attachCamera(cam);
mcRecordInfo.visible = false; //mcRecordInfo is a message that the app is recording
record_mc.buttonMode = true; //record_mc is the button 'record'
record_mc.addEventListener(MouseEvent.CLICK,record);
var nc:NetConnection = new NetConnection();
nc.connect(RTMP);
if (nc.connected == true)
{
trace("Connected");
}
else
{
trace("Didn't connected");
}
var ns:NetStream = new NetStream(nc);
function record(e:MouseEvent):void
{
mcRecordInfo.visible = true;
ns.attachCamera(cam);
ns.publish("demo.flv", "record");
nTimer = setInterval(stopRecording,10000);
}
function stopRecording():void
{
ns.close();
clearInterval(nTimer);
mcRecordInfo.visible = false;
}
-
A NetConnection doesn't connect instantly, odds are when you're checking it hasn't connected yet, but that doesn't mean it's not connecting.
Add a listener for NetStatus events:
Code:
nc.addEventListener(NetStatusEvent.NET_STATUS,_onNetStatus);
And add a function to check whether it's connecting:
Code:
function _onNetStatus(p_event:NetStatusEvent):void {
switch (p_event.info.code) {
case "NetConnection.Connect.Success" :
trace("success!");
break;
case "NetConnection.Connect.Rejected" :
trace("rejected!");
break;
case "NetConnection.Connect.Failed" :
trace("failed!");
break;
}
}
-
OK. First sorry for taking so long to reply and thank you, I did it like this:
Code:
import flash.net.NetStream;
var RTMP:String = "rtmp://localhost/vod";
var nTimer:Number;
var ns:NetStream;
var cam:Camera = Camera.getCamera();
//oVideo1 is a linked video in the stage.
oVideo1.attachCamera(cam);
mcRecordInfo.visible = false;//mcRecordInfo is a message that the app is recording
record_mc.buttonMode = true;//record_mc is the button 'record'
record_mc.addEventListener(MouseEvent.CLICK,record);
var nc:NetConnection = new NetConnection();
nc.connect(RTMP);
nc.addEventListener(NetStatusEvent.NET_STATUS,_onNetStatus);
function _onNetStatus(p_event:NetStatusEvent):void
{
switch (p_event.info.code)
{
case "NetConnection.Connect.Success" :
trace("success!");
ns = new NetStream(nc);
break;
case "NetConnection.Connect.Rejected" :
trace("rejected!");
break;
case "NetConnection.Connect.Failed" :
trace("failed!");
break;
}
}
function record(e:MouseEvent):void
{
mcRecordInfo.visible = true;
ns.attachCamera(cam);
ns.publish("demo.flv", "record");
nTimer = setInterval(stopRecording,10000);
}
function stopRecording():void
{
ns.close();
clearInterval(nTimer);
mcRecordInfo.visible = false;
}
and apparently it worked,
but now it's showing this 'output':
Code:
success!
Error #2044: Unhandled AsyncErrorEvent:. text=Error #2095: flash.net.NetConnection was unable to invoke callback onBWDone. error=ReferenceError: Error #1069: Property onBWDone not found on flash.net.NetConnection and there is no default value.
at Webcam_fla::MainTimeline/frame1()
Error #2044: Unhandled NetStatusEvent:. level=error, code=NetStream.Record.NoAccess
at Webcam_fla::MainTimeline/_onNetStatus()
Do you know what I could be doing wrong?
Thanks in advance.
-
Well onBWDone is a bandwidth check that Flash does when it connects to the RTMP server. The easiest way to handle this is to say
Code:
nc.client=this;
function onBWDone(...args):void
{
trace ( "onBWDone! : " + args );
}
The stuff about no access, I haven't worked with using FMS with webcams before, so I'm not sure if that's coming from the server or from the user's computer.
-
Ok. Thanks for you help, I just kind of got 'lost' in my code so I'm starting from beginning, but I'll probably read this again and ask for help again.
Thank you very much.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|