1

なぜ接続できないのですか?アプリケーションを実行すると、出力にNetConnection.failedが表示されます。私のコードを注意深く見てください。文字列のURLは正しいと思います。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);
4

1 に答える 1

1

Flash Media Serverがアプリケーションのテスト元のマシンと同じマシン上にある場合は、サーバーのURLを次のように変更する必要があります。サーバーが別のマシン上にある場合は、サーバーを実行しているマシンのIPアドレスrtmfp://localhost/streamExample に置き換える必要があります。localhostサーバ。

また、呼び出し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;
        }
    }
}
于 2013-03-20T01:49:12.037 に答える