2

I'm trying to use the NetConnection class to connect to a live video feed on an external server. I have it set up to start playing my video when the user clicks a Play button, however, this appears in my output every time I click the Play button:

ArgumentError: Error #2126: NetConnection object must be connected. at flash.net::NetStream/ctor() at flash.net::NetStream() at Over/connectLiveStream()[Over::frame2:31]

Any ideas as to why this isn't working? Here is the (I think relevant) code:

 if (playVid.label == "Play") 
 {
  nc = new NetConnection();
      nc.objectEncoding = flash.net.ObjectEncoding.AMF0;
      nc.connect("rtmp://my.rtmp.server:1935/live/");

      nsPlay = new NetStream(nc);
      nsPlay.play("livestream.flv");

 }

Thanks in advance.

1
  • 1
    You should add some event handlers to your nc object to see what is going on with the NetStatusEvent. Commented Oct 12, 2010 at 2:39

1 Answer 1

1

I am copying this from the adobe documentation site:

package {
import flash.display.Sprite;
import flash.events.*;
import flash.media.Video;
import flash.net.NetConnection;
import flash.net.NetStream;

public class NetStatusEventExample extends Sprite {
    private var videoURL:String = "Video.flv";
    private var connection:NetConnection;
    private var stream:NetStream;

    public function NetStatusEventExample() {
        connection = new NetConnection();
        connection.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
        connection.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
        connection.connect(null);
    }

    private function netStatusHandler(event:NetStatusEvent):void {
        switch (event.info.code) {
            case "NetConnection.Connect.Success":
                connectStream();
                break;
            case "NetStream.Play.StreamNotFound":
                trace("Unable to locate video: " + videoURL);
                break;
        }
    }

    private function connectStream():void {
        var stream:NetStream = new NetStream(connection);
        stream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
        stream.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);
        var video:Video = new Video();
        video.attachNetStream(stream);
        stream.play(videoURL);
        addChild(video);
    }

    private function securityErrorHandler(event:SecurityErrorEvent):void {
        trace("securityErrorHandler: " + event);
    }

    private function asyncErrorHandler(event:AsyncErrorEvent):void {
        // ignore AsyncErrorEvent events.
    }

}
}

class CustomClient {
public function onMetaData(info:Object):void {
    trace("metadata: duration=" + info.duration + " width=" + info.width + " height=" + info.height + " framerate=" + info.framerate);
}
public function onCuePoint(info:Object):void {
    trace("cuepoint: time=" + info.time + " name=" + info.name + " type=" + info.type);
}
}

Hope this can help, and if it throws a security error you need to set a crossdomain policy file on the streaming server you connect too.

Links:

Sign up to request clarification or add additional context in comments.

1 Comment

Can you give an example of the connection.connect() parameters here? In your code you're passing null. I'm wondering if the only protocol that is allowed is the rtmp protocol? I hope not because I wanted the server to be GlassFish(java) server...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.