PDA

View Full Version : RTMP basics


miquael
07-03-2009, 07:21 PM
Hello, I'm a seasoned ActionScript programmer, yet fairly new to Flash video, Flash Media Server, and RTMP.

I've been developing a custom Flash video player, and we now need it to use RTMP with FMS (actually we are using Wowza on www.simpleCDN.com, yet I think it is the same). Despite my attempts, it is not working.

Here is what I have now:

var nc:NetConnection = new NetConnection();
nc.connect("rtmp://e1f1.simplecdn.net/play/");

// alternately, I've tried this too, as SimpleCDN says that you may or may not need "_definst_" depending on the Flash methods:
// nc.connect("rtmp://e1f1.simplecdn.net/play/_definst_/video");

var ns:NetStream = new NetStream(nc);
ns.bufferTime = videoBufferTime;
ns.addEventListener(NetStatusEvent.NET_STATUS, onStatusEvent);

var meta:Object = new Object();

ns.client = meta;
video.attachNetStream(ns);

var st:SoundTransform = new SoundTransform();
ns.soundTransform = st;

// and then later ...

ns.play("mp4:video/test2.mp4");

I get an error when producing the SWF locally:

ArgumentError: Error #2126: NetConnection object must be connected.

(I did not get this error before when doing a (null) connection, and then calling the entire URL by HTTP method for progressive downloading).

When I run it off my web server, the video player acts as if it is broken (probably from having no connection. I don't think it is a firewall problem, because I am running a test right on the simpleCDN server, and they say it should work fine. It must be this AS code!

I don't get it. Why is a connection not being made?

There is a full thread of this also in Adobe forums:

http://forums.adobe.com/thread/456627?tstart=0

bowljoman
07-04-2009, 04:57 PM
The connection is being made, but you make a netstream, before it happens.

THe call to connect, does not block your code.

You need an onstatus event for the netconnection, then you make the netstream.

miquael
07-04-2009, 06:28 PM
Okay - good idea ... yet I am getting a strange error about "onStatus":

"1119: Access of possibly undefined property onStatus through a reference with static type flash.net:NetConnection.

miquael
07-04-2009, 06:29 PM
Huh?

Here is my attempt:

var connectionURL:String = "rtmpt://e1f1.simplecdn.net/play/_definst_";

var nc:NetConnection = new NetConnection();
nc.objectEncoding = ObjectEncoding.AMF3; // AMF0

nc.onStatus = function(infoObject) {

if (infoObject.code == "NetConnection.Connect.Success") {
trace("Successful connection.");
output.text = "Successful connection."
setNetStream();
}

if (infoObject.code == "NetConnection.Connect.Failed") {
trace("Connection failed.");
output.text = "Connection failed."
}
}

nc.connect(connectionURL);


var ns:NetStream;

function setNetStream() {

ns = new NetStream(nc);
ns.bufferTime = videoBufferTime;
ns.addEventListener(NetStatusEvent.NET_STATUS, onStatusEvent);

var meta:Object = new Object();

ns.client = meta;


meta.onMetaData = function(meta:Object) {
// a bunch of stuff in here
}
}

// onStatus for NetStream
function onStatusEvent(e:NetStatusEvent):void {
// a bunch of stuff in here
}

video.attachNetStream(ns);

bowljoman
07-05-2009, 09:53 AM
sd

Use 'Add Event Listener'.



private function makeCon():void
{
trace("makeCon");
nc=new NetConnection();
nc.addEventListener(NetStatusEvent.NET_STATUS,stat );
nc.connect("rtmp://"+m_server.ip+":"+m_server.port+"/application");

}
private function stat(nse:NetStatusEvent):void
{
trace(nse.info.code);
}

miquael
07-07-2009, 09:37 PM
Yes, thank you. I found a similar solution.

It had to do with arranging onStatus events for both the netConnection and the netStream in sequence, so that the NC would be established before trying to create the NS.

It now works very well.

Thanks for your help!!!


:)