Brought up to date with the private repository (feea4c7)

This commit is contained in:
S committed 2026-10-14 20:57:33 +03:00
1 parent 1aa738d692
commit 1b1df1ae48
7925 files changed
+2617237 -20

No files matched your search

@@ -0,0 +1,101 @@
package org.osmf.utils
{
import flash.events.NetStatusEvent;
import flash.events.TimerEvent;
import flash.net.NetConnection;
import flash.utils.Timer;
public class FCSubscribeHandler
{
private var maxRetry:Number = 5;
private var currentTry:Number = 0;
private var retryTimer:Timer;
private var nc:NetConnection;
private var owner:Object;
public var nsName:String;
public function FCSubscribeHandler()
{
super();
}
public function run(nsName:String, url:String, owner:Object) : void
{
this.nsName = nsName;
this.owner = owner;
this.nc = new NetConnection();
this.nc.addEventListener(NetStatusEvent.NET_STATUS,this.netConnectHandler);
this.nc.client = this;
this.nc.connect(url);
}
protected function netConnectHandler(event:NetStatusEvent) : void
{
trace("NC: " + event.info.code);
if(event.info.code == "NetConnection.Connect.Success")
{
this.fcSubscribeRetry();
}
else if(event.info.code == "NetStream.Play.UnpublishNotify")
{
trace("publish");
}
else if(event.info.code == "NetStream.Unpublish.Success")
{
trace("unpublish");
}
}
private function fcSubscribeRetry() : void
{
this.retryTimer = new Timer(1000,3);
this.retryTimer.addEventListener(TimerEvent.TIMER_COMPLETE,this.retryFCSubscribe);
this.retryTimer.start();
}
private function retryFCSubscribe(event:TimerEvent) : void
{
if(this.currentTry != this.maxRetry)
{
this.nc.call("FCSubscribe",null,this.nsName);
++this.currentTry;
}
else
{
this.cleanupTimer();
}
}
public function onFCSubscribe(info:Object) : void
{
trace(info.code);
if(info.code != "NetStream.Play.StreamNotFound")
{
if(info.code == "NetStream.Play.Start")
{
this.cleanupTimer();
trace("ready to play");
this.owner.fcSubscribeDone();
}
}
}
public function onFCUnpublish(info:Object) : void
{
trace("hi");
}
private function cleanupTimer() : void
{
this.retryTimer.stop();
this.retryTimer = null;
}
}
}
@@ -0,0 +1,30 @@
package org.osmf.utils
{
import flash.net.URLLoader;
import org.osmf.media.MediaResourceBase;
import org.osmf.traits.LoadTrait;
import org.osmf.traits.LoaderBase;
[ExcludeClass]
public class HTTPLoadTrait extends LoadTrait
{
private var _urlLoader:URLLoader;
public function HTTPLoadTrait(loader:LoaderBase, resource:MediaResourceBase)
{
super(loader,resource);
}
public function get urlLoader() : URLLoader
{
return this._urlLoader;
}
public function set urlLoader(value:URLLoader) : void
{
this._urlLoader = value;
}
}
}
@@ -0,0 +1,115 @@
package org.osmf.utils
{
import flash.errors.IOError;
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.events.SecurityErrorEvent;
import flash.net.URLLoader;
import flash.net.URLRequest;
import org.osmf.events.MediaError;
import org.osmf.events.MediaErrorCodes;
import org.osmf.events.MediaErrorEvent;
import org.osmf.media.MediaResourceBase;
import org.osmf.media.URLResource;
import org.osmf.traits.LoadState;
import org.osmf.traits.LoadTrait;
import org.osmf.traits.LoaderBase;
[ExcludeClass]
public class HTTPLoader extends LoaderBase
{
public function HTTPLoader()
{
super();
}
override public function canHandleResource(resource:MediaResourceBase) : Boolean
{
var urlResource:URLResource = resource as URLResource;
if(urlResource == null || urlResource.url == null || urlResource.url.length <= 0)
{
return false;
}
var url:URL = new URL(urlResource.url);
if(url.protocol.search(/http$|https$/i) == -1 && url.protocol != "")
{
return false;
}
return true;
}
override protected function executeLoad(loadTrait:LoadTrait) : void
{
var urlResource:URLResource;
var urlReq:URLRequest;
var loader:URLLoader = null;
var onLoadComplete:Function = null;
var onIOError:Function = null;
var onSecurityError:Function = null;
var toggleLoaderListeners:Function = function(loader:URLLoader, on:Boolean):void
{
if(on)
{
loader.addEventListener(Event.COMPLETE,onLoadComplete);
loader.addEventListener(IOErrorEvent.IO_ERROR,onIOError);
loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR,onSecurityError);
}
else
{
loader.removeEventListener(Event.COMPLETE,onLoadComplete);
loader.removeEventListener(IOErrorEvent.IO_ERROR,onIOError);
loader.removeEventListener(SecurityErrorEvent.SECURITY_ERROR,onSecurityError);
}
};
onLoadComplete = function(event:Event):void
{
toggleLoaderListeners(loader,false);
var httpLoadTrait:HTTPLoadTrait = loadTrait as HTTPLoadTrait;
httpLoadTrait.urlLoader = loader;
updateLoadTrait(loadTrait,LoadState.READY);
};
onIOError = function(ioEvent:IOErrorEvent, ioEventDetail:String = null):void
{
toggleLoaderListeners(loader,false);
updateLoadTrait(loadTrait,LoadState.LOAD_ERROR);
loadTrait.dispatchEvent(new MediaErrorEvent(MediaErrorEvent.MEDIA_ERROR,false,false,new MediaError(MediaErrorCodes.IO_ERROR,Boolean(ioEvent) ? ioEvent.text : ioEventDetail)));
};
onSecurityError = function(securityEvent:SecurityErrorEvent, securityEventDetail:String = null):void
{
toggleLoaderListeners(loader,false);
updateLoadTrait(loadTrait,LoadState.LOAD_ERROR);
loadTrait.dispatchEvent(new MediaErrorEvent(MediaErrorEvent.MEDIA_ERROR,false,false,new MediaError(MediaErrorCodes.SECURITY_ERROR,Boolean(securityEvent) ? securityEvent.text : securityEventDetail)));
};
updateLoadTrait(loadTrait,LoadState.LOADING);
urlResource = loadTrait.resource as URLResource;
urlReq = new URLRequest(urlResource.url.toString());
loader = this.createURLLoader();
toggleLoaderListeners(loader,true);
try
{
loader.load(urlReq);
}
catch(ioError:IOError)
{
onIOError(null,ioError.message);
}
catch(securityError:SecurityError)
{
onSecurityError(null,securityError.message);
}
}
override protected function executeUnload(loadTrait:LoadTrait) : void
{
updateLoadTrait(loadTrait,LoadState.UNLOADING);
updateLoadTrait(loadTrait,LoadState.UNINITIALIZED);
}
protected function createURLLoader() : URLLoader
{
return new URLLoader();
}
}
}
@@ -0,0 +1,236 @@
package org.osmf.utils
{
import flash.utils.Dictionary;
public class OSMFStrings
{
public static const COMPOSITE_TRAIT_NOT_FOUND:String = "compositeTraitNotFound";
public static const INVALID_PARAM:String = "invalidParam";
public static const NULL_PARAM:String = "nullParam";
public static const FUNCTION_MUST_BE_OVERRIDDEN:String = "functionMustBeOverridden";
public static const ALREADY_ADDED:String = "alreadyAdded";
public static const UNSUPPORTED_MEDIA_ELEMENT_TYPE:String = "unsupportedMediaElementType";
public static const TRAIT_INSTANCE_ALREADY_ADDED:String = "traitInstanceAlreadyAdded";
public static const TRAIT_RESOLVER_ALREADY_ADDED:String = "traitResolverAlreadyAdded";
public static const CAPABILITY_NOT_SUPPORTED:String = "capabilityNotSupported";
public static const MEDIA_LOAD_FAILED:String = "mediaLoadFailed";
public static const MUST_SET_LOADER:String = "mustSetLoader";
public static const LOADER_CANT_HANDLE_RESOURCE:String = "loaderCantHandleResource";
public static const PAUSE_NOT_SUPPORTED:String = "pauseNotSupported";
public static const ALREADY_READY:String = "alreadyReady";
public static const ALREADY_LOADING:String = "alreadyLoading";
public static const ALREADY_UNLOADED:String = "alreadyUnloaded";
public static const ALREADY_UNLOADING:String = "alreadyUnloading";
public static const INVALID_LAYOUT_RENDERER_CONSTRUCTOR:String = "invalidLayoutRendererConstructor";
public static const ILLEGAL_CONSTRUCTOR_INVOCATION:String = "illegalConstructorInvocation";
public static const DIRECT_DISPLAY_LIST_MOD_ERROR:String = "directDisplayListModError";
public static const NULL_SCRIPT_PATH:String = "nullScriptPath";
public static const STREAMSWITCH_INVALID_INDEX:String = "streamSwitchInvalidIndex";
public static const STREAMSWITCH_STREAM_NOT_IN_MANUAL_MODE:String = "streamSwitchStreamNotInManualMode";
public static const DVR_MAXIMUM_RPC_ATTEMPTS:String = "dvrMaximumRPCAttempts";
public static const DVR_UNEXPECTED_SERVER_RESPONSE:String = "dvrUnexpectedServerResponse";
public static const F4M_PARSE_PROFILE_MISSING:String = "f4mProfileMissing";
public static const F4M_PARSE_MEDIA_URL_MISSING:String = "f4mMediaURLMissing";
public static const F4M_PARSE_BITRATE_MISSING:String = "f4mBitrateMissing";
public static const IO_ERROR:String = "ioError";
public static const SECURITY_ERROR:String = "securityError";
public static const ASYNC_ERROR:String = "asyncError";
public static const ARGUMENT_ERROR:String = "argumentError";
public static const URL_SCHEME_INVALID:String = "urlSchemeInvalid";
public static const HTTP_GET_FAILED:String = "httpGetFailed";
public static const PLUGIN_VERSION_INVALID:String = "pluginVersionInvalid";
public static const PLUGIN_IMPLEMENTATION_INVALID:String = "pluginImplementationInvalid";
public static const SOUND_PLAY_FAILED:String = "soundPlayFailed";
public static const NETCONNECTION_REJECTED:String = "netConnectionRejected";
public static const NETCONNECTION_APPLICATION_INVALID:String = "netConnectionApplicationInvalid";
public static const NETCONNECTION_FAILED:String = "netConnectionFailed";
public static const NETCONNECTION_TIMEOUT:String = "netConnectionTimeout";
public static const NETSTREAM_PLAY_FAILED:String = "netStreamPlayFailed";
public static const NETSTREAM_STREAM_NOT_FOUND:String = "netStreamStreamNotFound";
public static const NETSTREAM_FILE_STRUCTURE_INVALID:String = "netStreamFileStructureInvalid";
public static const NETSTREAM_NO_SUPPORTED_TRACK_FOUND:String = "netStreamNoSupportedTrackFound";
public static const DRM_SYSTEM_UPDATE_ERROR:String = "drmSystemUpdateError";
public static const DVRCAST_SUBSCRIBE_FAILED:String = "dvrCastSubscribeFailed";
public static const DVRCAST_CONTENT_OFFLINE:String = "dvrCastContentOffline";
public static const DVRCAST_STREAM_INFO_RETRIEVAL_FAILED:String = "dvrCastStreamInfoRetrievalFailed";
public static const MULTICAST_PARAMETER_INVALID:String = "multicastParameterInvalid";
public static const MULTICAST_NOT_SUPPORT_MBR:String = "multicastNotSupportMBR";
public static const F4M_FILE_INVALID:String = "f4MFileINVALID";
private static const resourceDict:Dictionary = new Dictionary();
private static var _resourceStringFunction:Function = defaultResourceStringFunction;
public static const DRM_METADATA_NOT_SET:String = "drmMetadataNotSet";
resourceDict[COMPOSITE_TRAIT_NOT_FOUND] = "There is no composite trait for the given trait type";
resourceDict[INVALID_PARAM] = "Invalid parameter passed to method";
resourceDict[NULL_PARAM] = "Unexpected null parameter passed to method";
resourceDict[FUNCTION_MUST_BE_OVERRIDDEN] = "Function must be overridden";
resourceDict[ALREADY_ADDED] = "Child has already been added";
resourceDict[UNSUPPORTED_MEDIA_ELEMENT_TYPE] = "The specified media element type is not supported";
resourceDict[TRAIT_INSTANCE_ALREADY_ADDED] = "An instance of this trait class has already been added to this MediaElement";
resourceDict[TRAIT_RESOLVER_ALREADY_ADDED] = "A trait resolver for the specified trait type has already been added to this MediaElement";
resourceDict[CAPABILITY_NOT_SUPPORTED] = "The specified capability is not currently supported";
resourceDict[MEDIA_LOAD_FAILED] = "The loading of a MediaElement failed";
resourceDict[MUST_SET_LOADER] = "Must set LoaderBase on a LoadTrait before calling load or unload";
resourceDict[LOADER_CANT_HANDLE_RESOURCE] = "LoaderBase unable to handle the given MediaResourceBase";
resourceDict[PAUSE_NOT_SUPPORTED] = "PlayTrait.pause cannot be invoked when canPause is false";
resourceDict[ALREADY_READY] = "Loader - attempt to load an already loaded object";
resourceDict[ALREADY_LOADING] = "Loader - attempt to load a loading object";
resourceDict[ALREADY_UNLOADED] = "Loader - attempt to unload an already unloaded object";
resourceDict[ALREADY_UNLOADING] = "Loader - attempt to unload a unloading object";
resourceDict[INVALID_LAYOUT_RENDERER_CONSTRUCTOR] = "Unable to construct LayoutRenderer implementation";
resourceDict[ILLEGAL_CONSTRUCTOR_INVOCATION] = "Use the static getInstance method to obtain a class instance";
resourceDict[DIRECT_DISPLAY_LIST_MOD_ERROR] = "The direct addition or removal of display objects onto a MediaContainer is prohibited.";
resourceDict[NULL_SCRIPT_PATH] = "Operation requires a valid script path";
resourceDict[STREAMSWITCH_INVALID_INDEX] = "Dynamic Stream Switching - Invalid index requested";
resourceDict[STREAMSWITCH_STREAM_NOT_IN_MANUAL_MODE] = "Dynamic Stream Switching - stream is not in manual mode";
resourceDict[DRM_METADATA_NOT_SET] = "Metadata not set on DRMServices";
resourceDict[DVR_MAXIMUM_RPC_ATTEMPTS] = "Maximum DVRGetStreamInfo RPC attempts (%i) reached";
resourceDict[DVR_UNEXPECTED_SERVER_RESPONSE] = "Unexpected server response: ";
resourceDict[F4M_PARSE_PROFILE_MISSING] = "Profile missing from Bootstrap info tag";
resourceDict[F4M_PARSE_MEDIA_URL_MISSING] = "URL missing from Media tag";
resourceDict[F4M_PARSE_BITRATE_MISSING] = "Bitrate missing from Media tag";
resourceDict[IO_ERROR] = "I/O error when loading media";
resourceDict[SECURITY_ERROR] = "Security error when loading media";
resourceDict[ASYNC_ERROR] = "Async error when loading media";
resourceDict[ARGUMENT_ERROR] = "Argument error when loading media";
resourceDict[URL_SCHEME_INVALID] = "Invalid URL scheme";
resourceDict[HTTP_GET_FAILED] = "HTTP GET failed due to a Client Error (4xx Status Code)";
resourceDict[PLUGIN_VERSION_INVALID] = "Plugin failed to load due to version mismatch";
resourceDict[PLUGIN_IMPLEMENTATION_INVALID] = "Plugin failed to load due to improper or missing implementation of PluginInfo";
resourceDict[SOUND_PLAY_FAILED] = "Playback failed due to no sound channels being available";
resourceDict[NETCONNECTION_REJECTED] = "Connection attempt rejected by FMS server";
resourceDict[NETCONNECTION_APPLICATION_INVALID] = "Attempting to connect to an invalid FMS application";
resourceDict[NETCONNECTION_FAILED] = "All NetConnection attempts failed";
resourceDict[NETCONNECTION_TIMEOUT] = "Timed-out trying to establish a NetConnection, or timed out due to an idle NetConnection";
resourceDict[NETSTREAM_PLAY_FAILED] = "Playback failed";
resourceDict[NETSTREAM_STREAM_NOT_FOUND] = "Stream not found";
resourceDict[NETSTREAM_FILE_STRUCTURE_INVALID] = "File has invalid structure";
resourceDict[NETSTREAM_NO_SUPPORTED_TRACK_FOUND] = "No supported track found";
resourceDict[DRM_SYSTEM_UPDATE_ERROR] = "The update of the DRM subsystem failed";
resourceDict[DVRCAST_SUBSCRIBE_FAILED] = "DVRCast subscribe failed";
resourceDict[DVRCAST_CONTENT_OFFLINE] = "DVRCast content is offline and unavailable";
resourceDict[DVRCAST_STREAM_INFO_RETRIEVAL_FAILED] = "Unable to retrieve DVRCast stream info";
resourceDict[MULTICAST_PARAMETER_INVALID] = "The groupspec or streamName is null or empty but not both";
resourceDict[MULTICAST_NOT_SUPPORT_MBR] = "Multicast does not support MBR";
resourceDict[F4M_FILE_INVALID] = "The F4M document contains errors";
resourceDict["missingStringResource"] = "No string for resource {0}";
public function OSMFStrings()
{
super();
}
public static function getString(key:String, params:Array = null) : String
{
return resourceStringFunction(key,params);
}
public static function get resourceStringFunction() : Function
{
return _resourceStringFunction;
}
public static function set resourceStringFunction(value:Function) : void
{
_resourceStringFunction = value;
}
private static function defaultResourceStringFunction(resourceName:String, params:Array = null) : String
{
var value:String = resourceDict.hasOwnProperty(resourceName) ? String(resourceDict[resourceName]) : null;
if(value == null)
{
value = String(resourceDict["missingStringResource"]);
params = [resourceName];
}
if(Boolean(params))
{
value = substitute(value,params);
}
return value;
}
private static function substitute(value:String, ... rest) : String
{
var len:int = 0;
var args:Array = null;
var i:int = 0;
var result:String = "";
if(value != null)
{
result = value;
len = int(rest.length);
if(len == 1 && rest[0] is Array)
{
args = rest[0] as Array;
len = int(args.length);
}
else
{
args = rest;
}
for(i = 0; i < len; i++)
{
result = result.replace(new RegExp("\\{" + i + "\\}","g"),args[i]);
}
}
return result;
}
}
}
@@ -0,0 +1,61 @@
package org.osmf.utils
{
[ExcludeClass]
public class TimeUtil
{
public function TimeUtil()
{
super();
}
public static function parseTime(value:String) : Number
{
var mul:int = 0;
var time:Number = 0;
var a:Array = value.split(":");
if(a.length > 1)
{
time = a[0] * 3600;
time += a[1] * 60;
time += Number(a[2]);
}
else
{
mul = 0;
switch(value.charAt(value.length - 1))
{
case "h":
mul = 3600;
break;
case "m":
mul = 60;
break;
case "s":
mul = 1;
}
if(Boolean(mul))
{
time = Number(value.substr(0,value.length - 1)) * mul;
}
else
{
time = Number(value);
}
}
return time;
}
public static function formatAsTimeCode(sec:Number) : String
{
var h:Number = Math.floor(sec / 3600);
h = isNaN(h) ? 0 : h;
var m:Number = Math.floor(sec % 3600 / 60);
m = isNaN(m) ? 0 : m;
var s:Number = Math.floor(sec % 3600 % 60);
s = isNaN(s) ? 0 : s;
return (h == 0 ? "" : (h < 10 ? "0" + h.toString() + ":" : h.toString() + ":")) + (m < 10 ? "0" + m.toString() : m.toString()) + ":" + (s < 10 ? "0" + s.toString() : s.toString());
}
}
}
@@ -0,0 +1,213 @@
package org.osmf.utils
{
[ExcludeClass]
public class URL
{
private var _rawUrl:String;
private var _protocol:String;
private var _userInfo:String;
private var _host:String;
private var _port:String;
private var _path:String;
private var _query:String;
private var _fragment:String;
public function URL(url:String)
{
super();
this._rawUrl = url;
this._protocol = "";
this._userInfo = "";
this._host = "";
this._port = "";
this._path = "";
this._query = "";
this._fragment = "";
if(this._rawUrl != null && this._rawUrl.length > 0)
{
this._rawUrl = this._rawUrl.replace(/^\s+|\s+$/g,"");
this.parseUrl();
}
}
public function get rawUrl() : String
{
return this._rawUrl;
}
public function get protocol() : String
{
return this._protocol;
}
public function set protocol(value:String) : void
{
if(value != null)
{
this._protocol = value.replace(/:\/?\/?$/,"");
this._protocol = this._protocol.toLowerCase();
}
}
public function get userInfo() : String
{
return this._userInfo;
}
public function set userInfo(value:String) : void
{
if(value != null)
{
this._userInfo = value.replace(/@$/,"");
}
}
public function get host() : String
{
return this._host;
}
public function set host(value:String) : void
{
this._host = value;
}
public function get port() : String
{
return this._port;
}
public function set port(value:String) : void
{
if(value != null)
{
this._port = value.replace(/(:)/,"");
}
}
public function get path() : String
{
return this._path;
}
public function set path(value:String) : void
{
if(value != null)
{
this._path = value.replace(/^\//,"");
}
}
public function get query() : String
{
return this._query;
}
public function set query(value:String) : void
{
if(value != null)
{
this._query = value.replace(/^\?/,"");
}
}
public function get fragment() : String
{
return this._fragment;
}
public function set fragment(value:String) : void
{
if(value != null)
{
this._fragment = value.replace(/^#/,"");
}
}
public function toString() : String
{
return this._rawUrl;
}
public function getParamValue(param:String) : String
{
if(this._query == null)
{
return "";
}
var pattern:RegExp = new RegExp("[/?&]*" + param + "=([^&#]*)","i");
var result:Array = this._query.match(pattern);
return result == null ? "" : result[1];
}
public function get absolute() : Boolean
{
return this.protocol != "";
}
public function get extension() : String
{
var lastDot:int = this.path.lastIndexOf(".");
if(lastDot != -1)
{
return this.path.substr(lastDot + 1);
}
return "";
}
private function parseUrl() : void
{
var oneSlashRegExp:RegExp = null;
var oneSlashResult:Array = null;
var tempUrl:String = null;
var pattern:RegExp = null;
var result:Array = null;
var hostName:String = null;
if(this._rawUrl == null || this._rawUrl.length == 0)
{
return;
}
if(this._rawUrl.search(/:\//) == -1 && this._rawUrl.indexOf(":") != this._rawUrl.length - 1)
{
this.path = this._rawUrl;
}
else
{
oneSlashRegExp = /^(rtmp|rtmp[tse]|rtmpte)(:\/[^\/])/i;
oneSlashResult = this._rawUrl.match(oneSlashRegExp);
tempUrl = this._rawUrl;
if(oneSlashResult != null)
{
tempUrl = this._rawUrl.replace(/:\//,"://localhost/");
}
pattern = /^([a-z+\w\+\.\-]+:\/?\/?)?([^\/?#]*)?(\/[^?#]*)?(\?[^#]*)?(\#.*)?/i;
result = tempUrl.match(pattern);
if(result != null)
{
this.protocol = result[1];
hostName = result[2];
this.path = result[3];
this.query = result[4];
this.fragment = result[5];
pattern = /^([!-~]+@)?([^\/?#:]*)(:[\d]*)?/i;
result = hostName.match(pattern);
if(result != null)
{
this.userInfo = result[1];
this.host = result[2];
this.port = result[3];
}
}
}
}
}
}
@@ -0,0 +1,38 @@
package org.osmf.utils
{
public class Version
{
private static const _major:String = "1";
private static const _minor:String = "5";
private static const FIELD_SEPARATOR:String = ".";
public function Version()
{
super();
}
public static function get version() : String
{
return _major + FIELD_SEPARATOR + _minor;
}
public static function get lastAPICompatibleVersion() : String
{
return "1.0";
}
public static function get FLASH_10_1() : Boolean
{
return true;
}
public static function get LOGGING() : Boolean
{
return false;
}
}
}