Now remember, this just fixes my problem with connecting to Akamai (it was a security issue). Your mileage may vary.
The AS file:
Actionscript Code:
class ExtendedNCManager extends NCManager implements INCManager {
private var xml:XML;
private var akamaiHost:String;
private var isAkamai:Boolean
private var _akamaiToken:String
private var _serverNameAkamai:String
public function connectToURL(url:String):Boolean {
//trace("----------------KAPLAN NC MANAGER----------------")
initOtherInfo();
_contentPath = url;
if (_contentPath == null || _contentPath == undefined || _contentPath == "") {
throw new VideoError(VideoError.INVALID_CONTENT_PATH);
}
// parse URL to determine what to do with it
var parseResults:Object = parseURL(_contentPath);
if (parseResults.streamName == undefined || parseResults.streamName == "") {
throw new VideoError(VideoError.INVALID_CONTENT_PATH, url);
}
// connect to either rtmp or http or download and parse smil
if (parseResults.isRTMP) {
// Check to see if we are dealing with an Akamai URL
isAkamai = isAkamaiStreamingURL(url)
if (isAkamai) {
// Check to see if that serverName has already been processed
if (akamaiHost == parseResults.serverName) {
_streamName = _contentPath.slice(_contentPath.indexOf("ondemand/")+9, _contentPath.length);
if (_streamName.slice(-4).toLowerCase() == ".flv") {
_streamName = _streamName.slice(0, -4);
}
// if this hostname is already in use then reuse the existing connection
return true;
} else {
try {
xml = new XML();
xml.ignoreWhite = true;
xml.onLoad = Delegate.create(this, this.xmlOnLoad);
xml.load("http://"+parseResults.serverName+"/fcs/ident");
return false;
} catch (err:Error) {
_nc = undefined;
_owner.ncConnected();
throw err;
}
}
} else {
var canReuse:Boolean = canReuseOldConnection(parseResults);
_isRTMP = true;
_protocol = parseResults.protocol;
_streamName = parseResults.streamName;
_serverName = parseResults.serverName;
_wrappedURL = parseResults.wrappedURL;
_portNumber = parseResults.portNumber;
_appName = parseResults.appName;
if (_appName == undefined || _appName == "" || _streamName == undefined || _streamName == "") {
throw new VideoError(VideoError.INVALID_CONTENT_PATH, url);
}
_autoSenseBW = (_streamName.indexOf(",")>=0);
return (canReuse || connectRTMP());
}
} else {
if (parseResults.streamName.toLowerCase().indexOf(".flv") != -1) {
var canReuse:Boolean = canReuseOldConnection(parseResults);
_isRTMP = false;
_streamName = parseResults.streamName;
return (canReuse || connectHTTP());
}
if (parseResults.streamName.indexOf("/fms/fpad")>=0) {
try {
return connectFPAD(parseResults.streamName);
} catch (err:Error) {
//
}
}
_smilMgr = new SMILManager(this);
return _smilMgr.connectXML(parseResults.streamName);
}
}
private function xmlOnLoad(success:Boolean) {
try {
if (!success) {
_nc = undefined;
_owner.ncConnected();
} else {
var ipNode = xml.firstChild.firstChild;
if (ipNode.nodeName != "ip") {
throw new VideoError(VideoError.INVALID_XML, "URL: \""+_contentPath+"\" did not return a valid XML when queried using IDENT");
} else {
var parseResults:Object = parseURL(_contentPath);
//
_serverNameAkamai = _contentPath.split("://")[1].split("?")[0].split("ondemand")[0]
_akamaiToken = "ondemand?auth=" + _contentPath.split("auth=")[1]
//
akamaiHost = parseResults.serverName;
_isRTMP = true;
_protocol = parseResults.protocol;
_streamName = parseResults.streamName;
_appName = parseResults.appName;
_streamName = _contentPath.slice(_contentPath.indexOf("ondemand/")+9, _contentPath.length);
_serverName = ipNode.firstChild.toString();
_wrappedURL = parseResults.wrappedURL;
_portNumber = parseResults.portNumber;
_appName = "ondemand?_fcs_vhost="+parseResults.serverName;
if (_streamName.slice(-4).toLowerCase() == ".flv") {
_streamName = _streamName.slice(0, -4);
}
//
if (_appName == undefined || _appName == "" || _streamName == undefined || _streamName == "") {
throw new VideoError(VideoError.INVALID_CONTENT_PATH, _contentPath);
}
connectRTMP();
}
}
} catch (err:Error) {
_nc = undefined;
_owner.ncConnected();
throw err;
}
}
private function isAkamaiStreamingURL(url:String):Boolean {
return (url.toLowerCase().indexOf("edgefcs.net/") != -1);
}
private function nextConnect():Void {
//
clearInterval(_tryNCIntervalId);
_tryNCIntervalId = 0;
var protocol:String;
var port:String;
if (_connTypeCounter == 0) {
protocol = _protocol;
port = _portNumber;
} else {
port = null;
if (_protocol == "rtmp:/") {
protocol = "rtmpt:/";
} else if (_protocol == "rtmpe:/") {
protocol = "rtmpte:/";
} else {
_tryNC.pop();
return;
}
}
//
if (isAkamai == true) {
var xnURL:String = protocol + "/" + _serverNameAkamai + _akamaiToken
} else {
var xnURL:String = protocol + ((_serverName == undefined) ? "" : "/" + _serverName + ((port == null) ? "" : (":" + port)) + "/") + ((_wrappedURL == undefined) ? "" : _wrappedURL + "/") + _appName;
}
//
_tryNC[_connTypeCounter].pending = true;
_tryNC[_connTypeCounter].connect( xnURL, _autoSenseBW);
if (_connTypeCounter < (_tryNC.length-1)) {
_connTypeCounter++;
_tryNCIntervalId = setInterval(this, "nextConnect", 1500);
}
}
}
The code to include in the FLA:
Actionscript Code:
var __forceExtendedNCManager:ExtendedNCManager;
mx.video.VideoPlayer.DEFAULT_INCMANAGER = "ExtendedNCManager"
I must say that this type of thing is MUCH easier to figure out in AS3. I've done my AS2 work for the week. Enough.