Wowza Community

ActionScript code to attempt to connect over rtmp and if that fails rtmpt (rollover)

Hi charlie,

Just to to recap on what I wrote before, I have added something very similar to what you have suggested in this thread to your simple as2 player example and most of the time it works really well.

The player is being loaded into a parent swf each time we load a video.

For 99% of our customers it is fine, but sometimes it seems to intermittently be getting to the end of your switch statement and doing what I have set it to do when it cannot connect. That is go to frame 2 which contains and error message.

About 1% of our users have reported that in some cases the video plays for around 5 ses and then the error message is shown.

I think the problem may be specifically happening in Firefox as we have been able to recreate it in ff but it’s not happening everytime.

I also mentioned that it was only happening on our production server not when testing locally.

Hope the problem is clearer now,

Thanks!

Joe

Hi Charlie,

I don’t think it is to do with the code either, we have about 200 people on at the same time sometimes and only have this problem reported about once every couple of days. I think there may be something underlying in the way that the swf is loaded that effects some browsers and it has only become apparent since adding this code as it is skipping to frame 2 and the only point in the code that there is a goToAndStop(2) is here

function tryConnect()

{

clearConnectTimer();

switch(ncTryIndex)

{

case 0:

ncConnectTimeout= 8000

url = ncProtocol + “://”+ncDomain+":"+ncPort+"/"+ncApplication;

trace("tried " + url)

break;

case 1:

ncConnectTimeout= 15000

ncPort = ncPort2;

ncProtocol = ncProtocol2;

url = ncProtocol + “://”+ncDomain+":"+ncPort+"/"+ncApplication;

trace("tried " + url)

break;

default:

{trace(“Failed to connect after “+ncTryIndex+” tries”);

url = “”;

statusBox.text=“failed to connect”;

nc.close();

nc=null;

gotoAndStop(2);

}

break;

}

if (url.length > 0)

{

nc.connect(url);

ncConnectTimer = setInterval(_root, “tryReconnect”, ncConnectTimeout);

}

}

It is definitely starting to play before it moves on to frame 2, as this happened the only time that I managed to recreate it.

I am loading the simple player swf in using the loader component and do it in a few different places in my main swf, but they all use the same simple function and add the video file name as a parameter to url e.g simplePlayer.swf?fileName=

function loadExternalMovie(url:String) {

videoBgLoader._visible = true;

_root.externalMovieLoaded = false;

movieHolder.unloadMovie();

movieHolder._lockroot = true;

var listener:Object = new Object();

listener.onLoadInit = movieLoaded;

movieHolderLoader.addListener(listener);

movieHolderLoader.loadClip(url,movieHolder);

}

Is there any way you can think of that in certain browsers the loader component is caching any information from the last time it loaded that player swf , which would confuse it into thinking it was at a different stage in switch statement or confusing the net connection status’?

I was just wondering if there was anything off the top of your heads you could think of, as I’m finding it very hard to diagnose.

Thanks again,

Joe

I’m using an AS3 player with a version of the rtmp to rtmpt rollover in this thread. It works fine but I’m hearing from a handful of corporate viewers who’s Proxy servers are still blocking the connection. Do the folks at wowza have any documentation or port testing apps to help in these situations?

Thanks!

Im confused where i place this code?

We use flowplayer.

var nc:NetConnection = new NetConnection()
var ncConnectTimer:Number = 0;
var ncConnectTimeout:Number = 3000; // 3 seconds
var ncDomain:String = "localhost";
var ncPort:Number = 443;
var ncApplication:String = "fastplay";
var ncTryIndex:Number = 0;
function init()
{
	nc.onStatus = function(infoObj:Object)
	{
		trace("nc.onStatus: "+infoObj.code);
		if (infoObj.code == "NetConnection.Connect.Success")
			clearConnectTimer();
		else if (infoObj.code == "NetConnection.Connect.Failed")
			tryReconnect();
	}
}
function clearConnectTimer()
{
	if (ncConnectTimer != 0)
		clearInterval(ncConnectTimer);
	ncConnectTimer = 0;
}
function tryConnect()
{
	clearConnectTimer();
	
	var url:String = "";
	switch(ncTryIndex)
	{
		case 0:
			url = "rtmp://"+ncDomain+":"+ncPort+"/"+ncApplication;
			break;
		case 1:
			url = "rtmpt://"+ncDomain+":"+ncPort+"/"+ncApplication;
			break;
		default:
			trace("Failed to connect after "+ncTryIndex+" tries");
			break;
	}
	
	if (url.length > 0)
	{
		nc.connect(url);
		ncConnectTimer = setInterval(_root, "tryReconnect", ncConnectTimeout);
	}
}
function tryReconnect()
{
	trace("tryReconnect");
	clearConnectTimer();
	ncTryIndex++;
	tryConnect();
}
init();
tryConnect();