无法连接到FMS

时间:2013-03-15 14:49:24

标签: actionscript-3 adobe flash-media-server netconnection

为什么我无法连接?当我运行应用程序时,我在输出中收到NetConnection.failed。你能不能仔细看看我的代码。我相信我的字符串网址是正确的。我不确定我的FMS是否已关闭或者是否存在代码错误。

谢谢

import flash.net.NetConnection;
import flash.events.NetStatusEvent;
import flash.net.NetStream;
import flash.media.Camera;
import flash.media.Video;
import flash.media.Microphone;
import fl.controls.Button;

var nc:NetConnection;
var ns:NetStream;
var cam:Camera;
var microphone:Microphone;
var vid:Video;
var connectButton:Button;

//Connecting to Flash Media Server
nc = new NetConnection();

nc.connect("rtmfp:/fms/streamExample");

nc.addEventListener(NetStatusEvent.NET_STATUS, netHandler);

function netHandler(event:NetStatusEvent):void
{
    switch (event.info.code)
    {
        case "NetConnection.Connect.Success":
        {
            connectButton.label = "Disconnect";
            connectButton.enabled = true;
            sendButton.enabled = true;
            onConnect();
            break;
        }

        case "NetConnection.Connect.Closed":
        {
            connectButton.label = "Connect";
            connectButton.enabled = true;
            sendButton.enabled = false;
            nc.close();
            break;
        }

        case "NetConnection.Connect.Failed":
        {
            trace("Sorry your connection failed");
            break;
        }

        case "NetConnection.Connect.Rejected":
        {
            trace("Oops the connection has been rejected");
            break;
        }
    }
}
ns = new NetStream(nc);

ns.publish("live", "viewing");

ns.attachCamera();


//Setting the video
var vid:Video = new Video();
vid.height = cam.height;
vid.width = cam.width;
vid.x = 10;
vid.y = 10;
addChild(vid);

cam = Camera.getCamera();
cam.setMode(400, 300, 20);
cam.setQuality(0, 85);
cam.setKeyFrameInterval(18);
vid.attachCamera();
addChild(cam);

//Setting the audio
microphone = Microphone.getMicrophone();
microphone.codec = SoundCodec.SPEEX;
microphone.framesPerPacket = 1;
microphone.setSilenceLevel(0, 200);
microphone.gain = 50;
NetStream.attachAudio(microphone);

1 个答案:

答案 0 :(得分:1)

如果您的Flash Media Server与您测试应用程序的计算机位于同一台计算机上,则应使用rtmfp://localhost/streamExample更改服务器的URL 如果您的服务器位于另一台计算机上,则只需将localhost替换为运行该服务器的计算机的IP地址。

在执行NetConnection来电之前,您还应该在connect()上添加事件监听器。

为了帮助您了解失败的原因,您可能还想跟踪事件的描述。

以下是包含所有这些迹象的示例:

nc = new NetConnection();
nc.addEventListener(NetStatusEvent.NET_STATUS, netHandler);
nc.connect("rtmfp:/localhost/streamExample");

function netHandler(event:NetStatusEvent):void
{
    switch (event.info.code)
    {
        case "NetConnection.Connect.Success":
        {
            connectButton.label = "Disconnect";
            connectButton.enabled = true;
            sendButton.enabled = true;
            onConnect();
            break;
        }
        case "NetConnection.Connect.Closed":
        {
            connectButton.label = "Connect";
            connectButton.enabled = true;
            sendButton.enabled = false;
            nc.close();
            break;
        }
        case "NetConnection.Connect.Failed":
        {
            trace("Sorry your connection failed");
            trace("Reason is: " + event.info.description);
            break;
        }
        case "NetConnection.Connect.Rejected":
        {
            trace("Oops the connection has been rejected");
            break;
        }
    }
}