mirror of
https://github.com/burrow-dev/burrow-server.git
synced 2026-11-20 17:37:50 -05:00
Brought up to date with the private repository (feea4c7)
This commit is contained in:
1 parent
1aa738d692
commit
1b1df1ae48
7925 files changed
+2617237
-20
No files matched your search
@@ -0,0 +1,34 @@
|
||||
package org.osmf.captioning
|
||||
{
|
||||
import org.osmf.captioning.media.CaptioningProxyElement;
|
||||
import org.osmf.media.MediaElement;
|
||||
import org.osmf.media.MediaFactoryItem;
|
||||
import org.osmf.media.MediaFactoryItemType;
|
||||
import org.osmf.media.PluginInfo;
|
||||
import org.osmf.net.NetLoader;
|
||||
|
||||
public class CaptioningPluginInfo extends PluginInfo
|
||||
{
|
||||
|
||||
public static const CAPTIONING_METADATA_NAMESPACE:String = "http://www.osmf.org/captioning/1.0";
|
||||
|
||||
public static const CAPTIONING_METADATA_KEY_URI:String = "uri";
|
||||
|
||||
public static const CAPTIONING_TEMPORAL_METADATA_NAMESPACE:String = "http://www.osmf.org/temporal/captioning";
|
||||
|
||||
public function CaptioningPluginInfo()
|
||||
{
|
||||
var items:Vector.<MediaFactoryItem> = new Vector.<MediaFactoryItem>();
|
||||
var loader:NetLoader = new NetLoader();
|
||||
var item:MediaFactoryItem = new MediaFactoryItem("org.osmf.captioning.CaptioningPluginInfo",loader.canHandleResource,this.createCaptioningProxyElement,MediaFactoryItemType.PROXY);
|
||||
items.push(item);
|
||||
super(items);
|
||||
}
|
||||
|
||||
private function createCaptioningProxyElement() : MediaElement
|
||||
{
|
||||
return new CaptioningProxyElement();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
package org.osmf.captioning.loader
|
||||
{
|
||||
import org.osmf.captioning.model.CaptioningDocument;
|
||||
import org.osmf.media.MediaResourceBase;
|
||||
import org.osmf.traits.LoadTrait;
|
||||
import org.osmf.traits.LoaderBase;
|
||||
|
||||
public class CaptioningLoadTrait extends LoadTrait
|
||||
{
|
||||
|
||||
private var _document:CaptioningDocument;
|
||||
|
||||
public function CaptioningLoadTrait(loader:LoaderBase, resource:MediaResourceBase)
|
||||
{
|
||||
super(loader,resource);
|
||||
}
|
||||
|
||||
public function get document() : CaptioningDocument
|
||||
{
|
||||
return this._document;
|
||||
}
|
||||
|
||||
public function set document(value:CaptioningDocument) : void
|
||||
{
|
||||
this._document = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
package org.osmf.captioning.loader
|
||||
{
|
||||
import org.osmf.captioning.model.CaptioningDocument;
|
||||
import org.osmf.captioning.parsers.DFXPParser;
|
||||
import org.osmf.captioning.parsers.ICaptioningParser;
|
||||
import org.osmf.events.LoaderEvent;
|
||||
import org.osmf.events.MediaErrorEvent;
|
||||
import org.osmf.media.MediaResourceBase;
|
||||
import org.osmf.traits.LoadState;
|
||||
import org.osmf.traits.LoadTrait;
|
||||
import org.osmf.traits.LoaderBase;
|
||||
import org.osmf.utils.HTTPLoadTrait;
|
||||
import org.osmf.utils.HTTPLoader;
|
||||
|
||||
public class CaptioningLoader extends LoaderBase
|
||||
{
|
||||
|
||||
private var httpLoader:HTTPLoader;
|
||||
|
||||
public function CaptioningLoader(httpLoader:HTTPLoader = null)
|
||||
{
|
||||
super();
|
||||
this.httpLoader = httpLoader != null ? httpLoader : new HTTPLoader();
|
||||
}
|
||||
|
||||
override public function canHandleResource(resource:MediaResourceBase) : Boolean
|
||||
{
|
||||
return this.httpLoader.canHandleResource(resource);
|
||||
}
|
||||
|
||||
override protected function executeLoad(loadTrait:LoadTrait) : void
|
||||
{
|
||||
var httpLoadTrait:HTTPLoadTrait = null;
|
||||
var onHTTPLoaderStateChange:Function = null;
|
||||
var onLoadError:Function = null;
|
||||
onHTTPLoaderStateChange = function(event:LoaderEvent):void
|
||||
{
|
||||
var parser:ICaptioningParser = null;
|
||||
var captioningDocument:CaptioningDocument = null;
|
||||
if(event.newState == LoadState.READY)
|
||||
{
|
||||
httpLoader.removeEventListener(LoaderEvent.LOAD_STATE_CHANGE,onHTTPLoaderStateChange);
|
||||
httpLoadTrait.removeEventListener(MediaErrorEvent.MEDIA_ERROR,onLoadError);
|
||||
parser = createCaptioningParser();
|
||||
try
|
||||
{
|
||||
captioningDocument = parser.parse(httpLoadTrait.urlLoader.data.toString());
|
||||
}
|
||||
catch(e:Error)
|
||||
{
|
||||
updateLoadTrait(loadTrait,LoadState.LOAD_ERROR);
|
||||
}
|
||||
CaptioningLoadTrait(loadTrait).document = captioningDocument;
|
||||
updateLoadTrait(loadTrait,LoadState.READY);
|
||||
}
|
||||
else if(event.newState == LoadState.LOAD_ERROR)
|
||||
{
|
||||
httpLoader.removeEventListener(LoaderEvent.LOAD_STATE_CHANGE,onHTTPLoaderStateChange);
|
||||
updateLoadTrait(loadTrait,event.newState);
|
||||
}
|
||||
};
|
||||
onLoadError = function(event:MediaErrorEvent):void
|
||||
{
|
||||
httpLoadTrait.removeEventListener(MediaErrorEvent.MEDIA_ERROR,onLoadError);
|
||||
loadTrait.dispatchEvent(event.clone());
|
||||
};
|
||||
updateLoadTrait(loadTrait,LoadState.LOADING);
|
||||
this.httpLoader.addEventListener(LoaderEvent.LOAD_STATE_CHANGE,onHTTPLoaderStateChange);
|
||||
httpLoadTrait = new HTTPLoadTrait(this.httpLoader,loadTrait.resource);
|
||||
httpLoadTrait.addEventListener(MediaErrorEvent.MEDIA_ERROR,onLoadError);
|
||||
this.httpLoader.load(httpLoadTrait);
|
||||
}
|
||||
|
||||
override protected function executeUnload(loadTrait:LoadTrait) : void
|
||||
{
|
||||
updateLoadTrait(loadTrait,LoadState.UNLOADING);
|
||||
updateLoadTrait(loadTrait,LoadState.UNINITIALIZED);
|
||||
}
|
||||
|
||||
protected function createCaptioningParser() : ICaptioningParser
|
||||
{
|
||||
return new DFXPParser();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+139
@@ -0,0 +1,139 @@
|
||||
package org.osmf.captioning.media
|
||||
{
|
||||
import org.osmf.captioning.CaptioningPluginInfo;
|
||||
import org.osmf.captioning.loader.CaptioningLoadTrait;
|
||||
import org.osmf.captioning.loader.CaptioningLoader;
|
||||
import org.osmf.captioning.model.Caption;
|
||||
import org.osmf.captioning.model.CaptioningDocument;
|
||||
import org.osmf.elements.ProxyElement;
|
||||
import org.osmf.events.LoadEvent;
|
||||
import org.osmf.events.MediaError;
|
||||
import org.osmf.events.MediaErrorEvent;
|
||||
import org.osmf.media.MediaElement;
|
||||
import org.osmf.media.MediaResourceBase;
|
||||
import org.osmf.media.URLResource;
|
||||
import org.osmf.metadata.Metadata;
|
||||
import org.osmf.metadata.TimelineMetadata;
|
||||
import org.osmf.traits.LoadState;
|
||||
import org.osmf.traits.LoadTrait;
|
||||
import org.osmf.traits.MediaTraitType;
|
||||
|
||||
public class CaptioningProxyElement extends ProxyElement
|
||||
{
|
||||
|
||||
public static const MEDIA_ERROR_INVALID_PROXIED_ELEMENT:int = 2201;
|
||||
|
||||
private static const ERROR_MISSING_CAPTION_METADATA:String = "Media Element is missing Captioning metadata";
|
||||
|
||||
private static const ERROR_MISSING_RESOURCE:String = "Media Element is missing a valid resource";
|
||||
|
||||
private var loadTrait:CaptioningLoadTrait;
|
||||
|
||||
private var _continueLoadOnFailure:Boolean;
|
||||
|
||||
public function CaptioningProxyElement(proxiedElement:MediaElement = null, continueLoadOnFailure:Boolean = true)
|
||||
{
|
||||
super(proxiedElement);
|
||||
this._continueLoadOnFailure = continueLoadOnFailure;
|
||||
}
|
||||
|
||||
public function get continueLoadOnFailure() : Boolean
|
||||
{
|
||||
return this._continueLoadOnFailure;
|
||||
}
|
||||
|
||||
override public function set proxiedElement(value:MediaElement) : void
|
||||
{
|
||||
var mediaElement:MediaElement = null;
|
||||
var tempResource:MediaResourceBase = null;
|
||||
var metadata:Metadata = null;
|
||||
var timedTextURL:String = null;
|
||||
super.proxiedElement = value;
|
||||
if(value != null)
|
||||
{
|
||||
mediaElement = super.proxiedElement;
|
||||
tempResource = Boolean(mediaElement) && mediaElement.resource != null ? mediaElement.resource : resource;
|
||||
if(tempResource == null)
|
||||
{
|
||||
dispatchEvent(new MediaErrorEvent(MediaErrorEvent.MEDIA_ERROR,false,false,new MediaError(MEDIA_ERROR_INVALID_PROXIED_ELEMENT)));
|
||||
}
|
||||
else
|
||||
{
|
||||
metadata = tempResource.getMetadataValue(CaptioningPluginInfo.CAPTIONING_METADATA_NAMESPACE) as Metadata;
|
||||
if(metadata == null)
|
||||
{
|
||||
if(!this._continueLoadOnFailure)
|
||||
{
|
||||
dispatchEvent(new MediaErrorEvent(MediaErrorEvent.MEDIA_ERROR,false,false,new MediaError(MEDIA_ERROR_INVALID_PROXIED_ELEMENT)));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
timedTextURL = metadata.getValue(CaptioningPluginInfo.CAPTIONING_METADATA_KEY_URI);
|
||||
if(timedTextURL != null)
|
||||
{
|
||||
this.loadTrait = new CaptioningLoadTrait(new CaptioningLoader(),new URLResource(timedTextURL));
|
||||
this.loadTrait.addEventListener(LoadEvent.LOAD_STATE_CHANGE,this.onLoadStateChange,false,99);
|
||||
addTrait(MediaTraitType.LOAD,this.loadTrait);
|
||||
}
|
||||
else if(!this._continueLoadOnFailure)
|
||||
{
|
||||
dispatchEvent(new MediaErrorEvent(MediaErrorEvent.MEDIA_ERROR,false,false,new MediaError(MEDIA_ERROR_INVALID_PROXIED_ELEMENT)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function onLoadStateChange(event:LoadEvent) : void
|
||||
{
|
||||
var document:CaptioningDocument = null;
|
||||
var mediaElement:MediaElement = null;
|
||||
var captionMetadata:TimelineMetadata = null;
|
||||
var i:int = 0;
|
||||
var caption:Caption = null;
|
||||
if(event.loadState == LoadState.READY)
|
||||
{
|
||||
document = this.loadTrait.document;
|
||||
if(Boolean(document))
|
||||
{
|
||||
mediaElement = super.proxiedElement;
|
||||
captionMetadata = proxiedElement.getMetadata(CaptioningPluginInfo.CAPTIONING_TEMPORAL_METADATA_NAMESPACE) as TimelineMetadata;
|
||||
if(captionMetadata == null)
|
||||
{
|
||||
captionMetadata = new TimelineMetadata(proxiedElement);
|
||||
proxiedElement.addMetadata(CaptioningPluginInfo.CAPTIONING_TEMPORAL_METADATA_NAMESPACE,captionMetadata);
|
||||
}
|
||||
for(i = 0; i < document.numCaptions; i++)
|
||||
{
|
||||
caption = document.getCaptionAt(i);
|
||||
captionMetadata.addMarker(caption);
|
||||
}
|
||||
}
|
||||
this.cleanUp();
|
||||
}
|
||||
else if(event.loadState == LoadState.LOAD_ERROR)
|
||||
{
|
||||
if(!this._continueLoadOnFailure)
|
||||
{
|
||||
dispatchEvent(event.clone());
|
||||
}
|
||||
else
|
||||
{
|
||||
this.cleanUp();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function cleanUp() : void
|
||||
{
|
||||
removeTrait(MediaTraitType.LOAD);
|
||||
var loadTrait:LoadTrait = getTrait(MediaTraitType.LOAD) as LoadTrait;
|
||||
if(loadTrait != null && loadTrait.loadState == LoadState.UNINITIALIZED)
|
||||
{
|
||||
loadTrait.load();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
package org.osmf.captioning.model
|
||||
{
|
||||
import flash.errors.IllegalOperationError;
|
||||
import org.osmf.metadata.TimelineMarker;
|
||||
import org.osmf.utils.OSMFStrings;
|
||||
|
||||
public class Caption extends TimelineMarker
|
||||
{
|
||||
|
||||
private var _id:uint;
|
||||
|
||||
private var _captionText:String;
|
||||
|
||||
private var _formats:Vector.<CaptionFormat>;
|
||||
|
||||
public function Caption(id:uint, start:Number, end:Number, captionText:String)
|
||||
{
|
||||
var duration:Number = end > 0 ? end - start : NaN;
|
||||
super(start,duration);
|
||||
this._id = id;
|
||||
this._captionText = captionText;
|
||||
}
|
||||
|
||||
public function addCaptionFormat(value:CaptionFormat) : void
|
||||
{
|
||||
if(this._formats == null)
|
||||
{
|
||||
this._formats = new Vector.<CaptionFormat>();
|
||||
}
|
||||
this._formats.push(value);
|
||||
}
|
||||
|
||||
public function get numCaptionFormats() : int
|
||||
{
|
||||
var num:int = 0;
|
||||
if(this._formats != null)
|
||||
{
|
||||
num = int(this._formats.length);
|
||||
}
|
||||
return num;
|
||||
}
|
||||
|
||||
public function getCaptionFormatAt(index:int) : CaptionFormat
|
||||
{
|
||||
if(this._formats == null || index >= this._formats.length || index < 0)
|
||||
{
|
||||
throw new IllegalOperationError(OSMFStrings.getString(OSMFStrings.INVALID_PARAM));
|
||||
}
|
||||
return this._formats[index];
|
||||
}
|
||||
|
||||
public function get text() : String
|
||||
{
|
||||
return this._captionText;
|
||||
}
|
||||
|
||||
public function get clearText() : String
|
||||
{
|
||||
var clrTxt:String = "";
|
||||
if(this._captionText != null && this._captionText.length > 0)
|
||||
{
|
||||
clrTxt = this._captionText.replace(/<(.|\n)*?>/g,"");
|
||||
}
|
||||
return clrTxt;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
package org.osmf.captioning.model
|
||||
{
|
||||
public class CaptionFormat
|
||||
{
|
||||
|
||||
public static const UNDEFINED_INDEX:int = -1;
|
||||
|
||||
private static const MISSING_STYLE_ERROR_MSG:String = "CaptionStyle is required for CaptionFormat objects";
|
||||
|
||||
private var _startIndex:int;
|
||||
|
||||
private var _endIndex:int;
|
||||
|
||||
private var _style:CaptionStyle;
|
||||
|
||||
public function CaptionFormat(style:CaptionStyle, start:int = -1, end:int = -1)
|
||||
{
|
||||
super();
|
||||
if(style == null)
|
||||
{
|
||||
throw new ArgumentError(MISSING_STYLE_ERROR_MSG);
|
||||
}
|
||||
this._startIndex = start;
|
||||
this._endIndex = end;
|
||||
this._style = style;
|
||||
}
|
||||
|
||||
public function get startIndex() : int
|
||||
{
|
||||
return this._startIndex;
|
||||
}
|
||||
|
||||
public function get endIndex() : int
|
||||
{
|
||||
return this._endIndex;
|
||||
}
|
||||
|
||||
public function get style() : CaptionStyle
|
||||
{
|
||||
return this._style;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,140 @@
|
||||
package org.osmf.captioning.model
|
||||
{
|
||||
public class CaptionStyle
|
||||
{
|
||||
|
||||
private var _id:String;
|
||||
|
||||
private var _backgroundColor:Object;
|
||||
|
||||
private var _backgroundColorAlpha:Object;
|
||||
|
||||
private var _textColor:Object;
|
||||
|
||||
private var _textColorAlpha:Object;
|
||||
|
||||
private var _fontFamily:String;
|
||||
|
||||
private var _fontSize:int;
|
||||
|
||||
private var _fontStyle:String;
|
||||
|
||||
private var _fontWeight:String;
|
||||
|
||||
private var _textAlign:String;
|
||||
|
||||
private var _wrapOption:Boolean;
|
||||
|
||||
public function CaptionStyle(id:String)
|
||||
{
|
||||
super();
|
||||
this._id = id;
|
||||
}
|
||||
|
||||
public function get id() : String
|
||||
{
|
||||
return this._id;
|
||||
}
|
||||
|
||||
public function get backgroundColor() : Object
|
||||
{
|
||||
return this._backgroundColor;
|
||||
}
|
||||
|
||||
public function set backgroundColor(value:Object) : void
|
||||
{
|
||||
this._backgroundColor = value;
|
||||
}
|
||||
|
||||
public function get backgroundColorAlpha() : Object
|
||||
{
|
||||
return this._backgroundColorAlpha;
|
||||
}
|
||||
|
||||
public function set backgroundColorAlpha(value:Object) : void
|
||||
{
|
||||
this._backgroundColorAlpha = value;
|
||||
}
|
||||
|
||||
public function get textColor() : Object
|
||||
{
|
||||
return this._textColor;
|
||||
}
|
||||
|
||||
public function set textColor(value:Object) : void
|
||||
{
|
||||
this._textColor = value;
|
||||
}
|
||||
|
||||
public function get textColorAlpha() : Object
|
||||
{
|
||||
return this._textColorAlpha;
|
||||
}
|
||||
|
||||
public function set textColorAlpha(value:Object) : void
|
||||
{
|
||||
this._textColorAlpha = value;
|
||||
}
|
||||
|
||||
public function get fontFamily() : String
|
||||
{
|
||||
return this._fontFamily;
|
||||
}
|
||||
|
||||
public function set fontFamily(value:String) : void
|
||||
{
|
||||
this._fontFamily = value;
|
||||
}
|
||||
|
||||
public function get fontSize() : int
|
||||
{
|
||||
return this._fontSize;
|
||||
}
|
||||
|
||||
public function set fontSize(value:int) : void
|
||||
{
|
||||
this._fontSize = value;
|
||||
}
|
||||
|
||||
public function get fontStyle() : String
|
||||
{
|
||||
return this._fontStyle;
|
||||
}
|
||||
|
||||
public function set fontStyle(value:String) : void
|
||||
{
|
||||
this._fontStyle = value;
|
||||
}
|
||||
|
||||
public function get fontWeight() : String
|
||||
{
|
||||
return this._fontWeight;
|
||||
}
|
||||
|
||||
public function set fontWeight(value:String) : void
|
||||
{
|
||||
this._fontWeight = value;
|
||||
}
|
||||
|
||||
public function get textAlign() : String
|
||||
{
|
||||
return this._textAlign;
|
||||
}
|
||||
|
||||
public function set textAlign(value:String) : void
|
||||
{
|
||||
this._textAlign = value;
|
||||
}
|
||||
|
||||
public function get wrapOption() : Boolean
|
||||
{
|
||||
return this._wrapOption;
|
||||
}
|
||||
|
||||
public function set wrapOption(value:Boolean) : void
|
||||
{
|
||||
this._wrapOption = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
package org.osmf.captioning.model
|
||||
{
|
||||
import flash.errors.IllegalOperationError;
|
||||
import org.osmf.utils.OSMFStrings;
|
||||
|
||||
public class CaptioningDocument
|
||||
{
|
||||
|
||||
private var _title:String;
|
||||
|
||||
private var _desc:String;
|
||||
|
||||
private var _copyright:String;
|
||||
|
||||
private var _captions:Vector.<Caption>;
|
||||
|
||||
private var _styles:Vector.<CaptionStyle>;
|
||||
|
||||
public function CaptioningDocument()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public function get title() : String
|
||||
{
|
||||
return this._title;
|
||||
}
|
||||
|
||||
public function set title(value:String) : void
|
||||
{
|
||||
this._title = value;
|
||||
}
|
||||
|
||||
public function get description() : String
|
||||
{
|
||||
return this._desc;
|
||||
}
|
||||
|
||||
public function set description(value:String) : void
|
||||
{
|
||||
this._desc = value;
|
||||
}
|
||||
|
||||
public function get copyright() : String
|
||||
{
|
||||
return this._copyright;
|
||||
}
|
||||
|
||||
public function set copyright(value:String) : void
|
||||
{
|
||||
this._copyright = value;
|
||||
}
|
||||
|
||||
public function addStyle(style:CaptionStyle) : void
|
||||
{
|
||||
if(this._styles == null)
|
||||
{
|
||||
this._styles = new Vector.<CaptionStyle>();
|
||||
}
|
||||
this._styles.push(style);
|
||||
}
|
||||
|
||||
public function get numStyles() : int
|
||||
{
|
||||
var num:int = 0;
|
||||
if(this._styles != null)
|
||||
{
|
||||
num = int(this._styles.length);
|
||||
}
|
||||
return num;
|
||||
}
|
||||
|
||||
public function getStyleAt(index:int) : CaptionStyle
|
||||
{
|
||||
if(this._styles == null || index >= this._styles.length)
|
||||
{
|
||||
throw new IllegalOperationError(OSMFStrings.getString(OSMFStrings.INVALID_PARAM));
|
||||
}
|
||||
return this._styles[index];
|
||||
}
|
||||
|
||||
public function addCaption(caption:Caption) : void
|
||||
{
|
||||
if(this._captions == null)
|
||||
{
|
||||
this._captions = new Vector.<Caption>();
|
||||
}
|
||||
this._captions.push(caption);
|
||||
}
|
||||
|
||||
public function get numCaptions() : int
|
||||
{
|
||||
var num:int = 0;
|
||||
if(this._captions != null)
|
||||
{
|
||||
num = int(this._captions.length);
|
||||
}
|
||||
return num;
|
||||
}
|
||||
|
||||
public function getCaptionAt(index:int) : Caption
|
||||
{
|
||||
if(this._captions == null || index >= this._captions.length)
|
||||
{
|
||||
throw new IllegalOperationError(OSMFStrings.getString(OSMFStrings.INVALID_PARAM));
|
||||
}
|
||||
return this._captions[index];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,500 @@
|
||||
package org.osmf.captioning.parsers
|
||||
{
|
||||
import flash.utils.Dictionary;
|
||||
import org.osmf.captioning.model.Caption;
|
||||
import org.osmf.captioning.model.CaptionFormat;
|
||||
import org.osmf.captioning.model.CaptionStyle;
|
||||
import org.osmf.captioning.model.CaptioningDocument;
|
||||
import org.osmf.utils.TimeUtil;
|
||||
|
||||
public class DFXPParser implements ICaptioningParser
|
||||
{
|
||||
|
||||
private var ns:Namespace;
|
||||
|
||||
private var ttm:Namespace;
|
||||
|
||||
private var tts:Namespace;
|
||||
|
||||
private var rootNamespace:Namespace;
|
||||
|
||||
private var namedColorMap:Dictionary;
|
||||
|
||||
public function DFXPParser()
|
||||
{
|
||||
super();
|
||||
this.namedColorMap = new Dictionary();
|
||||
this.namedColorMap["transparent"] = 0;
|
||||
this.namedColorMap["black"] = 0;
|
||||
this.namedColorMap["silver"] = 12632256;
|
||||
this.namedColorMap["gray"] = 8421504;
|
||||
this.namedColorMap["white"] = 16777215;
|
||||
this.namedColorMap["maroon"] = 8388608;
|
||||
this.namedColorMap["red"] = 16711680;
|
||||
this.namedColorMap["purple"] = 8388736;
|
||||
this.namedColorMap["fuchsia"] = 16711935;
|
||||
this.namedColorMap["magenta"] = 16711935;
|
||||
this.namedColorMap["green"] = 32768;
|
||||
this.namedColorMap["lime"] = 65280;
|
||||
this.namedColorMap["olive"] = 8421376;
|
||||
this.namedColorMap["yellow"] = 16776960;
|
||||
this.namedColorMap["navy"] = 128;
|
||||
this.namedColorMap["blue"] = 255;
|
||||
this.namedColorMap["teal"] = 32896;
|
||||
this.namedColorMap["aqua"] = 65535;
|
||||
this.namedColorMap["cyan"] = 65535;
|
||||
}
|
||||
|
||||
public function parse(rawData:String) : CaptioningDocument
|
||||
{
|
||||
var xml:XML = null;
|
||||
var document:CaptioningDocument = new CaptioningDocument();
|
||||
var saveXMLIgnoreWhitespace:Boolean = Boolean(XML.ignoreWhitespace);
|
||||
var saveXMLPrettyPrinting:Boolean = Boolean(XML.prettyPrinting);
|
||||
var xmlStr:String = rawData.replace(/\s+$/,"");
|
||||
xmlStr = xmlStr.replace(/>\s+</g,"><");
|
||||
XML.ignoreWhitespace = false;
|
||||
XML.prettyPrinting = false;
|
||||
try
|
||||
{
|
||||
xml = new XML(xmlStr);
|
||||
}
|
||||
catch(e:Error)
|
||||
{
|
||||
debugLog("Unhandled exception in DFXPParser : " + e.message);
|
||||
throw e;
|
||||
}
|
||||
finally
|
||||
{
|
||||
XML.ignoreWhitespace = saveXMLIgnoreWhitespace;
|
||||
XML.prettyPrinting = saveXMLPrettyPrinting;
|
||||
}
|
||||
this.rootNamespace = xml.namespace();
|
||||
this.ns = xml.namespace();
|
||||
this.ttm = xml.namespace("ttm");
|
||||
this.tts = xml.namespace("tts");
|
||||
try
|
||||
{
|
||||
this.parseHead(document,xml);
|
||||
this.parseBody(document,xml);
|
||||
}
|
||||
catch(err:Error)
|
||||
{
|
||||
debugLog("Unhandled exception in DFXPParser : " + err.message);
|
||||
throw err;
|
||||
}
|
||||
return document;
|
||||
}
|
||||
|
||||
private function parseHead(doc:CaptioningDocument, xml:XML) : void
|
||||
{
|
||||
var styling:XMLList;
|
||||
var styles:XMLList = null;
|
||||
var i:uint = 0;
|
||||
var styleNode:XML = null;
|
||||
var styleObj:CaptionStyle = null;
|
||||
try
|
||||
{
|
||||
doc.title = xml..this.ttm::title.text();
|
||||
doc.description = xml..this.ttm::desc.text();
|
||||
doc.copyright = xml..this.ttm::copyright.text();
|
||||
}
|
||||
catch(err:Error)
|
||||
{
|
||||
if(err.errorID != 1080)
|
||||
{
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
styling = xml..this.ns::styling;
|
||||
if(Boolean(styling.length()))
|
||||
{
|
||||
styles = styling.children();
|
||||
for(i = 0; i < styles.length(); i++)
|
||||
{
|
||||
styleNode = styles[i];
|
||||
styleObj = this.createStyleObject(styleNode);
|
||||
doc.addStyle(styleObj);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function createStyleObject(styleNode:XML) : CaptionStyle
|
||||
{
|
||||
var colorValue:Object = null;
|
||||
var id:String = styleNode.@id;
|
||||
var styleObj:CaptionStyle = new CaptionStyle(id);
|
||||
var color:String = styleNode.this.tts::@backgroundColor;
|
||||
if(color != "")
|
||||
{
|
||||
colorValue = this.parseColor(color);
|
||||
styleObj.backgroundColor = colorValue.color;
|
||||
styleObj.backgroundColorAlpha = colorValue.alpha;
|
||||
}
|
||||
styleObj.textAlign = styleNode.this.tts::@textAlign;
|
||||
color = styleNode.this.tts::@color;
|
||||
if(color != "")
|
||||
{
|
||||
colorValue = this.parseColor(color);
|
||||
styleObj.textColor = colorValue.color;
|
||||
styleObj.textColorAlpha = colorValue.alpha;
|
||||
}
|
||||
styleObj.fontFamily = this.parseFontFamily(styleNode.this.tts::@fontFamily);
|
||||
var fontSize:String = this.parseFontSize(styleNode.this.tts::@fontSize);
|
||||
styleObj.fontSize = parseInt(fontSize);
|
||||
styleObj.fontStyle = styleNode.this.tts::@fontStyle;
|
||||
styleObj.fontWeight = styleNode.this.tts::@fontWeight;
|
||||
styleObj.wrapOption = String(styleNode.this.tts::@wrapOption).toLowerCase() == "nowrap" ? false : true;
|
||||
return styleObj;
|
||||
}
|
||||
|
||||
private function parseColor(colorStr:String) : Object
|
||||
{
|
||||
var colorValue:Object = null;
|
||||
var alphaValue:Object = null;
|
||||
var pattern:RegExp = /^\s*#([\dA-Fa-f][\dA-Fa-f][\dA-Fa-f][\dA-Fa-f][\dA-Fa-f][\dA-Fa-f])([\dA-Fa-f][\dA-Fa-f])?\s*$/;
|
||||
var result:Array = colorStr.match(pattern);
|
||||
if(result != null)
|
||||
{
|
||||
colorValue = parseInt(result[1],16);
|
||||
if(result.length == 3)
|
||||
{
|
||||
alphaValue = Number(parseInt(result[2]) / 255);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
pattern = /^\s*rgb(a)?\((\d+),(\d+),(\d+)(\)|(,(\d+)\)))\s*$/i;
|
||||
result = colorStr.match(pattern);
|
||||
if(result != null && result.length >= 5)
|
||||
{
|
||||
colorValue = (parseInt(result[2]) << 16) + (parseInt(result[3]) << 8) + parseInt(result[4]);
|
||||
if(result.length == 8 && result[7] != undefined)
|
||||
{
|
||||
alphaValue = Number(parseInt(result[7]) / 255);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
colorValue = this.namedColorMap[colorStr.toLowerCase()];
|
||||
if(colorValue == null)
|
||||
{
|
||||
colorValue = parseInt(colorStr);
|
||||
if(isNaN(int(colorValue)))
|
||||
{
|
||||
colorValue = null;
|
||||
this.debugLog("Invalid DFXP document: invalid color value of " + colorStr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return {
|
||||
"color":colorValue,
|
||||
"alpha":alphaValue
|
||||
};
|
||||
}
|
||||
|
||||
private function parseFontSize(rawFontSize:String) : String
|
||||
{
|
||||
var incRegExp:RegExp = null;
|
||||
var incResult:Object = null;
|
||||
var regExp:RegExp = null;
|
||||
var result:Object = null;
|
||||
if(!rawFontSize || rawFontSize == "")
|
||||
{
|
||||
return "";
|
||||
}
|
||||
var returnValue:String = "";
|
||||
var perRegExp:RegExp = new RegExp(/^\s*\d+%.*$/);
|
||||
var perResult:Object = perRegExp.exec(rawFontSize);
|
||||
if(Boolean(perResult))
|
||||
{
|
||||
this.debugLog("Invalid DFXP document: percentages are not supported for font size.");
|
||||
returnValue = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
incRegExp = new RegExp(/^\s*[\+\-]\d.*/);
|
||||
incResult = incRegExp.exec(rawFontSize);
|
||||
if(Boolean(incResult))
|
||||
{
|
||||
this.debugLog("Invalid DFXP document: increment values are not supported for font size.");
|
||||
returnValue = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
regExp = new RegExp(/^\s*(\d+).*$/);
|
||||
result = regExp.exec(rawFontSize);
|
||||
if(Boolean(result) && result[1] != undefined)
|
||||
{
|
||||
returnValue = result[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
private function parseFontFamily(rawFontFamily:String) : String
|
||||
{
|
||||
var result:Object = null;
|
||||
if(!rawFontFamily || rawFontFamily == "")
|
||||
{
|
||||
return "";
|
||||
}
|
||||
var retVal:String = "";
|
||||
var regExp:RegExp = new RegExp(/^\s*([^,\s]+)\s*((,\s*([^,\s]+)\s*)*)$/);
|
||||
var done:Boolean = false;
|
||||
do
|
||||
{
|
||||
result = regExp.exec(rawFontFamily);
|
||||
if(!result)
|
||||
{
|
||||
done = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(retVal.length > 0)
|
||||
{
|
||||
retVal += ",";
|
||||
}
|
||||
switch(result[1])
|
||||
{
|
||||
case "default":
|
||||
case "serif":
|
||||
case "proportionalSerif":
|
||||
retVal += "_serif";
|
||||
break;
|
||||
case "monospace":
|
||||
case "monospaceSansSerif":
|
||||
case "monospaceSerif":
|
||||
retVal += "_typewriter";
|
||||
break;
|
||||
case "sansSerif":
|
||||
case "proportionalSansSerif":
|
||||
retVal += "_sans";
|
||||
break;
|
||||
default:
|
||||
retVal += result[1];
|
||||
}
|
||||
if(result[2] != undefined && result[2] != "")
|
||||
{
|
||||
rawFontFamily = result[2].slice(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
done = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
while(!done);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
private function parseBody(doc:CaptioningDocument, xml:XML) : void
|
||||
{
|
||||
var div:XMLList = null;
|
||||
var p:XMLList = null;
|
||||
var i:uint = 0;
|
||||
var pNode:XML = null;
|
||||
var body:XMLList = xml..this.ns::body;
|
||||
if(body.length() <= 0)
|
||||
{
|
||||
this.debugLog("Invalid DFXP document: <body> tag is required.");
|
||||
}
|
||||
else
|
||||
{
|
||||
div = xml..this.ns::div;
|
||||
p = Boolean(div.length()) ? div.children() : (Boolean(body.length()) ? body.children() : new XMLList());
|
||||
for(i = 0; i < p.length(); i++)
|
||||
{
|
||||
pNode = p[i];
|
||||
if(this.rootNamespace == pNode.namespace())
|
||||
{
|
||||
this.parsePTag(doc,pNode,i);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.debugLog("Ignoring this tag, foreign namespaces not supported: \"" + pNode + "\"");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function parsePTag(doc:CaptioningDocument, pNode:XML, index:uint) : void
|
||||
{
|
||||
var text:String = null;
|
||||
var child:XML = null;
|
||||
var styleStartIndex:uint = 0;
|
||||
var spanText:String = null;
|
||||
var stylesList:Array = null;
|
||||
var styleEndIndex:uint = 0;
|
||||
var styleObject:CaptionStyle = null;
|
||||
var fmtObj:CaptionFormat = null;
|
||||
var formatObj:CaptionFormat = null;
|
||||
var begin:String = pNode.@begin;
|
||||
var end:String = pNode.@end;
|
||||
var dur:String = pNode.@dur;
|
||||
if(begin == "")
|
||||
{
|
||||
begin = "0s";
|
||||
}
|
||||
var beginSecs:Number = TimeUtil.parseTime(begin);
|
||||
var endSecs:Number = 0;
|
||||
if(end != "")
|
||||
{
|
||||
endSecs = TimeUtil.parseTime(end);
|
||||
}
|
||||
else if(dur != "")
|
||||
{
|
||||
endSecs = beginSecs + TimeUtil.parseTime(dur);
|
||||
}
|
||||
var captionFormatList:Array = new Array();
|
||||
text = new String("<p>");
|
||||
var children:XMLList = pNode.children();
|
||||
for(var i:uint = 0; i < children.length(); i++)
|
||||
{
|
||||
child = children[i];
|
||||
switch(child.nodeKind())
|
||||
{
|
||||
case "text":
|
||||
text += this.formatCCText(child.toString());
|
||||
break;
|
||||
case "element":
|
||||
switch(child.localName())
|
||||
{
|
||||
case "set":
|
||||
case "metadata":
|
||||
break;
|
||||
case "span":
|
||||
styleStartIndex = uint(this.calcClearTextLength(text));
|
||||
stylesList = new Array();
|
||||
text += this.parseSpanTag(doc,child,stylesList);
|
||||
styleEndIndex = uint(this.calcClearTextLength(text));
|
||||
for each(styleObject in stylesList)
|
||||
{
|
||||
fmtObj = new CaptionFormat(styleObject,styleStartIndex,styleEndIndex);
|
||||
captionFormatList.push(fmtObj);
|
||||
}
|
||||
break;
|
||||
case "br":
|
||||
text += "<br />";
|
||||
break;
|
||||
default:
|
||||
text += this.formatCCText(child.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
text += "</p>";
|
||||
var captionItem:Caption = new Caption(index,beginSecs,endSecs,text);
|
||||
var styleObj:CaptionStyle = this.parseStyleAttrib(doc,pNode);
|
||||
if(Boolean(styleObj))
|
||||
{
|
||||
formatObj = new CaptionFormat(styleObj);
|
||||
captionItem.addCaptionFormat(formatObj);
|
||||
}
|
||||
for(i = 0; i < captionFormatList.length; i++)
|
||||
{
|
||||
captionItem.addCaptionFormat(captionFormatList[i]);
|
||||
}
|
||||
doc.addCaption(captionItem);
|
||||
}
|
||||
|
||||
private function parseStyleAttrib(doc:CaptioningDocument, node:XML) : CaptionStyle
|
||||
{
|
||||
var i:uint = 0;
|
||||
var attributes:XMLList = null;
|
||||
var attrib:XML = null;
|
||||
var localName:String = null;
|
||||
var styleId:String = node.@style;
|
||||
var captionStyle:CaptionStyle = null;
|
||||
if(styleId != "")
|
||||
{
|
||||
while(i < doc.numStyles)
|
||||
{
|
||||
if(doc.getStyleAt(i).id == styleId)
|
||||
{
|
||||
captionStyle = doc.getStyleAt(i);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
attributes = node.this.tts::@*;
|
||||
}
|
||||
catch(err:Error)
|
||||
{
|
||||
if(err.errorID != 1080)
|
||||
{
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
i = 0;
|
||||
while(attributes != null && i < attributes.length())
|
||||
{
|
||||
attrib = attributes[i];
|
||||
localName = attrib.localName();
|
||||
if(localName != "inherit")
|
||||
{
|
||||
captionStyle = this.createStyleObject(node);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
return captionStyle;
|
||||
}
|
||||
|
||||
private function parseSpanTag(doc:CaptioningDocument, spanNode:XML, styles:Array) : String
|
||||
{
|
||||
var child:XML = null;
|
||||
var styleObj:CaptionStyle = this.parseStyleAttrib(doc,spanNode);
|
||||
if(styleObj != null)
|
||||
{
|
||||
styles.push(styleObj);
|
||||
}
|
||||
var ccText:String = new String();
|
||||
var children:XMLList = spanNode.children();
|
||||
for(var i:uint = 0; i < children.length(); i++)
|
||||
{
|
||||
child = children[i];
|
||||
switch(child.nodeKind())
|
||||
{
|
||||
case "text":
|
||||
ccText += this.formatCCText(child.toString());
|
||||
break;
|
||||
case "element":
|
||||
switch(child.localName())
|
||||
{
|
||||
case "set":
|
||||
case "metadata":
|
||||
break;
|
||||
case "br":
|
||||
ccText += "<br/>";
|
||||
break;
|
||||
default:
|
||||
ccText += child.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
return ccText;
|
||||
}
|
||||
|
||||
private function formatCCText(txt:String) : String
|
||||
{
|
||||
return txt.replace(/\s+/g," ");
|
||||
}
|
||||
|
||||
private function calcClearTextLength(txt:String) : int
|
||||
{
|
||||
var clrTxt:String = txt.replace(/<(.|\n)*?>/g,"");
|
||||
return clrTxt.length;
|
||||
}
|
||||
|
||||
private function debugLog(msg:String) : void
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package org.osmf.captioning.parsers
|
||||
{
|
||||
import org.osmf.captioning.model.CaptioningDocument;
|
||||
|
||||
public interface ICaptioningParser
|
||||
{
|
||||
|
||||
function parse(param1:String) : CaptioningDocument;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package org.osmf.containers
|
||||
{
|
||||
import org.osmf.media.MediaElement;
|
||||
|
||||
public interface IMediaContainer
|
||||
{
|
||||
|
||||
function addMediaElement(param1:MediaElement) : MediaElement;
|
||||
|
||||
function removeMediaElement(param1:MediaElement) : MediaElement;
|
||||
|
||||
function containsMediaElement(param1:MediaElement) : Boolean;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,211 @@
|
||||
package org.osmf.containers
|
||||
{
|
||||
import flash.display.DisplayObject;
|
||||
import flash.errors.IllegalOperationError;
|
||||
import flash.geom.Rectangle;
|
||||
import flash.utils.Dictionary;
|
||||
import org.osmf.events.ContainerChangeEvent;
|
||||
import org.osmf.layout.LayoutMetadata;
|
||||
import org.osmf.layout.LayoutRenderer;
|
||||
import org.osmf.layout.LayoutRendererBase;
|
||||
import org.osmf.layout.LayoutTargetEvent;
|
||||
import org.osmf.layout.LayoutTargetSprite;
|
||||
import org.osmf.layout.MediaElementLayoutTarget;
|
||||
import org.osmf.media.MediaElement;
|
||||
import org.osmf.utils.OSMFStrings;
|
||||
|
||||
public class MediaContainer extends LayoutTargetSprite implements IMediaContainer
|
||||
{
|
||||
|
||||
private var layoutTargets:Dictionary = new Dictionary();
|
||||
|
||||
private var _layoutRenderer:LayoutRendererBase;
|
||||
|
||||
private var _backgroundColor:Number;
|
||||
|
||||
private var _backgroundAlpha:Number;
|
||||
|
||||
private var lastAvailableWidth:Number;
|
||||
|
||||
private var lastAvailableHeight:Number;
|
||||
|
||||
public function MediaContainer(layoutRenderer:LayoutRendererBase = null, layoutMetadata:LayoutMetadata = null)
|
||||
{
|
||||
super(layoutMetadata);
|
||||
this._layoutRenderer = layoutRenderer || new LayoutRenderer();
|
||||
this._layoutRenderer.container = this;
|
||||
}
|
||||
|
||||
public function addMediaElement(element:MediaElement) : MediaElement
|
||||
{
|
||||
var contentTarget:MediaElementLayoutTarget = null;
|
||||
if(element == null)
|
||||
{
|
||||
throw new IllegalOperationError(OSMFStrings.getString(OSMFStrings.NULL_PARAM));
|
||||
}
|
||||
if(this.layoutTargets[element] == undefined)
|
||||
{
|
||||
element.dispatchEvent(new ContainerChangeEvent(ContainerChangeEvent.CONTAINER_CHANGE,false,false,element.container,this));
|
||||
contentTarget = MediaElementLayoutTarget.getInstance(element);
|
||||
this.layoutTargets[element] = contentTarget;
|
||||
this._layoutRenderer.addTarget(contentTarget);
|
||||
element.addEventListener(ContainerChangeEvent.CONTAINER_CHANGE,this.onElementContainerChange);
|
||||
return element;
|
||||
}
|
||||
throw new IllegalOperationError(OSMFStrings.getString(OSMFStrings.INVALID_PARAM));
|
||||
}
|
||||
|
||||
public function removeMediaElement(element:MediaElement) : MediaElement
|
||||
{
|
||||
var result:MediaElement = null;
|
||||
if(element == null)
|
||||
{
|
||||
throw new IllegalOperationError(OSMFStrings.getString(OSMFStrings.NULL_PARAM));
|
||||
}
|
||||
var contentTarget:MediaElementLayoutTarget = this.layoutTargets[element];
|
||||
if(Boolean(contentTarget))
|
||||
{
|
||||
element.removeEventListener(ContainerChangeEvent.CONTAINER_CHANGE,this.onElementContainerChange);
|
||||
this._layoutRenderer.removeTarget(contentTarget);
|
||||
delete this.layoutTargets[element];
|
||||
result = element;
|
||||
if(element.container == this)
|
||||
{
|
||||
element.dispatchEvent(new ContainerChangeEvent(ContainerChangeEvent.CONTAINER_CHANGE,false,false,element.container,null));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
throw new IllegalOperationError(OSMFStrings.getString(OSMFStrings.INVALID_PARAM));
|
||||
}
|
||||
|
||||
public function containsMediaElement(element:MediaElement) : Boolean
|
||||
{
|
||||
return this.layoutTargets[element] != undefined;
|
||||
}
|
||||
|
||||
public function get layoutRenderer() : LayoutRendererBase
|
||||
{
|
||||
return this._layoutRenderer;
|
||||
}
|
||||
|
||||
public function get clipChildren() : Boolean
|
||||
{
|
||||
return scrollRect != null;
|
||||
}
|
||||
|
||||
public function set clipChildren(value:Boolean) : void
|
||||
{
|
||||
if(value && scrollRect == null)
|
||||
{
|
||||
scrollRect = new Rectangle(0,0,this._layoutRenderer.measuredWidth,this._layoutRenderer.measuredHeight);
|
||||
}
|
||||
else if(value == false && Boolean(scrollRect))
|
||||
{
|
||||
scrollRect = null;
|
||||
}
|
||||
}
|
||||
|
||||
public function get backgroundColor() : Number
|
||||
{
|
||||
return this._backgroundColor;
|
||||
}
|
||||
|
||||
public function set backgroundColor(value:Number) : void
|
||||
{
|
||||
if(value != this._backgroundColor)
|
||||
{
|
||||
this._backgroundColor = value;
|
||||
this.drawBackground();
|
||||
}
|
||||
}
|
||||
|
||||
public function get backgroundAlpha() : Number
|
||||
{
|
||||
return this._backgroundAlpha;
|
||||
}
|
||||
|
||||
public function set backgroundAlpha(value:Number) : void
|
||||
{
|
||||
if(value != this._backgroundAlpha)
|
||||
{
|
||||
this._backgroundAlpha = value;
|
||||
this.drawBackground();
|
||||
}
|
||||
}
|
||||
|
||||
override public function layout(availableWidth:Number, availableHeight:Number, deep:Boolean = true) : void
|
||||
{
|
||||
super.layout(availableWidth,availableHeight,deep);
|
||||
this.lastAvailableWidth = availableWidth;
|
||||
this.lastAvailableHeight = availableHeight;
|
||||
if(!isNaN(this.backgroundColor))
|
||||
{
|
||||
this.drawBackground();
|
||||
}
|
||||
if(Boolean(scrollRect))
|
||||
{
|
||||
scrollRect = new Rectangle(0,0,availableWidth,availableHeight);
|
||||
}
|
||||
}
|
||||
|
||||
override public function validateNow() : void
|
||||
{
|
||||
this._layoutRenderer.validateNow();
|
||||
}
|
||||
|
||||
override public function addChild(child:DisplayObject) : DisplayObject
|
||||
{
|
||||
throw new IllegalOperationError(OSMFStrings.getString(OSMFStrings.DIRECT_DISPLAY_LIST_MOD_ERROR));
|
||||
}
|
||||
|
||||
override public function addChildAt(child:DisplayObject, index:int) : DisplayObject
|
||||
{
|
||||
throw new IllegalOperationError(OSMFStrings.getString(OSMFStrings.DIRECT_DISPLAY_LIST_MOD_ERROR));
|
||||
}
|
||||
|
||||
override public function removeChild(child:DisplayObject) : DisplayObject
|
||||
{
|
||||
throw new IllegalOperationError(OSMFStrings.getString(OSMFStrings.DIRECT_DISPLAY_LIST_MOD_ERROR));
|
||||
}
|
||||
|
||||
override public function setChildIndex(child:DisplayObject, index:int) : void
|
||||
{
|
||||
throw new IllegalOperationError(OSMFStrings.getString(OSMFStrings.DIRECT_DISPLAY_LIST_MOD_ERROR));
|
||||
}
|
||||
|
||||
override protected function onAddChildAt(event:LayoutTargetEvent) : void
|
||||
{
|
||||
super.addChildAt(event.displayObject,event.index);
|
||||
}
|
||||
|
||||
override protected function onRemoveChild(event:LayoutTargetEvent) : void
|
||||
{
|
||||
super.removeChild(event.displayObject);
|
||||
}
|
||||
|
||||
override protected function onSetChildIndex(event:LayoutTargetEvent) : void
|
||||
{
|
||||
super.setChildIndex(event.displayObject,event.index);
|
||||
}
|
||||
|
||||
private function drawBackground() : void
|
||||
{
|
||||
graphics.clear();
|
||||
if(Boolean(!isNaN(this._backgroundColor) && this._backgroundAlpha != 0) && Boolean(this.lastAvailableWidth) && Boolean(this.lastAvailableHeight))
|
||||
{
|
||||
graphics.beginFill(this._backgroundColor,this._backgroundAlpha);
|
||||
graphics.drawRect(0,0,this.lastAvailableWidth,this.lastAvailableHeight);
|
||||
graphics.endFill();
|
||||
}
|
||||
}
|
||||
|
||||
private function onElementContainerChange(event:ContainerChangeEvent) : void
|
||||
{
|
||||
if(event.oldContainer == this)
|
||||
{
|
||||
this.removeMediaElement(event.target as MediaElement);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,183 @@
|
||||
package org.osmf.elements
|
||||
{
|
||||
import flash.events.NetStatusEvent;
|
||||
import flash.net.NetStream;
|
||||
import org.osmf.elements.audioClasses.AudioAudioTrait;
|
||||
import org.osmf.elements.audioClasses.AudioPlayTrait;
|
||||
import org.osmf.elements.audioClasses.AudioSeekTrait;
|
||||
import org.osmf.elements.audioClasses.AudioTimeTrait;
|
||||
import org.osmf.elements.audioClasses.SoundAdapter;
|
||||
import org.osmf.elements.audioClasses.SoundLoadTrait;
|
||||
import org.osmf.events.MediaError;
|
||||
import org.osmf.events.MediaErrorCodes;
|
||||
import org.osmf.events.MediaErrorEvent;
|
||||
import org.osmf.media.DefaultTraitResolver;
|
||||
import org.osmf.media.LoadableElementBase;
|
||||
import org.osmf.media.MediaResourceBase;
|
||||
import org.osmf.media.URLResource;
|
||||
import org.osmf.net.*;
|
||||
import org.osmf.traits.LoadTrait;
|
||||
import org.osmf.traits.LoaderBase;
|
||||
import org.osmf.traits.MediaTraitType;
|
||||
import org.osmf.traits.TimeTrait;
|
||||
import org.osmf.utils.OSMFStrings;
|
||||
|
||||
public class AudioElement extends LoadableElementBase
|
||||
{
|
||||
|
||||
private var soundAdapter:SoundAdapter;
|
||||
|
||||
private var stream:NetStream;
|
||||
|
||||
private var defaultTimeTrait:ModifiableTimeTrait;
|
||||
|
||||
private var _alternateLoaders:Vector.<LoaderBase>;
|
||||
|
||||
public function AudioElement(resource:URLResource = null, loader:LoaderBase = null)
|
||||
{
|
||||
super(resource,loader);
|
||||
if(!(loader == null || loader is NetLoader || loader is SoundLoader))
|
||||
{
|
||||
throw new ArgumentError(OSMFStrings.getString(OSMFStrings.INVALID_PARAM));
|
||||
}
|
||||
}
|
||||
|
||||
public function get defaultDuration() : Number
|
||||
{
|
||||
return Boolean(this.defaultTimeTrait) ? this.defaultTimeTrait.duration : NaN;
|
||||
}
|
||||
|
||||
public function set defaultDuration(value:Number) : void
|
||||
{
|
||||
if(isNaN(value) || value < 0)
|
||||
{
|
||||
if(this.defaultTimeTrait != null)
|
||||
{
|
||||
removeTraitResolver(MediaTraitType.TIME);
|
||||
this.defaultTimeTrait = null;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(this.defaultTimeTrait == null)
|
||||
{
|
||||
this.defaultTimeTrait = new ModifiableTimeTrait();
|
||||
addTraitResolver(MediaTraitType.TIME,new DefaultTraitResolver(MediaTraitType.TIME,this.defaultTimeTrait));
|
||||
}
|
||||
this.defaultTimeTrait.duration = value;
|
||||
}
|
||||
}
|
||||
|
||||
override public function set resource(value:MediaResourceBase) : void
|
||||
{
|
||||
loader = getLoaderForResource(value,this.alternateLoaders);
|
||||
super.resource = value;
|
||||
}
|
||||
|
||||
override protected function createLoadTrait(resource:MediaResourceBase, loader:LoaderBase) : LoadTrait
|
||||
{
|
||||
return loader is NetLoader ? new NetStreamLoadTrait(loader,resource) : new SoundLoadTrait(loader,resource);
|
||||
}
|
||||
|
||||
override protected function processReadyState() : void
|
||||
{
|
||||
var timeTrait:TimeTrait = null;
|
||||
var reconnectStreams:Boolean = false;
|
||||
var soundLoadTrait:SoundLoadTrait = null;
|
||||
var loadTrait:LoadTrait = getTrait(MediaTraitType.LOAD) as LoadTrait;
|
||||
this.soundAdapter = null;
|
||||
this.stream = null;
|
||||
var netLoadTrait:NetStreamLoadTrait = loadTrait as NetStreamLoadTrait;
|
||||
if(Boolean(netLoadTrait))
|
||||
{
|
||||
this.stream = netLoadTrait.netStream;
|
||||
this.stream.addEventListener(NetStatusEvent.NET_STATUS,this.onNetStatusEvent);
|
||||
netLoadTrait.connection.addEventListener(NetStatusEvent.NET_STATUS,this.onNetStatusEvent,false,0,true);
|
||||
reconnectStreams = false;
|
||||
if(loader is NetLoader)
|
||||
{
|
||||
reconnectStreams = (loader as NetLoader).reconnectStreams;
|
||||
}
|
||||
addTrait(MediaTraitType.PLAY,new NetStreamPlayTrait(this.stream,resource,reconnectStreams,netLoadTrait.connection));
|
||||
timeTrait = new NetStreamTimeTrait(this.stream,resource,this.defaultDuration);
|
||||
addTrait(MediaTraitType.TIME,timeTrait);
|
||||
addTrait(MediaTraitType.SEEK,new NetStreamSeekTrait(timeTrait,loadTrait,this.stream));
|
||||
addTrait(MediaTraitType.AUDIO,new NetStreamAudioTrait(this.stream));
|
||||
addTrait(MediaTraitType.BUFFER,new NetStreamBufferTrait(this.stream));
|
||||
}
|
||||
else
|
||||
{
|
||||
soundLoadTrait = loadTrait as SoundLoadTrait;
|
||||
this.soundAdapter = new SoundAdapter(this,soundLoadTrait.sound);
|
||||
addTrait(MediaTraitType.PLAY,new AudioPlayTrait(this.soundAdapter));
|
||||
timeTrait = new AudioTimeTrait(this.soundAdapter);
|
||||
addTrait(MediaTraitType.TIME,timeTrait);
|
||||
addTrait(MediaTraitType.SEEK,new AudioSeekTrait(timeTrait,this.soundAdapter));
|
||||
addTrait(MediaTraitType.AUDIO,new AudioAudioTrait(this.soundAdapter));
|
||||
}
|
||||
}
|
||||
|
||||
override protected function processUnloadingState() : void
|
||||
{
|
||||
if(this.stream != null)
|
||||
{
|
||||
this.stream.removeEventListener(NetStatusEvent.NET_STATUS,this.onNetStatusEvent);
|
||||
}
|
||||
var netLoadTrait:NetStreamLoadTrait = getTrait(MediaTraitType.LOAD) as NetStreamLoadTrait;
|
||||
if(netLoadTrait != null)
|
||||
{
|
||||
netLoadTrait.connection.removeEventListener(NetStatusEvent.NET_STATUS,this.onNetStatusEvent);
|
||||
}
|
||||
removeTrait(MediaTraitType.PLAY);
|
||||
removeTrait(MediaTraitType.SEEK);
|
||||
removeTrait(MediaTraitType.TIME);
|
||||
removeTrait(MediaTraitType.AUDIO);
|
||||
removeTrait(MediaTraitType.BUFFER);
|
||||
if(this.soundAdapter != null)
|
||||
{
|
||||
this.soundAdapter.pause();
|
||||
}
|
||||
this.soundAdapter = null;
|
||||
this.stream = null;
|
||||
}
|
||||
|
||||
private function onNetStatusEvent(event:NetStatusEvent) : void
|
||||
{
|
||||
var error:MediaError = null;
|
||||
switch(event.info.code)
|
||||
{
|
||||
case NetStreamCodes.NETSTREAM_PLAY_FAILED:
|
||||
case NetStreamCodes.NETSTREAM_FAILED:
|
||||
error = new MediaError(MediaErrorCodes.NETSTREAM_PLAY_FAILED,event.info.description);
|
||||
break;
|
||||
case NetStreamCodes.NETSTREAM_PLAY_STREAMNOTFOUND:
|
||||
error = new MediaError(MediaErrorCodes.NETSTREAM_STREAM_NOT_FOUND,event.info.description);
|
||||
break;
|
||||
case NetStreamCodes.NETSTREAM_PLAY_FILESTRUCTUREINVALID:
|
||||
error = new MediaError(MediaErrorCodes.NETSTREAM_FILE_STRUCTURE_INVALID,event.info.description);
|
||||
break;
|
||||
case NetStreamCodes.NETSTREAM_PLAY_NOSUPPORTEDTRACKFOUND:
|
||||
error = new MediaError(MediaErrorCodes.NETSTREAM_NO_SUPPORTED_TRACK_FOUND,event.info.description);
|
||||
break;
|
||||
case NetConnectionCodes.CONNECT_IDLE_TIME_OUT:
|
||||
error = new MediaError(MediaErrorCodes.NETCONNECTION_TIMEOUT,event.info.description);
|
||||
}
|
||||
if(error != null)
|
||||
{
|
||||
dispatchEvent(new MediaErrorEvent(MediaErrorEvent.MEDIA_ERROR,false,false,error));
|
||||
}
|
||||
}
|
||||
|
||||
private function get alternateLoaders() : Vector.<LoaderBase>
|
||||
{
|
||||
if(this._alternateLoaders == null)
|
||||
{
|
||||
this._alternateLoaders = new Vector.<LoaderBase>();
|
||||
this._alternateLoaders.push(new SoundLoader());
|
||||
this._alternateLoaders.push(new NetLoader());
|
||||
}
|
||||
return this._alternateLoaders;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package org.osmf.elements
|
||||
{
|
||||
import org.osmf.media.URLResource;
|
||||
|
||||
public class F4MElement extends LoadFromDocumentElement
|
||||
{
|
||||
|
||||
public function F4MElement(resource:URLResource = null, loader:F4MLoader = null)
|
||||
{
|
||||
if(loader == null)
|
||||
{
|
||||
loader = new F4MLoader();
|
||||
}
|
||||
super(resource,loader);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,191 @@
|
||||
package org.osmf.elements
|
||||
{
|
||||
import flash.events.ErrorEvent;
|
||||
import flash.events.Event;
|
||||
import flash.events.IOErrorEvent;
|
||||
import flash.events.SecurityErrorEvent;
|
||||
import flash.net.URLLoader;
|
||||
import flash.net.URLLoaderDataFormat;
|
||||
import flash.net.URLRequest;
|
||||
import org.osmf.elements.f4mClasses.DRMAdditionalHeader;
|
||||
import org.osmf.elements.f4mClasses.Manifest;
|
||||
import org.osmf.elements.f4mClasses.ManifestParser;
|
||||
import org.osmf.elements.proxyClasses.LoadFromDocumentLoadTrait;
|
||||
import org.osmf.events.MediaError;
|
||||
import org.osmf.events.MediaErrorCodes;
|
||||
import org.osmf.events.MediaErrorEvent;
|
||||
import org.osmf.media.DefaultMediaFactory;
|
||||
import org.osmf.media.MediaElement;
|
||||
import org.osmf.media.MediaFactory;
|
||||
import org.osmf.media.MediaResourceBase;
|
||||
import org.osmf.media.MediaTypeUtil;
|
||||
import org.osmf.media.URLResource;
|
||||
import org.osmf.net.httpstreaming.HTTPStreamingUtils;
|
||||
import org.osmf.traits.LoadState;
|
||||
import org.osmf.traits.LoadTrait;
|
||||
import org.osmf.traits.LoaderBase;
|
||||
import org.osmf.utils.OSMFStrings;
|
||||
import org.osmf.utils.URL;
|
||||
|
||||
public class F4MLoader extends LoaderBase
|
||||
{
|
||||
|
||||
public static const F4M_MIME_TYPE:String = "application/f4m+xml";
|
||||
|
||||
private static const F4M_EXTENSION:String = "f4m";
|
||||
|
||||
private var supportedMimeTypes:Vector.<String> = new Vector.<String>();
|
||||
|
||||
private var factory:MediaFactory;
|
||||
|
||||
private var parser:ManifestParser;
|
||||
|
||||
public function F4MLoader(factory:MediaFactory = null)
|
||||
{
|
||||
super();
|
||||
this.supportedMimeTypes.push(F4M_MIME_TYPE);
|
||||
if(factory == null)
|
||||
{
|
||||
factory = new DefaultMediaFactory();
|
||||
}
|
||||
this.parser = new ManifestParser();
|
||||
this.factory = factory;
|
||||
}
|
||||
|
||||
override public function canHandleResource(resource:MediaResourceBase) : Boolean
|
||||
{
|
||||
var urlResource:URLResource = null;
|
||||
var extension:String = null;
|
||||
var supported:int = MediaTypeUtil.checkMetadataMatchWithResource(resource,new Vector.<String>(),this.supportedMimeTypes);
|
||||
if(supported == MediaTypeUtil.METADATA_MATCH_FOUND)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if(resource is URLResource)
|
||||
{
|
||||
urlResource = URLResource(resource);
|
||||
extension = new URL(urlResource.url).extension;
|
||||
return extension == F4M_EXTENSION;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
override protected function executeLoad(loadTrait:LoadTrait) : void
|
||||
{
|
||||
var manifest:Manifest = null;
|
||||
var manifestLoader:URLLoader = null;
|
||||
var onError:Function = null;
|
||||
var onComplete:Function = null;
|
||||
onError = function(event:ErrorEvent):void
|
||||
{
|
||||
manifestLoader.removeEventListener(Event.COMPLETE,onComplete);
|
||||
manifestLoader.removeEventListener(IOErrorEvent.IO_ERROR,onError);
|
||||
manifestLoader.removeEventListener(SecurityErrorEvent.SECURITY_ERROR,onError);
|
||||
updateLoadTrait(loadTrait,LoadState.LOAD_ERROR);
|
||||
loadTrait.dispatchEvent(new MediaErrorEvent(MediaErrorEvent.MEDIA_ERROR,false,false,new MediaError(0,event.text)));
|
||||
};
|
||||
onComplete = function(event:Event):void
|
||||
{
|
||||
var completionCallback:Function;
|
||||
var unfinishedLoads:Number = NaN;
|
||||
var item:DRMAdditionalHeader = null;
|
||||
manifestLoader.removeEventListener(Event.COMPLETE,onComplete);
|
||||
manifestLoader.removeEventListener(IOErrorEvent.IO_ERROR,onError);
|
||||
manifestLoader.removeEventListener(SecurityErrorEvent.SECURITY_ERROR,onError);
|
||||
try
|
||||
{
|
||||
manifest = parser.parse(event.target.data,getRootUrl(URLResource(loadTrait.resource).url));
|
||||
}
|
||||
catch(parseError:Error)
|
||||
{
|
||||
updateLoadTrait(loadTrait,LoadState.LOAD_ERROR);
|
||||
loadTrait.dispatchEvent(new MediaErrorEvent(MediaErrorEvent.MEDIA_ERROR,false,false,new MediaError(parseError.errorID,parseError.message)));
|
||||
}
|
||||
if(manifest != null)
|
||||
{
|
||||
unfinishedLoads = 0;
|
||||
for each(item in manifest.drmAdditionalHeaders)
|
||||
{
|
||||
if(item.url != null)
|
||||
{
|
||||
completionCallback = function(success:Boolean):void
|
||||
{
|
||||
if(success)
|
||||
{
|
||||
--unfinishedLoads;
|
||||
}
|
||||
if(unfinishedLoads == 0)
|
||||
{
|
||||
finishLoad();
|
||||
}
|
||||
};
|
||||
unfinishedLoads++;
|
||||
loadAdditionalHeader(item,completionCallback,onError);
|
||||
}
|
||||
}
|
||||
if(unfinishedLoads == 0)
|
||||
{
|
||||
finishLoad();
|
||||
}
|
||||
}
|
||||
};
|
||||
var finishLoad:Function = function():void
|
||||
{
|
||||
var netResource:MediaResourceBase = null;
|
||||
var loadedElem:MediaElement = null;
|
||||
var s:OSMFStrings = null;
|
||||
try
|
||||
{
|
||||
netResource = parser.createResource(manifest,URLResource(loadTrait.resource));
|
||||
loadedElem = factory.createMediaElement(netResource);
|
||||
if(loadedElem.hasOwnProperty("defaultDuration") && !isNaN(manifest.duration))
|
||||
{
|
||||
loadedElem["defaultDuration"] = manifest.duration;
|
||||
}
|
||||
LoadFromDocumentLoadTrait(loadTrait).mediaElement = loadedElem;
|
||||
updateLoadTrait(loadTrait,LoadState.READY);
|
||||
}
|
||||
catch(error:Error)
|
||||
{
|
||||
updateLoadTrait(loadTrait,LoadState.LOAD_ERROR);
|
||||
loadTrait.dispatchEvent(new MediaErrorEvent(MediaErrorEvent.MEDIA_ERROR,false,false,new MediaError(MediaErrorCodes.F4M_FILE_INVALID,error.message)));
|
||||
}
|
||||
};
|
||||
updateLoadTrait(loadTrait,LoadState.LOADING);
|
||||
manifestLoader = new URLLoader(new URLRequest(URLResource(loadTrait.resource).url));
|
||||
manifestLoader.addEventListener(Event.COMPLETE,onComplete);
|
||||
manifestLoader.addEventListener(IOErrorEvent.IO_ERROR,onError);
|
||||
manifestLoader.addEventListener(SecurityErrorEvent.SECURITY_ERROR,onError);
|
||||
}
|
||||
|
||||
override protected function executeUnload(loadTrait:LoadTrait) : void
|
||||
{
|
||||
updateLoadTrait(loadTrait,LoadState.UNINITIALIZED);
|
||||
}
|
||||
|
||||
private function loadAdditionalHeader(item:DRMAdditionalHeader, completionCallback:Function, onError:Function) : void
|
||||
{
|
||||
var onDRMLoadComplete:Function = null;
|
||||
onDRMLoadComplete = function(event:Event):void
|
||||
{
|
||||
event.target.removeEventListener(Event.COMPLETE,onDRMLoadComplete);
|
||||
event.target.removeEventListener(IOErrorEvent.IO_ERROR,onError);
|
||||
event.target.removeEventListener(SecurityErrorEvent.SECURITY_ERROR,onError);
|
||||
item.data = URLLoader(event.target).data;
|
||||
completionCallback(true);
|
||||
};
|
||||
var drmLoader:URLLoader = new URLLoader();
|
||||
drmLoader.dataFormat = URLLoaderDataFormat.BINARY;
|
||||
drmLoader.addEventListener(Event.COMPLETE,onDRMLoadComplete);
|
||||
drmLoader.addEventListener(IOErrorEvent.IO_ERROR,onError);
|
||||
drmLoader.addEventListener(SecurityErrorEvent.SECURITY_ERROR,onError);
|
||||
drmLoader.load(new URLRequest(HTTPStreamingUtils.normalizeURL(item.url)));
|
||||
}
|
||||
|
||||
private function getRootUrl(url:String) : String
|
||||
{
|
||||
return url.substr(0,url.lastIndexOf("/"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
package org.osmf.elements
|
||||
{
|
||||
import flash.display.Bitmap;
|
||||
import flash.display.Loader;
|
||||
import org.osmf.elements.loaderClasses.LoaderLoadTrait;
|
||||
import org.osmf.elements.loaderClasses.LoaderUtils;
|
||||
import org.osmf.media.LoadableElementBase;
|
||||
import org.osmf.media.MediaResourceBase;
|
||||
import org.osmf.media.URLResource;
|
||||
import org.osmf.traits.DisplayObjectTrait;
|
||||
import org.osmf.traits.LoadTrait;
|
||||
import org.osmf.traits.LoaderBase;
|
||||
import org.osmf.traits.MediaTraitType;
|
||||
|
||||
public class ImageElement extends LoadableElementBase
|
||||
{
|
||||
|
||||
private var _smoothing:Boolean;
|
||||
|
||||
public function ImageElement(resource:URLResource = null, loader:ImageLoader = null)
|
||||
{
|
||||
if(loader == null)
|
||||
{
|
||||
loader = new ImageLoader();
|
||||
}
|
||||
super(resource,loader);
|
||||
}
|
||||
|
||||
public function get smoothing() : Boolean
|
||||
{
|
||||
return this._smoothing;
|
||||
}
|
||||
|
||||
public function set smoothing(value:Boolean) : void
|
||||
{
|
||||
if(this._smoothing != value)
|
||||
{
|
||||
this._smoothing = value;
|
||||
this.applySmoothingSetting();
|
||||
}
|
||||
}
|
||||
|
||||
override protected function createLoadTrait(resource:MediaResourceBase, loader:LoaderBase) : LoadTrait
|
||||
{
|
||||
return new LoaderLoadTrait(loader,resource);
|
||||
}
|
||||
|
||||
override protected function processReadyState() : void
|
||||
{
|
||||
var loaderLoadTrait:LoaderLoadTrait = getTrait(MediaTraitType.LOAD) as LoaderLoadTrait;
|
||||
addTrait(MediaTraitType.DISPLAY_OBJECT,LoaderUtils.createDisplayObjectTrait(loaderLoadTrait.loader,this));
|
||||
this.applySmoothingSetting();
|
||||
}
|
||||
|
||||
override protected function processUnloadingState() : void
|
||||
{
|
||||
removeTrait(MediaTraitType.DISPLAY_OBJECT);
|
||||
}
|
||||
|
||||
private function applySmoothingSetting() : void
|
||||
{
|
||||
var loader:Loader = null;
|
||||
var bitmap:Bitmap = null;
|
||||
var displayObjectTrait:DisplayObjectTrait = getTrait(MediaTraitType.DISPLAY_OBJECT) as DisplayObjectTrait;
|
||||
if(Boolean(displayObjectTrait))
|
||||
{
|
||||
loader = displayObjectTrait.displayObject as Loader;
|
||||
if(loader != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
bitmap = loader.content as Bitmap;
|
||||
if(bitmap != null)
|
||||
{
|
||||
bitmap.smoothing = this._smoothing;
|
||||
}
|
||||
}
|
||||
catch(error:SecurityError)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
package org.osmf.elements
|
||||
{
|
||||
import org.osmf.elements.loaderClasses.LoaderUtils;
|
||||
import org.osmf.media.MediaResourceBase;
|
||||
import org.osmf.media.MediaType;
|
||||
import org.osmf.media.MediaTypeUtil;
|
||||
import org.osmf.media.URLResource;
|
||||
import org.osmf.traits.LoadTrait;
|
||||
import org.osmf.traits.LoaderBase;
|
||||
import org.osmf.utils.*;
|
||||
|
||||
public class ImageLoader extends LoaderBase
|
||||
{
|
||||
|
||||
private static const MIME_TYPES_SUPPORTED:Vector.<String> = Vector.<String>(["image/png","image/gif","image/jpeg"]);
|
||||
|
||||
private static const MEDIA_TYPES_SUPPORTED:Vector.<String> = Vector.<String>([MediaType.IMAGE]);
|
||||
|
||||
private var checkPolicyFile:Boolean;
|
||||
|
||||
public function ImageLoader(checkPolicyFile:Boolean = true)
|
||||
{
|
||||
super();
|
||||
this.checkPolicyFile = checkPolicyFile;
|
||||
}
|
||||
|
||||
override public function canHandleResource(resource:MediaResourceBase) : Boolean
|
||||
{
|
||||
var url:URL = null;
|
||||
var rt:int = MediaTypeUtil.checkMetadataMatchWithResource(resource,MEDIA_TYPES_SUPPORTED,MIME_TYPES_SUPPORTED);
|
||||
if(rt != MediaTypeUtil.METADATA_MATCH_UNKNOWN)
|
||||
{
|
||||
return rt == MediaTypeUtil.METADATA_MATCH_FOUND;
|
||||
}
|
||||
var urlResource:URLResource = resource as URLResource;
|
||||
if(urlResource != null && urlResource.url != null)
|
||||
{
|
||||
url = new URL(urlResource.url);
|
||||
return url.path.search(/\.gif$|\.jpg$|\.png$/i) != -1;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
override protected function executeLoad(loadTrait:LoadTrait) : void
|
||||
{
|
||||
LoaderUtils.loadLoadTrait(loadTrait,updateLoadTrait,false,this.checkPolicyFile);
|
||||
}
|
||||
|
||||
override protected function executeUnload(loadTrait:LoadTrait) : void
|
||||
{
|
||||
LoaderUtils.unloadLoadTrait(loadTrait,updateLoadTrait);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,433 @@
|
||||
package org.osmf.elements
|
||||
{
|
||||
import flash.events.DRMErrorEvent;
|
||||
import flash.events.DRMStatusEvent;
|
||||
import flash.events.Event;
|
||||
import flash.events.NetStatusEvent;
|
||||
import flash.events.StatusEvent;
|
||||
import flash.media.Video;
|
||||
import flash.net.NetStream;
|
||||
import flash.system.SystemUpdater;
|
||||
import flash.system.SystemUpdaterType;
|
||||
import flash.utils.ByteArray;
|
||||
import org.osmf.events.DRMEvent;
|
||||
import org.osmf.events.MediaError;
|
||||
import org.osmf.events.MediaErrorCodes;
|
||||
import org.osmf.events.MediaErrorEvent;
|
||||
import org.osmf.events.TimeEvent;
|
||||
import org.osmf.media.DefaultTraitResolver;
|
||||
import org.osmf.media.LoadableElementBase;
|
||||
import org.osmf.media.MediaResourceBase;
|
||||
import org.osmf.media.URLResource;
|
||||
import org.osmf.metadata.CuePoint;
|
||||
import org.osmf.metadata.TimelineMetadata;
|
||||
import org.osmf.net.DynamicStreamingResource;
|
||||
import org.osmf.net.ModifiableTimeTrait;
|
||||
import org.osmf.net.NetClient;
|
||||
import org.osmf.net.NetConnectionCodes;
|
||||
import org.osmf.net.NetLoader;
|
||||
import org.osmf.net.NetStreamAudioTrait;
|
||||
import org.osmf.net.NetStreamBufferTrait;
|
||||
import org.osmf.net.NetStreamCodes;
|
||||
import org.osmf.net.NetStreamDisplayObjectTrait;
|
||||
import org.osmf.net.NetStreamDynamicStreamTrait;
|
||||
import org.osmf.net.NetStreamLoadTrait;
|
||||
import org.osmf.net.NetStreamPlayTrait;
|
||||
import org.osmf.net.NetStreamSeekTrait;
|
||||
import org.osmf.net.NetStreamTimeTrait;
|
||||
import org.osmf.net.NetStreamUtils;
|
||||
import org.osmf.net.StreamType;
|
||||
import org.osmf.net.StreamingURLResource;
|
||||
import org.osmf.net.drm.NetStreamDRMTrait;
|
||||
import org.osmf.traits.DRMState;
|
||||
import org.osmf.traits.DisplayObjectTrait;
|
||||
import org.osmf.traits.LoadState;
|
||||
import org.osmf.traits.LoadTrait;
|
||||
import org.osmf.traits.LoaderBase;
|
||||
import org.osmf.traits.MediaTraitBase;
|
||||
import org.osmf.traits.MediaTraitType;
|
||||
import org.osmf.traits.TimeTrait;
|
||||
import org.osmf.utils.OSMFStrings;
|
||||
|
||||
public class LightweightVideoElement extends LoadableElementBase
|
||||
{
|
||||
|
||||
private static const DRM_STATUS_CODE:String = "DRM.encryptedFLV";
|
||||
|
||||
private static const DRM_NEEDS_AUTHENTICATION:int = 3330;
|
||||
|
||||
private var displayObjectTrait:DisplayObjectTrait;
|
||||
|
||||
private var defaultTimeTrait:ModifiableTimeTrait;
|
||||
|
||||
private var stream:NetStream;
|
||||
|
||||
private var video:Video;
|
||||
|
||||
private var embeddedCuePoints:TimelineMetadata;
|
||||
|
||||
private var _smoothing:Boolean;
|
||||
|
||||
private var _deblocking:int;
|
||||
|
||||
private var drmTrait:NetStreamDRMTrait;
|
||||
|
||||
public function LightweightVideoElement(resource:MediaResourceBase = null, loader:NetLoader = null)
|
||||
{
|
||||
if(loader == null)
|
||||
{
|
||||
loader = new NetLoader();
|
||||
}
|
||||
super(resource,loader);
|
||||
if(!(resource == null || resource is URLResource))
|
||||
{
|
||||
throw new ArgumentError(OSMFStrings.getString(OSMFStrings.INVALID_PARAM));
|
||||
}
|
||||
}
|
||||
|
||||
public function get client() : NetClient
|
||||
{
|
||||
return this.stream != null ? this.stream.client as NetClient : null;
|
||||
}
|
||||
|
||||
public function get defaultDuration() : Number
|
||||
{
|
||||
return Boolean(this.defaultTimeTrait) ? this.defaultTimeTrait.duration : NaN;
|
||||
}
|
||||
|
||||
public function set defaultDuration(value:Number) : void
|
||||
{
|
||||
if(isNaN(value) || value < 0)
|
||||
{
|
||||
if(this.defaultTimeTrait != null)
|
||||
{
|
||||
removeTraitResolver(MediaTraitType.TIME);
|
||||
this.defaultTimeTrait = null;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(this.defaultTimeTrait == null)
|
||||
{
|
||||
this.defaultTimeTrait = new ModifiableTimeTrait();
|
||||
addTraitResolver(MediaTraitType.TIME,new DefaultTraitResolver(MediaTraitType.TIME,this.defaultTimeTrait));
|
||||
}
|
||||
this.defaultTimeTrait.duration = value;
|
||||
}
|
||||
}
|
||||
|
||||
public function get smoothing() : Boolean
|
||||
{
|
||||
return this._smoothing;
|
||||
}
|
||||
|
||||
public function set smoothing(value:Boolean) : void
|
||||
{
|
||||
this._smoothing = value;
|
||||
if(this.video != null)
|
||||
{
|
||||
this.video.smoothing = value;
|
||||
}
|
||||
}
|
||||
|
||||
public function get deblocking() : int
|
||||
{
|
||||
return this._deblocking;
|
||||
}
|
||||
|
||||
public function set deblocking(value:int) : void
|
||||
{
|
||||
this._deblocking = value;
|
||||
if(this.video != null)
|
||||
{
|
||||
this.video.deblocking = value;
|
||||
}
|
||||
}
|
||||
|
||||
public function get currentFPS() : Number
|
||||
{
|
||||
return this.stream != null ? this.stream.currentFPS : 0;
|
||||
}
|
||||
|
||||
override protected function createLoadTrait(resource:MediaResourceBase, loader:LoaderBase) : LoadTrait
|
||||
{
|
||||
return new NetStreamLoadTrait(loader,resource);
|
||||
}
|
||||
|
||||
protected function createVideo() : Video
|
||||
{
|
||||
return new Video();
|
||||
}
|
||||
|
||||
override protected function processReadyState() : void
|
||||
{
|
||||
var streamingResource:StreamingURLResource = null;
|
||||
var metadata:ByteArray = null;
|
||||
var loadTrait:NetStreamLoadTrait = getTrait(MediaTraitType.LOAD) as NetStreamLoadTrait;
|
||||
this.stream = loadTrait.netStream;
|
||||
this.video = this.createVideo();
|
||||
this.video.smoothing = this._smoothing;
|
||||
this.video.deblocking = this._deblocking;
|
||||
this.video.width = this.video.height = 0;
|
||||
this.video.attachNetStream(this.stream);
|
||||
NetClient(this.stream.client).addHandler(NetStreamCodes.ON_META_DATA,this.onMetaData);
|
||||
NetClient(this.stream.client).addHandler(NetStreamCodes.ON_CUE_POINT,this.onCuePoint);
|
||||
this.stream.addEventListener(NetStatusEvent.NET_STATUS,this.onNetStatusEvent);
|
||||
loadTrait.connection.addEventListener(NetStatusEvent.NET_STATUS,this.onNetStatusEvent,false,0,true);
|
||||
this.stream.addEventListener(DRMErrorEvent.DRM_ERROR,this.onDRMErrorEvent);
|
||||
streamingResource = resource as StreamingURLResource;
|
||||
if(streamingResource != null && Boolean(streamingResource.drmContentData))
|
||||
{
|
||||
metadata = streamingResource.drmContentData;
|
||||
this.setupDRMTrait(metadata);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.stream.addEventListener(StatusEvent.STATUS,this.onStatus);
|
||||
this.stream.addEventListener(DRMStatusEvent.DRM_STATUS,this.onDRMStatus);
|
||||
}
|
||||
this.finishLoad();
|
||||
}
|
||||
|
||||
private function finishLoad() : void
|
||||
{
|
||||
var reconnectStreams:Boolean;
|
||||
var dsResource:DynamicStreamingResource;
|
||||
var trait:MediaTraitBase = null;
|
||||
var timeTrait:TimeTrait = null;
|
||||
var onDurationChange:Function = null;
|
||||
var dsTrait:MediaTraitBase = null;
|
||||
var loadTrait:NetStreamLoadTrait = getTrait(MediaTraitType.LOAD) as NetStreamLoadTrait;
|
||||
trait = loadTrait.getTrait(MediaTraitType.DVR);
|
||||
if(trait != null)
|
||||
{
|
||||
addTrait(MediaTraitType.DVR,trait);
|
||||
}
|
||||
trait = loadTrait.getTrait(MediaTraitType.AUDIO);
|
||||
addTrait(MediaTraitType.AUDIO,trait || new NetStreamAudioTrait(this.stream));
|
||||
trait = loadTrait.getTrait(MediaTraitType.BUFFER);
|
||||
addTrait(MediaTraitType.BUFFER,trait || new NetStreamBufferTrait(this.stream));
|
||||
timeTrait = (trait = loadTrait.getTrait(MediaTraitType.TIME)) as TimeTrait;
|
||||
if(timeTrait == null)
|
||||
{
|
||||
timeTrait = new NetStreamTimeTrait(this.stream,loadTrait.resource,this.defaultDuration);
|
||||
}
|
||||
addTrait(MediaTraitType.TIME,timeTrait);
|
||||
trait = loadTrait.getTrait(MediaTraitType.DISPLAY_OBJECT);
|
||||
addTrait(MediaTraitType.DISPLAY_OBJECT,trait || new NetStreamDisplayObjectTrait(this.stream,this.video,NaN,NaN));
|
||||
trait = loadTrait.getTrait(MediaTraitType.PLAY);
|
||||
reconnectStreams = false;
|
||||
reconnectStreams = (loader as NetLoader).reconnectStreams;
|
||||
addTrait(MediaTraitType.PLAY,trait || new NetStreamPlayTrait(this.stream,resource,reconnectStreams,loadTrait.connection));
|
||||
trait = loadTrait.getTrait(MediaTraitType.SEEK);
|
||||
if(trait == null && NetStreamUtils.getStreamType(resource) != StreamType.LIVE)
|
||||
{
|
||||
trait = new NetStreamSeekTrait(timeTrait,loadTrait,this.stream,this.video);
|
||||
}
|
||||
if(trait != null)
|
||||
{
|
||||
if(isNaN(timeTrait.duration) || timeTrait.duration == 0)
|
||||
{
|
||||
onDurationChange = function(event:TimeEvent):void
|
||||
{
|
||||
timeTrait.removeEventListener(TimeEvent.DURATION_CHANGE,onDurationChange);
|
||||
addTrait(MediaTraitType.SEEK,trait);
|
||||
};
|
||||
timeTrait.addEventListener(TimeEvent.DURATION_CHANGE,onDurationChange);
|
||||
}
|
||||
else
|
||||
{
|
||||
addTrait(MediaTraitType.SEEK,trait);
|
||||
}
|
||||
}
|
||||
dsResource = resource as DynamicStreamingResource;
|
||||
if(dsResource != null && loadTrait.switchManager != null)
|
||||
{
|
||||
dsTrait = loadTrait.getTrait(MediaTraitType.DYNAMIC_STREAM);
|
||||
addTrait(MediaTraitType.DYNAMIC_STREAM,dsTrait || new NetStreamDynamicStreamTrait(this.stream,loadTrait.switchManager,dsResource));
|
||||
}
|
||||
}
|
||||
|
||||
override protected function processUnloadingState() : void
|
||||
{
|
||||
var loadTrait:NetStreamLoadTrait = getTrait(MediaTraitType.LOAD) as NetStreamLoadTrait;
|
||||
NetClient(this.stream.client).removeHandler(NetStreamCodes.ON_META_DATA,this.onMetaData);
|
||||
this.stream.removeEventListener(NetStatusEvent.NET_STATUS,this.onNetStatusEvent);
|
||||
loadTrait.connection.removeEventListener(NetStatusEvent.NET_STATUS,this.onNetStatusEvent);
|
||||
removeTrait(MediaTraitType.AUDIO);
|
||||
removeTrait(MediaTraitType.BUFFER);
|
||||
removeTrait(MediaTraitType.PLAY);
|
||||
removeTrait(MediaTraitType.TIME);
|
||||
removeTrait(MediaTraitType.DISPLAY_OBJECT);
|
||||
removeTrait(MediaTraitType.SEEK);
|
||||
removeTrait(MediaTraitType.DYNAMIC_STREAM);
|
||||
removeTrait(MediaTraitType.DVR);
|
||||
this.stream.removeEventListener(DRMErrorEvent.DRM_ERROR,this.onDRMErrorEvent);
|
||||
this.stream.removeEventListener(DRMStatusEvent.DRM_STATUS,this.onDRMStatus);
|
||||
this.stream.removeEventListener(StatusEvent.STATUS,this.onStatus);
|
||||
if(this.drmTrait != null)
|
||||
{
|
||||
this.drmTrait.removeEventListener(DRMEvent.DRM_STATE_CHANGE,this.reloadAfterAuth);
|
||||
removeTrait(MediaTraitType.DRM);
|
||||
this.drmTrait = null;
|
||||
}
|
||||
this.video.attachNetStream(null);
|
||||
this.stream = null;
|
||||
this.video = null;
|
||||
this.displayObjectTrait = null;
|
||||
}
|
||||
|
||||
private function onMetaData(info:Object) : void
|
||||
{
|
||||
var dynamicCuePoints:TimelineMetadata = null;
|
||||
var i:int = 0;
|
||||
var cuePoint:CuePoint = null;
|
||||
var cuePoints:Array = info.cuePoints;
|
||||
if(cuePoints != null && cuePoints.length > 0)
|
||||
{
|
||||
dynamicCuePoints = getMetadata(CuePoint.DYNAMIC_CUEPOINTS_NAMESPACE) as TimelineMetadata;
|
||||
if(dynamicCuePoints == null)
|
||||
{
|
||||
dynamicCuePoints = new TimelineMetadata(this);
|
||||
addMetadata(CuePoint.DYNAMIC_CUEPOINTS_NAMESPACE,dynamicCuePoints);
|
||||
}
|
||||
for(i = 0; i < cuePoints.length; i++)
|
||||
{
|
||||
cuePoint = new CuePoint(cuePoints[i].type,cuePoints[i].time,cuePoints[i].name,cuePoints[i].parameters);
|
||||
try
|
||||
{
|
||||
dynamicCuePoints.addMarker(cuePoint);
|
||||
}
|
||||
catch(error:ArgumentError)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function onCuePoint(info:Object) : void
|
||||
{
|
||||
if(this.embeddedCuePoints == null)
|
||||
{
|
||||
this.embeddedCuePoints = new TimelineMetadata(this);
|
||||
addMetadata(CuePoint.EMBEDDED_CUEPOINTS_NAMESPACE,this.embeddedCuePoints);
|
||||
}
|
||||
var cuePoint:CuePoint = new CuePoint(info.type,info.time,info.name,info.parameters);
|
||||
try
|
||||
{
|
||||
this.embeddedCuePoints.addMarker(cuePoint);
|
||||
}
|
||||
catch(error:ArgumentError)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
private function onUpdateComplete(event:Event) : void
|
||||
{
|
||||
(getTrait(MediaTraitType.LOAD) as LoadTrait).unload();
|
||||
(getTrait(MediaTraitType.LOAD) as LoadTrait).load();
|
||||
}
|
||||
|
||||
private function onNetStatusEvent(event:NetStatusEvent) : void
|
||||
{
|
||||
var error:MediaError = null;
|
||||
switch(event.info.code)
|
||||
{
|
||||
case NetStreamCodes.NETSTREAM_PLAY_FAILED:
|
||||
case NetStreamCodes.NETSTREAM_FAILED:
|
||||
error = new MediaError(MediaErrorCodes.NETSTREAM_PLAY_FAILED,event.info.description);
|
||||
break;
|
||||
case NetStreamCodes.NETSTREAM_PLAY_STREAMNOTFOUND:
|
||||
error = new MediaError(MediaErrorCodes.NETSTREAM_STREAM_NOT_FOUND,event.info.description);
|
||||
break;
|
||||
case NetStreamCodes.NETSTREAM_PLAY_FILESTRUCTUREINVALID:
|
||||
error = new MediaError(MediaErrorCodes.NETSTREAM_FILE_STRUCTURE_INVALID,event.info.description);
|
||||
break;
|
||||
case NetStreamCodes.NETSTREAM_PLAY_NOSUPPORTEDTRACKFOUND:
|
||||
error = new MediaError(MediaErrorCodes.NETSTREAM_NO_SUPPORTED_TRACK_FOUND,event.info.description);
|
||||
break;
|
||||
case NetConnectionCodes.CONNECT_IDLE_TIME_OUT:
|
||||
error = new MediaError(MediaErrorCodes.NETCONNECTION_TIMEOUT,event.info.description);
|
||||
}
|
||||
if(event.info.code == NetStreamCodes.NETSTREAM_DRM_UPDATE)
|
||||
{
|
||||
this.update(SystemUpdaterType.DRM);
|
||||
}
|
||||
if(error != null)
|
||||
{
|
||||
dispatchEvent(new MediaErrorEvent(MediaErrorEvent.MEDIA_ERROR,false,false,error));
|
||||
}
|
||||
}
|
||||
|
||||
private function onStatus(event:StatusEvent) : void
|
||||
{
|
||||
if(event.code == DRM_STATUS_CODE && getTrait(MediaTraitType.DRM) == null)
|
||||
{
|
||||
this.createDRMTrait();
|
||||
}
|
||||
}
|
||||
|
||||
private function onDRMStatus(event:DRMStatusEvent) : void
|
||||
{
|
||||
this.drmTrait.inlineOnVoucher(event);
|
||||
}
|
||||
|
||||
private function reloadAfterAuth(event:DRMEvent) : void
|
||||
{
|
||||
var loadTrait:NetStreamLoadTrait = null;
|
||||
if(this.drmTrait.drmState == DRMState.AUTHENTICATION_COMPLETE)
|
||||
{
|
||||
loadTrait = getTrait(MediaTraitType.LOAD) as NetStreamLoadTrait;
|
||||
if(loadTrait.loadState == LoadState.READY)
|
||||
{
|
||||
loadTrait.unload();
|
||||
}
|
||||
loadTrait.load();
|
||||
}
|
||||
}
|
||||
|
||||
private function createDRMTrait() : void
|
||||
{
|
||||
this.drmTrait = new NetStreamDRMTrait();
|
||||
addTrait(MediaTraitType.DRM,this.drmTrait);
|
||||
}
|
||||
|
||||
private function setupDRMTrait(contentData:ByteArray) : void
|
||||
{
|
||||
this.createDRMTrait();
|
||||
this.drmTrait.drmMetadata = contentData;
|
||||
}
|
||||
|
||||
private function onDRMErrorEvent(event:DRMErrorEvent) : void
|
||||
{
|
||||
if(event.errorID == DRM_NEEDS_AUTHENTICATION)
|
||||
{
|
||||
this.drmTrait.addEventListener(DRMEvent.DRM_STATE_CHANGE,this.reloadAfterAuth);
|
||||
this.drmTrait.drmMetadata = event.contentData;
|
||||
}
|
||||
else if(event.drmUpdateNeeded)
|
||||
{
|
||||
this.update(SystemUpdaterType.DRM);
|
||||
}
|
||||
else if(event.systemUpdateNeeded)
|
||||
{
|
||||
this.update(SystemUpdaterType.SYSTEM);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.drmTrait.inlineDRMFailed(new MediaError(event.errorID));
|
||||
}
|
||||
}
|
||||
|
||||
private function update(type:String) : void
|
||||
{
|
||||
if(this.drmTrait == null)
|
||||
{
|
||||
this.createDRMTrait();
|
||||
}
|
||||
var updater:SystemUpdater = this.drmTrait.update(type);
|
||||
updater.addEventListener(Event.COMPLETE,this.onUpdateComplete);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
package org.osmf.elements
|
||||
{
|
||||
import flash.events.Event;
|
||||
import org.osmf.elements.proxyClasses.LoadFromDocumentLoadTrait;
|
||||
import org.osmf.events.LoadEvent;
|
||||
import org.osmf.media.MediaResourceBase;
|
||||
import org.osmf.traits.LoadState;
|
||||
import org.osmf.traits.LoadTrait;
|
||||
import org.osmf.traits.LoaderBase;
|
||||
import org.osmf.traits.MediaTraitType;
|
||||
import org.osmf.utils.OSMFStrings;
|
||||
|
||||
public class LoadFromDocumentElement extends ProxyElement
|
||||
{
|
||||
|
||||
private var _resource:MediaResourceBase;
|
||||
|
||||
private var loadTrait:LoadFromDocumentLoadTrait;
|
||||
|
||||
private var loader:LoaderBase;
|
||||
|
||||
public function LoadFromDocumentElement(resource:MediaResourceBase = null, loader:LoaderBase = null)
|
||||
{
|
||||
super(null);
|
||||
this.loader = loader;
|
||||
this.resource = resource;
|
||||
if(loader == null)
|
||||
{
|
||||
throw new ArgumentError(OSMFStrings.getString(OSMFStrings.NULL_PARAM));
|
||||
}
|
||||
}
|
||||
|
||||
override public function set resource(value:MediaResourceBase) : void
|
||||
{
|
||||
if(this._resource != value && value != null)
|
||||
{
|
||||
this._resource = value;
|
||||
this.loadTrait = new LoadFromDocumentLoadTrait(this.loader,this.resource);
|
||||
this.loadTrait.addEventListener(LoadEvent.LOAD_STATE_CHANGE,this.onLoadStateChange,false,int.MAX_VALUE);
|
||||
if(super.getTrait(MediaTraitType.LOAD) != null)
|
||||
{
|
||||
super.removeTrait(MediaTraitType.LOAD);
|
||||
}
|
||||
super.addTrait(MediaTraitType.LOAD,this.loadTrait);
|
||||
}
|
||||
}
|
||||
|
||||
override public function get resource() : MediaResourceBase
|
||||
{
|
||||
return this._resource;
|
||||
}
|
||||
|
||||
private function onLoaderStateChange(event:Event) : void
|
||||
{
|
||||
removeTrait(MediaTraitType.LOAD);
|
||||
proxiedElement = this.loadTrait.mediaElement;
|
||||
}
|
||||
|
||||
private function onLoadStateChange(event:LoadEvent) : void
|
||||
{
|
||||
var proxiedLoadTrait:LoadTrait = null;
|
||||
var onProxiedElementLoadStateChange:Function = null;
|
||||
if(event.loadState == LoadState.READY)
|
||||
{
|
||||
onProxiedElementLoadStateChange = function(event:LoadEvent):void
|
||||
{
|
||||
if(event.loadState == LoadState.LOADING)
|
||||
{
|
||||
event.stopImmediatePropagation();
|
||||
}
|
||||
else
|
||||
{
|
||||
proxiedLoadTrait.removeEventListener(LoadEvent.LOAD_STATE_CHANGE,onProxiedElementLoadStateChange);
|
||||
}
|
||||
};
|
||||
event.stopImmediatePropagation();
|
||||
removeTrait(MediaTraitType.LOAD);
|
||||
proxiedLoadTrait = this.loadTrait.mediaElement.getTrait(MediaTraitType.LOAD) as LoadTrait;
|
||||
proxiedLoadTrait.addEventListener(LoadEvent.LOAD_STATE_CHANGE,onProxiedElementLoadStateChange,false,int.MAX_VALUE);
|
||||
proxiedElement = this.loadTrait.mediaElement;
|
||||
if(proxiedLoadTrait.loadState == LoadState.UNINITIALIZED)
|
||||
{
|
||||
proxiedLoadTrait.load();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,283 @@
|
||||
package org.osmf.elements
|
||||
{
|
||||
import org.osmf.elements.proxyClasses.ProxyMetadata;
|
||||
import org.osmf.events.ContainerChangeEvent;
|
||||
import org.osmf.events.MediaElementEvent;
|
||||
import org.osmf.events.MediaErrorEvent;
|
||||
import org.osmf.media.MediaElement;
|
||||
import org.osmf.media.MediaResourceBase;
|
||||
import org.osmf.metadata.Metadata;
|
||||
import org.osmf.traits.MediaTraitBase;
|
||||
import org.osmf.traits.MediaTraitType;
|
||||
import org.osmf.utils.OSMFStrings;
|
||||
|
||||
public class ProxyElement extends MediaElement
|
||||
{
|
||||
|
||||
private var _proxiedMetadata:ProxyMetadata;
|
||||
|
||||
private var _proxiedElement:MediaElement;
|
||||
|
||||
private var _blockedTraits:Vector.<String>;
|
||||
|
||||
public function ProxyElement(proxiedElement:MediaElement = null)
|
||||
{
|
||||
super();
|
||||
this.addEventListener(MediaElementEvent.TRAIT_ADD,this.onProxyTraitAdd,false,int.MAX_VALUE);
|
||||
this.addEventListener(MediaElementEvent.TRAIT_REMOVE,this.onProxyTraitRemove,false,int.MAX_VALUE);
|
||||
this.addEventListener(ContainerChangeEvent.CONTAINER_CHANGE,this.onProxyContainerChange);
|
||||
this.proxiedElement = proxiedElement;
|
||||
}
|
||||
|
||||
public function get proxiedElement() : MediaElement
|
||||
{
|
||||
return this._proxiedElement;
|
||||
}
|
||||
|
||||
public function set proxiedElement(value:MediaElement) : void
|
||||
{
|
||||
var traitType:String = null;
|
||||
if(value != this._proxiedElement)
|
||||
{
|
||||
if(this._proxiedElement != null)
|
||||
{
|
||||
this.toggleMediaElementListeners(this._proxiedElement,false);
|
||||
for each(traitType in this._proxiedElement.traitTypes)
|
||||
{
|
||||
if(super.hasTrait(traitType) == false && (this._blockedTraits == null || this._blockedTraits.indexOf(traitType) == -1))
|
||||
{
|
||||
super.dispatchEvent(new MediaElementEvent(MediaElementEvent.TRAIT_REMOVE,false,false,traitType));
|
||||
}
|
||||
}
|
||||
}
|
||||
this._proxiedElement = value;
|
||||
if(this._proxiedElement != null)
|
||||
{
|
||||
ProxyMetadata(metadata).metadata = this._proxiedElement.metadata;
|
||||
this._proxiedElement.dispatchEvent(new ContainerChangeEvent(ContainerChangeEvent.CONTAINER_CHANGE,false,false,this._proxiedElement.container,container));
|
||||
this.toggleMediaElementListeners(this._proxiedElement,true);
|
||||
for each(traitType in this._proxiedElement.traitTypes)
|
||||
{
|
||||
if(super.hasTrait(traitType) == false && (this._blockedTraits == null || this._blockedTraits.indexOf(traitType) == -1))
|
||||
{
|
||||
super.dispatchEvent(new MediaElementEvent(MediaElementEvent.TRAIT_ADD,false,false,traitType));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override public function get traitTypes() : Vector.<String>
|
||||
{
|
||||
var traitType:String = null;
|
||||
var results:Vector.<String> = new Vector.<String>();
|
||||
for each(traitType in MediaTraitType.ALL_TYPES)
|
||||
{
|
||||
if(this.hasTrait(traitType))
|
||||
{
|
||||
results.push(traitType);
|
||||
}
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
override public function hasTrait(type:String) : Boolean
|
||||
{
|
||||
if(type == null)
|
||||
{
|
||||
throw new ArgumentError(OSMFStrings.getString(OSMFStrings.INVALID_PARAM));
|
||||
}
|
||||
return this.getTrait(type) != null;
|
||||
}
|
||||
|
||||
override public function getTrait(type:String) : MediaTraitBase
|
||||
{
|
||||
if(type == null)
|
||||
{
|
||||
throw new ArgumentError(OSMFStrings.getString(OSMFStrings.INVALID_PARAM));
|
||||
}
|
||||
var trait:MediaTraitBase = null;
|
||||
if(this.blocksTrait(type) == false)
|
||||
{
|
||||
trait = super.getTrait(type) || (this.proxiedElement != null ? this.proxiedElement.getTrait(type) : null);
|
||||
}
|
||||
return trait;
|
||||
}
|
||||
|
||||
override public function get resource() : MediaResourceBase
|
||||
{
|
||||
return Boolean(this.proxiedElement) ? this.proxiedElement.resource : null;
|
||||
}
|
||||
|
||||
override public function set resource(value:MediaResourceBase) : void
|
||||
{
|
||||
if(this.proxiedElement != null)
|
||||
{
|
||||
this.proxiedElement.resource = value;
|
||||
}
|
||||
}
|
||||
|
||||
override protected function addTrait(type:String, instance:MediaTraitBase) : void
|
||||
{
|
||||
if(this.blocksTrait(type) == false && this.proxiedElement != null && this.proxiedElement.hasTrait(type) == true)
|
||||
{
|
||||
super.dispatchEvent(new MediaElementEvent(MediaElementEvent.TRAIT_REMOVE,false,false,type));
|
||||
}
|
||||
super.addTrait(type,instance);
|
||||
}
|
||||
|
||||
override protected function removeTrait(type:String) : MediaTraitBase
|
||||
{
|
||||
var result:MediaTraitBase = super.removeTrait(type);
|
||||
if(this.blocksTrait(type) == false && this.proxiedElement != null && this.proxiedElement.hasTrait(type) == true)
|
||||
{
|
||||
super.dispatchEvent(new MediaElementEvent(MediaElementEvent.TRAIT_ADD,false,false,type));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
override protected function createMetadata() : Metadata
|
||||
{
|
||||
return new ProxyMetadata();
|
||||
}
|
||||
|
||||
final protected function get blockedTraits() : Vector.<String>
|
||||
{
|
||||
if(this._blockedTraits == null)
|
||||
{
|
||||
this._blockedTraits = new Vector.<String>();
|
||||
}
|
||||
return this._blockedTraits;
|
||||
}
|
||||
|
||||
final protected function set blockedTraits(value:Vector.<String>) : void
|
||||
{
|
||||
var traitType:String = null;
|
||||
if(value == this._blockedTraits)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var newlyBlockedTraitTypes:Array = [];
|
||||
var previouslyBlockedTraitTypes:Array = [];
|
||||
if(this._proxiedElement != null)
|
||||
{
|
||||
for each(traitType in MediaTraitType.ALL_TYPES)
|
||||
{
|
||||
if(value.indexOf(traitType) != -1)
|
||||
{
|
||||
if(this._blockedTraits == null || this._blockedTraits.indexOf(traitType) == -1)
|
||||
{
|
||||
newlyBlockedTraitTypes.push(traitType);
|
||||
}
|
||||
}
|
||||
else if(this._blockedTraits != null && this._blockedTraits.indexOf(traitType) != -1)
|
||||
{
|
||||
previouslyBlockedTraitTypes.push(traitType);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(this._proxiedElement != null)
|
||||
{
|
||||
for each(traitType in newlyBlockedTraitTypes)
|
||||
{
|
||||
if(this.proxiedElement.hasTrait(traitType) || Boolean(super.hasTrait(traitType)))
|
||||
{
|
||||
dispatchEvent(new MediaElementEvent(MediaElementEvent.TRAIT_REMOVE,false,false,traitType));
|
||||
}
|
||||
}
|
||||
this._blockedTraits = value;
|
||||
for each(traitType in previouslyBlockedTraitTypes)
|
||||
{
|
||||
if(this.proxiedElement.hasTrait(traitType) || Boolean(super.hasTrait(traitType)))
|
||||
{
|
||||
dispatchEvent(new MediaElementEvent(MediaElementEvent.TRAIT_ADD,false,false,traitType));
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this._blockedTraits = value;
|
||||
}
|
||||
}
|
||||
|
||||
private function toggleMediaElementListeners(mediaElement:MediaElement, add:Boolean) : void
|
||||
{
|
||||
if(add)
|
||||
{
|
||||
this._proxiedElement.addEventListener(MediaErrorEvent.MEDIA_ERROR,this.onMediaError);
|
||||
this._proxiedElement.addEventListener(MediaElementEvent.TRAIT_ADD,this.onTraitAdd);
|
||||
this._proxiedElement.addEventListener(MediaElementEvent.TRAIT_REMOVE,this.onTraitRemove);
|
||||
this._proxiedElement.addEventListener(MediaElementEvent.METADATA_ADD,this.onMetadataEvent);
|
||||
this._proxiedElement.addEventListener(MediaElementEvent.METADATA_REMOVE,this.onMetadataEvent);
|
||||
}
|
||||
else
|
||||
{
|
||||
this._proxiedElement.removeEventListener(MediaErrorEvent.MEDIA_ERROR,this.onMediaError);
|
||||
this._proxiedElement.removeEventListener(MediaElementEvent.TRAIT_ADD,this.onTraitAdd);
|
||||
this._proxiedElement.removeEventListener(MediaElementEvent.TRAIT_REMOVE,this.onTraitRemove);
|
||||
this._proxiedElement.removeEventListener(MediaElementEvent.METADATA_ADD,this.onMetadataEvent);
|
||||
this._proxiedElement.removeEventListener(MediaElementEvent.METADATA_REMOVE,this.onMetadataEvent);
|
||||
}
|
||||
}
|
||||
|
||||
private function onMediaError(event:MediaErrorEvent) : void
|
||||
{
|
||||
dispatchEvent(event.clone());
|
||||
}
|
||||
|
||||
private function onTraitAdd(event:MediaElementEvent) : void
|
||||
{
|
||||
this.processTraitsChangeEvent(event);
|
||||
}
|
||||
|
||||
private function onTraitRemove(event:MediaElementEvent) : void
|
||||
{
|
||||
this.processTraitsChangeEvent(event);
|
||||
}
|
||||
|
||||
private function onMetadataEvent(event:MediaElementEvent) : void
|
||||
{
|
||||
dispatchEvent(event.clone());
|
||||
}
|
||||
|
||||
private function onProxyContainerChange(event:ContainerChangeEvent) : void
|
||||
{
|
||||
if(this.proxiedElement != null)
|
||||
{
|
||||
this.proxiedElement.dispatchEvent(event.clone());
|
||||
}
|
||||
}
|
||||
|
||||
private function onProxyTraitAdd(event:MediaElementEvent) : void
|
||||
{
|
||||
this.processProxyTraitsChangeEvent(event);
|
||||
}
|
||||
|
||||
private function onProxyTraitRemove(event:MediaElementEvent) : void
|
||||
{
|
||||
this.processProxyTraitsChangeEvent(event);
|
||||
}
|
||||
|
||||
private function processTraitsChangeEvent(event:MediaElementEvent) : void
|
||||
{
|
||||
if(this.blocksTrait(event.traitType) == false && super.hasTrait(event.traitType) == false)
|
||||
{
|
||||
super.dispatchEvent(event.clone());
|
||||
}
|
||||
}
|
||||
|
||||
private function processProxyTraitsChangeEvent(event:MediaElementEvent) : void
|
||||
{
|
||||
if(this.blocksTrait(event.traitType) == true)
|
||||
{
|
||||
event.stopImmediatePropagation();
|
||||
}
|
||||
}
|
||||
|
||||
private function blocksTrait(traitType:String) : Boolean
|
||||
{
|
||||
return Boolean(this._blockedTraits) && this._blockedTraits.indexOf(traitType) != -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
package org.osmf.elements
|
||||
{
|
||||
import org.osmf.elements.loaderClasses.LoaderLoadTrait;
|
||||
import org.osmf.elements.loaderClasses.LoaderUtils;
|
||||
import org.osmf.media.LoadableElementBase;
|
||||
import org.osmf.media.MediaResourceBase;
|
||||
import org.osmf.media.URLResource;
|
||||
import org.osmf.traits.LoadTrait;
|
||||
import org.osmf.traits.LoaderBase;
|
||||
import org.osmf.traits.MediaTraitType;
|
||||
|
||||
public class SWFElement extends LoadableElementBase
|
||||
{
|
||||
|
||||
public function SWFElement(resource:URLResource = null, loader:SWFLoader = null)
|
||||
{
|
||||
if(loader == null)
|
||||
{
|
||||
loader = new SWFLoader();
|
||||
}
|
||||
super(resource,loader);
|
||||
}
|
||||
|
||||
override protected function createLoadTrait(resource:MediaResourceBase, loader:LoaderBase) : LoadTrait
|
||||
{
|
||||
return new LoaderLoadTrait(loader,resource);
|
||||
}
|
||||
|
||||
override protected function processReadyState() : void
|
||||
{
|
||||
var loaderLoadTrait:LoaderLoadTrait = getTrait(MediaTraitType.LOAD) as LoaderLoadTrait;
|
||||
addTrait(MediaTraitType.DISPLAY_OBJECT,LoaderUtils.createDisplayObjectTrait(loaderLoadTrait.loader,this));
|
||||
}
|
||||
|
||||
override protected function processUnloadingState() : void
|
||||
{
|
||||
removeTrait(MediaTraitType.DISPLAY_OBJECT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
package org.osmf.elements
|
||||
{
|
||||
import org.osmf.elements.loaderClasses.LoaderUtils;
|
||||
import org.osmf.media.MediaResourceBase;
|
||||
import org.osmf.media.MediaType;
|
||||
import org.osmf.media.MediaTypeUtil;
|
||||
import org.osmf.media.URLResource;
|
||||
import org.osmf.traits.LoadTrait;
|
||||
import org.osmf.traits.LoaderBase;
|
||||
import org.osmf.utils.URL;
|
||||
|
||||
public class SWFLoader extends LoaderBase
|
||||
{
|
||||
|
||||
public static var allowValidationOfLoadedContent:Boolean = true;
|
||||
|
||||
private static const MIME_TYPES_SUPPORTED:Vector.<String> = Vector.<String>(["application/x-shockwave-flash"]);
|
||||
|
||||
private static const MEDIA_TYPES_SUPPORTED:Vector.<String> = Vector.<String>([MediaType.SWF]);
|
||||
|
||||
private var useCurrentSecurityDomain:Boolean = false;
|
||||
|
||||
private var _validateLoadedContentFunction:Function = null;
|
||||
|
||||
public function SWFLoader(useCurrentSecurityDomain:Boolean = false)
|
||||
{
|
||||
super();
|
||||
this.useCurrentSecurityDomain = useCurrentSecurityDomain;
|
||||
}
|
||||
|
||||
override public function canHandleResource(resource:MediaResourceBase) : Boolean
|
||||
{
|
||||
var url:URL = null;
|
||||
var rt:int = MediaTypeUtil.checkMetadataMatchWithResource(resource,MEDIA_TYPES_SUPPORTED,MIME_TYPES_SUPPORTED);
|
||||
if(rt != MediaTypeUtil.METADATA_MATCH_UNKNOWN)
|
||||
{
|
||||
return rt == MediaTypeUtil.METADATA_MATCH_FOUND;
|
||||
}
|
||||
var urlResource:URLResource = resource as URLResource;
|
||||
if(urlResource != null && urlResource.url != null)
|
||||
{
|
||||
url = new URL(urlResource.url);
|
||||
return url.path.search(/\.swf$/i) != -1;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
override protected function executeLoad(loadTrait:LoadTrait) : void
|
||||
{
|
||||
LoaderUtils.loadLoadTrait(loadTrait,updateLoadTrait,this.useCurrentSecurityDomain,false,this.validateLoadedContentFunction);
|
||||
}
|
||||
|
||||
override protected function executeUnload(loadTrait:LoadTrait) : void
|
||||
{
|
||||
LoaderUtils.unloadLoadTrait(loadTrait,updateLoadTrait);
|
||||
}
|
||||
|
||||
public function get validateLoadedContentFunction() : Function
|
||||
{
|
||||
return allowValidationOfLoadedContent ? this._validateLoadedContentFunction : null;
|
||||
}
|
||||
|
||||
public function set validateLoadedContentFunction(value:Function) : void
|
||||
{
|
||||
this._validateLoadedContentFunction = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,143 @@
|
||||
package org.osmf.elements
|
||||
{
|
||||
import flash.errors.IOError;
|
||||
import flash.events.IOErrorEvent;
|
||||
import flash.events.ProgressEvent;
|
||||
import flash.media.Sound;
|
||||
import flash.media.SoundLoaderContext;
|
||||
import flash.net.URLRequest;
|
||||
import org.osmf.elements.audioClasses.SoundLoadTrait;
|
||||
import org.osmf.events.MediaError;
|
||||
import org.osmf.events.MediaErrorCodes;
|
||||
import org.osmf.events.MediaErrorEvent;
|
||||
import org.osmf.media.MediaResourceBase;
|
||||
import org.osmf.media.MediaType;
|
||||
import org.osmf.media.MediaTypeUtil;
|
||||
import org.osmf.media.URLResource;
|
||||
import org.osmf.traits.LoadState;
|
||||
import org.osmf.traits.LoadTrait;
|
||||
import org.osmf.traits.LoaderBase;
|
||||
import org.osmf.utils.*;
|
||||
|
||||
public class SoundLoader extends LoaderBase
|
||||
{
|
||||
|
||||
private static const MIME_TYPES_SUPPORTED:Vector.<String> = Vector.<String>(["audio/mpeg"]);
|
||||
|
||||
private static const MEDIA_TYPES_SUPPORTED:Vector.<String> = Vector.<String>([MediaType.AUDIO]);
|
||||
|
||||
private static const MIN_BYTES_TO_RECEIVE:int = 16;
|
||||
|
||||
private var checkPolicyFile:Boolean;
|
||||
|
||||
public function SoundLoader(checkPolicyFile:Boolean = false)
|
||||
{
|
||||
super();
|
||||
this.checkPolicyFile = checkPolicyFile;
|
||||
}
|
||||
|
||||
override public function canHandleResource(resource:MediaResourceBase) : Boolean
|
||||
{
|
||||
var rt:int = MediaTypeUtil.checkMetadataMatchWithResource(resource,MEDIA_TYPES_SUPPORTED,MIME_TYPES_SUPPORTED);
|
||||
if(rt != MediaTypeUtil.METADATA_MATCH_UNKNOWN)
|
||||
{
|
||||
return rt == MediaTypeUtil.METADATA_MATCH_FOUND;
|
||||
}
|
||||
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 == "")
|
||||
{
|
||||
return url.path.search(/\.mp3$|\.m4a$/i) != -1;
|
||||
}
|
||||
if(url.protocol.search(/file$|http$|https$/i) != -1)
|
||||
{
|
||||
return url.path == null || url.path.length <= 0 || url.path.indexOf(".") == -1 || url.path.search(/\.mp3$|\.m4a$/i) != -1;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
override protected function executeLoad(loadTrait:LoadTrait) : void
|
||||
{
|
||||
var urlRequest:URLRequest;
|
||||
var context:SoundLoaderContext;
|
||||
var soundLoadTrait:SoundLoadTrait = null;
|
||||
var sound:Sound = null;
|
||||
var onProgress:Function = null;
|
||||
var onIOError:Function = null;
|
||||
var toggleSoundListeners:Function = function(sound:Sound, on:Boolean):void
|
||||
{
|
||||
if(on)
|
||||
{
|
||||
sound.addEventListener(ProgressEvent.PROGRESS,onProgress);
|
||||
sound.addEventListener(IOErrorEvent.IO_ERROR,onIOError);
|
||||
}
|
||||
else
|
||||
{
|
||||
sound.removeEventListener(ProgressEvent.PROGRESS,onProgress);
|
||||
sound.removeEventListener(IOErrorEvent.IO_ERROR,onIOError);
|
||||
}
|
||||
};
|
||||
onProgress = function(event:ProgressEvent):void
|
||||
{
|
||||
if(event.bytesTotal >= MIN_BYTES_TO_RECEIVE && soundLoadTrait.loadState == LoadState.LOADING)
|
||||
{
|
||||
toggleSoundListeners(sound,false);
|
||||
soundLoadTrait.sound = sound;
|
||||
updateLoadTrait(soundLoadTrait,LoadState.READY);
|
||||
}
|
||||
};
|
||||
onIOError = function(ioEvent:IOErrorEvent, ioEventDetail:String = null):void
|
||||
{
|
||||
toggleSoundListeners(sound,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)));
|
||||
};
|
||||
var handleSecurityError:Function = function(securityErrorDetail:String):void
|
||||
{
|
||||
toggleSoundListeners(sound,false);
|
||||
updateLoadTrait(loadTrait,LoadState.LOAD_ERROR);
|
||||
loadTrait.dispatchEvent(new MediaErrorEvent(MediaErrorEvent.MEDIA_ERROR,false,false,new MediaError(MediaErrorCodes.SECURITY_ERROR,securityErrorDetail)));
|
||||
};
|
||||
soundLoadTrait = loadTrait as SoundLoadTrait;
|
||||
updateLoadTrait(soundLoadTrait,LoadState.LOADING);
|
||||
sound = new Sound();
|
||||
toggleSoundListeners(sound,true);
|
||||
urlRequest = new URLRequest((soundLoadTrait.resource as URLResource).url.toString());
|
||||
context = new SoundLoaderContext(1000,this.checkPolicyFile);
|
||||
try
|
||||
{
|
||||
sound.load(urlRequest,context);
|
||||
}
|
||||
catch(ioError:IOError)
|
||||
{
|
||||
onIOError(null,ioError.message);
|
||||
}
|
||||
catch(securityError:SecurityError)
|
||||
{
|
||||
handleSecurityError(securityError.message);
|
||||
}
|
||||
}
|
||||
|
||||
override protected function executeUnload(loadTrait:LoadTrait) : void
|
||||
{
|
||||
var soundLoadTrait:SoundLoadTrait = loadTrait as SoundLoadTrait;
|
||||
updateLoadTrait(soundLoadTrait,LoadState.UNLOADING);
|
||||
try
|
||||
{
|
||||
if(soundLoadTrait.sound != null)
|
||||
{
|
||||
soundLoadTrait.sound.close();
|
||||
}
|
||||
}
|
||||
catch(error:IOError)
|
||||
{
|
||||
}
|
||||
updateLoadTrait(soundLoadTrait,LoadState.UNINITIALIZED);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package org.osmf.elements
|
||||
{
|
||||
import org.osmf.media.MediaResourceBase;
|
||||
import org.osmf.net.NetLoader;
|
||||
import org.osmf.net.httpstreaming.HTTPStreamingNetLoader;
|
||||
import org.osmf.net.rtmpstreaming.RTMPDynamicStreamingNetLoader;
|
||||
import org.osmf.traits.LoaderBase;
|
||||
|
||||
public class VideoElement extends LightweightVideoElement
|
||||
{
|
||||
|
||||
private var _alternateLoaders:Vector.<LoaderBase>;
|
||||
|
||||
public function VideoElement(resource:MediaResourceBase = null, loader:NetLoader = null)
|
||||
{
|
||||
super(null,null);
|
||||
super.loader = loader;
|
||||
this.resource = resource;
|
||||
}
|
||||
|
||||
override public function set resource(value:MediaResourceBase) : void
|
||||
{
|
||||
loader = getLoaderForResource(value,this.alternateLoaders);
|
||||
super.resource = value;
|
||||
}
|
||||
|
||||
private function get alternateLoaders() : Vector.<LoaderBase>
|
||||
{
|
||||
if(this._alternateLoaders == null)
|
||||
{
|
||||
this._alternateLoaders = new Vector.<LoaderBase>();
|
||||
this._alternateLoaders.push(new HTTPStreamingNetLoader());
|
||||
this._alternateLoaders.push(new RTMPDynamicStreamingNetLoader());
|
||||
this._alternateLoaders.push(new NetLoader());
|
||||
}
|
||||
return this._alternateLoaders;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
package org.osmf.elements.audioClasses
|
||||
{
|
||||
import flash.media.SoundTransform;
|
||||
import org.osmf.traits.AudioTrait;
|
||||
|
||||
[ExcludeClass]
|
||||
public class AudioAudioTrait extends AudioTrait
|
||||
{
|
||||
|
||||
private var soundAdapter:SoundAdapter;
|
||||
|
||||
public function AudioAudioTrait(soundAdapter:SoundAdapter)
|
||||
{
|
||||
super();
|
||||
this.soundAdapter = soundAdapter;
|
||||
soundAdapter.soundTransform.volume = volume;
|
||||
soundAdapter.soundTransform.pan = pan;
|
||||
}
|
||||
|
||||
override protected function volumeChangeStart(newVolume:Number) : void
|
||||
{
|
||||
var soundTransform:SoundTransform = this.soundAdapter.soundTransform;
|
||||
soundTransform.volume = muted ? 0 : newVolume;
|
||||
this.soundAdapter.soundTransform = soundTransform;
|
||||
}
|
||||
|
||||
override protected function mutedChangeStart(newMuted:Boolean) : void
|
||||
{
|
||||
var soundTransform:SoundTransform = this.soundAdapter.soundTransform;
|
||||
soundTransform.volume = newMuted ? 0 : volume;
|
||||
this.soundAdapter.soundTransform = soundTransform;
|
||||
}
|
||||
|
||||
override protected function panChangeStart(newPan:Number) : void
|
||||
{
|
||||
var soundTransform:SoundTransform = this.soundAdapter.soundTransform;
|
||||
soundTransform.pan = newPan;
|
||||
this.soundAdapter.soundTransform = soundTransform;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
package org.osmf.elements.audioClasses
|
||||
{
|
||||
import flash.events.Event;
|
||||
import org.osmf.traits.PlayState;
|
||||
import org.osmf.traits.PlayTrait;
|
||||
|
||||
[ExcludeClass]
|
||||
public class AudioPlayTrait extends PlayTrait
|
||||
{
|
||||
|
||||
private var lastPlayFailed:Boolean = false;
|
||||
|
||||
private var soundAdapter:SoundAdapter;
|
||||
|
||||
public function AudioPlayTrait(soundAdapter:SoundAdapter)
|
||||
{
|
||||
super();
|
||||
this.soundAdapter = soundAdapter;
|
||||
soundAdapter.addEventListener(Event.COMPLETE,this.onPlaybackComplete,false,1,true);
|
||||
}
|
||||
|
||||
override protected function playStateChangeStart(newPlayState:String) : void
|
||||
{
|
||||
if(newPlayState == PlayState.PLAYING)
|
||||
{
|
||||
this.lastPlayFailed = !this.soundAdapter.play();
|
||||
}
|
||||
else if(newPlayState == PlayState.PAUSED)
|
||||
{
|
||||
this.soundAdapter.pause();
|
||||
}
|
||||
else if(newPlayState == PlayState.STOPPED)
|
||||
{
|
||||
this.soundAdapter.stop();
|
||||
}
|
||||
}
|
||||
|
||||
override protected function playStateChangeEnd() : void
|
||||
{
|
||||
if(this.lastPlayFailed)
|
||||
{
|
||||
stop();
|
||||
this.lastPlayFailed = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
super.playStateChangeEnd();
|
||||
}
|
||||
}
|
||||
|
||||
private function onPlaybackComplete(event:Event) : void
|
||||
{
|
||||
stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package org.osmf.elements.audioClasses
|
||||
{
|
||||
import org.osmf.traits.SeekTrait;
|
||||
import org.osmf.traits.TimeTrait;
|
||||
|
||||
[ExcludeClass]
|
||||
public class AudioSeekTrait extends SeekTrait
|
||||
{
|
||||
|
||||
private var soundAdapter:SoundAdapter;
|
||||
|
||||
public function AudioSeekTrait(timeTrait:TimeTrait, soundAdapter:SoundAdapter)
|
||||
{
|
||||
super(timeTrait);
|
||||
this.soundAdapter = soundAdapter;
|
||||
}
|
||||
|
||||
override protected function seekingChangeStart(newSeeking:Boolean, time:Number) : void
|
||||
{
|
||||
if(newSeeking)
|
||||
{
|
||||
this.soundAdapter.seek(time);
|
||||
}
|
||||
}
|
||||
|
||||
override protected function seekingChangeEnd(time:Number) : void
|
||||
{
|
||||
super.seekingChangeEnd(time);
|
||||
if(seeking == true)
|
||||
{
|
||||
setSeeking(false,time);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
package org.osmf.elements.audioClasses
|
||||
{
|
||||
import flash.events.Event;
|
||||
import flash.events.ProgressEvent;
|
||||
import org.osmf.traits.TimeTrait;
|
||||
|
||||
[ExcludeClass]
|
||||
public class AudioTimeTrait extends TimeTrait
|
||||
{
|
||||
|
||||
private var soundAdapter:SoundAdapter;
|
||||
|
||||
public function AudioTimeTrait(soundAdapter:SoundAdapter)
|
||||
{
|
||||
super();
|
||||
this.soundAdapter = soundAdapter;
|
||||
soundAdapter.addEventListener(ProgressEvent.PROGRESS,this.onDownloadProgress,false,0,true);
|
||||
soundAdapter.addEventListener(SoundAdapter.DOWNLOAD_COMPLETE,this.onDownloadComplete,false,0,true);
|
||||
soundAdapter.addEventListener(Event.COMPLETE,this.onPlaybackComplete,false,0,true);
|
||||
}
|
||||
|
||||
override public function get currentTime() : Number
|
||||
{
|
||||
return this.soundAdapter.currentTime;
|
||||
}
|
||||
|
||||
private function onDownloadProgress(event:Event) : void
|
||||
{
|
||||
if(!isNaN(this.soundAdapter.estimatedDuration) && this.soundAdapter.estimatedDuration > 0)
|
||||
{
|
||||
this.soundAdapter.removeEventListener(ProgressEvent.PROGRESS,this.onDownloadProgress);
|
||||
setDuration(this.soundAdapter.estimatedDuration);
|
||||
}
|
||||
}
|
||||
|
||||
private function onDownloadComplete(event:Event) : void
|
||||
{
|
||||
setDuration(this.soundAdapter.estimatedDuration);
|
||||
}
|
||||
|
||||
private function onPlaybackComplete(event:Event) : void
|
||||
{
|
||||
signalComplete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,167 @@
|
||||
package org.osmf.elements.audioClasses
|
||||
{
|
||||
import flash.events.Event;
|
||||
import flash.events.EventDispatcher;
|
||||
import flash.events.IOErrorEvent;
|
||||
import flash.events.ProgressEvent;
|
||||
import flash.media.Sound;
|
||||
import flash.media.SoundChannel;
|
||||
import flash.media.SoundTransform;
|
||||
import org.osmf.events.MediaError;
|
||||
import org.osmf.events.MediaErrorCodes;
|
||||
import org.osmf.events.MediaErrorEvent;
|
||||
import org.osmf.media.MediaElement;
|
||||
|
||||
[Event(name="progress",type="flash.events.ProgressEvent")]
|
||||
[Event(name="downloadComplete",type="flash.events.Event")]
|
||||
[Event(name="complete",type="flash.events.Event")]
|
||||
[ExcludeClass]
|
||||
public class SoundAdapter extends EventDispatcher
|
||||
{
|
||||
|
||||
public static const DOWNLOAD_COMPLETE:String = "downloadComplete";
|
||||
|
||||
private var owner:MediaElement;
|
||||
|
||||
private var _soundTransform:SoundTransform;
|
||||
|
||||
private var sound:Sound;
|
||||
|
||||
private var playing:Boolean = false;
|
||||
|
||||
private var channel:SoundChannel;
|
||||
|
||||
private var lastStartTime:Number = 0;
|
||||
|
||||
public function SoundAdapter(owner:MediaElement, sound:Sound)
|
||||
{
|
||||
super();
|
||||
this.owner = owner;
|
||||
this.sound = sound;
|
||||
this._soundTransform = new SoundTransform();
|
||||
sound.addEventListener(Event.COMPLETE,this.onDownloadComplete,false,0,true);
|
||||
sound.addEventListener(ProgressEvent.PROGRESS,this.onProgress,false,0,true);
|
||||
sound.addEventListener(IOErrorEvent.IO_ERROR,this.onIOError,false,0,true);
|
||||
}
|
||||
|
||||
public function get currentTime() : Number
|
||||
{
|
||||
return this.channel != null ? this.channel.position / 1000 : this.lastStartTime / 1000;
|
||||
}
|
||||
|
||||
public function get estimatedDuration() : Number
|
||||
{
|
||||
return this.sound.length / (1000 * this.sound.bytesLoaded / this.sound.bytesTotal);
|
||||
}
|
||||
|
||||
public function get soundTransform() : SoundTransform
|
||||
{
|
||||
return this._soundTransform;
|
||||
}
|
||||
|
||||
public function set soundTransform(value:SoundTransform) : void
|
||||
{
|
||||
this._soundTransform = value;
|
||||
if(this.channel != null)
|
||||
{
|
||||
this.channel.soundTransform = value;
|
||||
}
|
||||
}
|
||||
|
||||
public function play(time:Number = -1) : Boolean
|
||||
{
|
||||
var success:Boolean = false;
|
||||
if(this.channel == null)
|
||||
{
|
||||
try
|
||||
{
|
||||
this.channel = this.sound.play(time != -1 ? time : this.lastStartTime);
|
||||
}
|
||||
catch(error:ArgumentError)
|
||||
{
|
||||
channel = null;
|
||||
}
|
||||
if(this.channel != null)
|
||||
{
|
||||
this.playing = true;
|
||||
this.channel.soundTransform = this._soundTransform;
|
||||
this.channel.addEventListener(Event.SOUND_COMPLETE,this.onSoundComplete);
|
||||
success = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.owner.dispatchEvent(new MediaErrorEvent(MediaErrorEvent.MEDIA_ERROR,false,false,new MediaError(MediaErrorCodes.SOUND_PLAY_FAILED)));
|
||||
}
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
public function pause() : void
|
||||
{
|
||||
if(this.channel != null)
|
||||
{
|
||||
this.lastStartTime = this.channel.position;
|
||||
this.clearChannel();
|
||||
this.playing = false;
|
||||
}
|
||||
}
|
||||
|
||||
public function stop() : void
|
||||
{
|
||||
if(this.channel != null)
|
||||
{
|
||||
this.lastStartTime = 0;
|
||||
this.clearChannel();
|
||||
this.playing = false;
|
||||
}
|
||||
}
|
||||
|
||||
public function seek(time:Number) : void
|
||||
{
|
||||
var wasPlaying:Boolean = this.playing;
|
||||
if(this.channel != null)
|
||||
{
|
||||
this.clearChannel();
|
||||
}
|
||||
this.play(time * 1000);
|
||||
if(wasPlaying == false)
|
||||
{
|
||||
this.pause();
|
||||
}
|
||||
}
|
||||
|
||||
private function clearChannel() : void
|
||||
{
|
||||
if(this.channel != null)
|
||||
{
|
||||
this.channel.removeEventListener(Event.SOUND_COMPLETE,this.onSoundComplete);
|
||||
this.channel.stop();
|
||||
this.channel = null;
|
||||
}
|
||||
}
|
||||
|
||||
private function onSoundComplete(event:Event) : void
|
||||
{
|
||||
this.lastStartTime = this.channel.position;
|
||||
this.clearChannel();
|
||||
this.playing = false;
|
||||
dispatchEvent(new Event(Event.COMPLETE));
|
||||
}
|
||||
|
||||
private function onDownloadComplete(event:Event) : void
|
||||
{
|
||||
dispatchEvent(new Event(DOWNLOAD_COMPLETE));
|
||||
}
|
||||
|
||||
private function onProgress(event:ProgressEvent) : void
|
||||
{
|
||||
dispatchEvent(event.clone());
|
||||
}
|
||||
|
||||
private function onIOError(event:IOErrorEvent) : void
|
||||
{
|
||||
this.owner.dispatchEvent(new MediaErrorEvent(MediaErrorEvent.MEDIA_ERROR,false,false,new MediaError(MediaErrorCodes.IO_ERROR)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
package org.osmf.elements.audioClasses
|
||||
{
|
||||
import flash.events.Event;
|
||||
import flash.events.ProgressEvent;
|
||||
import flash.media.Sound;
|
||||
import org.osmf.events.LoadEvent;
|
||||
import org.osmf.media.MediaResourceBase;
|
||||
import org.osmf.traits.LoadState;
|
||||
import org.osmf.traits.LoadTrait;
|
||||
import org.osmf.traits.LoaderBase;
|
||||
|
||||
[ExcludeClass]
|
||||
public class SoundLoadTrait extends LoadTrait
|
||||
{
|
||||
|
||||
private var lastBytesTotal:Number;
|
||||
|
||||
private var _sound:Sound;
|
||||
|
||||
public function SoundLoadTrait(loader:LoaderBase, resource:MediaResourceBase)
|
||||
{
|
||||
super(loader,resource);
|
||||
}
|
||||
|
||||
public function get sound() : Sound
|
||||
{
|
||||
return this._sound;
|
||||
}
|
||||
|
||||
public function set sound(value:Sound) : void
|
||||
{
|
||||
this._sound = value;
|
||||
}
|
||||
|
||||
override protected function loadStateChangeStart(newState:String) : void
|
||||
{
|
||||
if(newState == LoadState.READY)
|
||||
{
|
||||
if(this._sound != null)
|
||||
{
|
||||
this._sound.addEventListener(Event.OPEN,this.bytesTotalCheckingHandler,false,0,true);
|
||||
this._sound.addEventListener(ProgressEvent.PROGRESS,this.bytesTotalCheckingHandler,false,0,true);
|
||||
}
|
||||
}
|
||||
else if(newState == LoadState.UNINITIALIZED)
|
||||
{
|
||||
this._sound = null;
|
||||
}
|
||||
}
|
||||
|
||||
override public function get bytesLoaded() : Number
|
||||
{
|
||||
return Boolean(this._sound) ? this._sound.bytesLoaded : NaN;
|
||||
}
|
||||
|
||||
override public function get bytesTotal() : Number
|
||||
{
|
||||
return Boolean(this._sound) ? this._sound.bytesTotal : NaN;
|
||||
}
|
||||
|
||||
private function bytesTotalCheckingHandler(_:Event) : void
|
||||
{
|
||||
var event:LoadEvent = null;
|
||||
if(this.lastBytesTotal != this._sound.bytesTotal)
|
||||
{
|
||||
event = new LoadEvent(LoadEvent.BYTES_TOTAL_CHANGE,false,false,null,this._sound.bytesTotal);
|
||||
this.lastBytesTotal = this._sound.bytesTotal;
|
||||
dispatchEvent(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
package org.osmf.elements.compositeClasses
|
||||
{
|
||||
[ExcludeClass]
|
||||
public final class CompositionMode
|
||||
{
|
||||
|
||||
public static const PARALLEL:String = "parallel";
|
||||
|
||||
public static const SERIAL:String = "serial";
|
||||
|
||||
public function CompositionMode()
|
||||
{
|
||||
super();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
package org.osmf.elements.f4mClasses
|
||||
{
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
[ExcludeClass]
|
||||
internal class Base64Decoder
|
||||
{
|
||||
|
||||
private static const ESCAPE_CHAR_CODE:Number = 61;
|
||||
|
||||
private static const inverse:Array = [64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,62,64,64,64,63,52,53,54,55,56,57,58,59,60,61,64,64,64,64,64,64,64,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,64,64,64,64,64,64,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64];
|
||||
|
||||
private var count:int = 0;
|
||||
|
||||
private var data:ByteArray;
|
||||
|
||||
private var filled:int = 0;
|
||||
|
||||
private var work:Array = [0,0,0,0];
|
||||
|
||||
public function Base64Decoder()
|
||||
{
|
||||
super();
|
||||
this.data = new ByteArray();
|
||||
}
|
||||
|
||||
private static function copyByteArray(source:ByteArray, destination:ByteArray, length:uint = 0) : void
|
||||
{
|
||||
var oldPosition:int = int(source.position);
|
||||
source.position = 0;
|
||||
destination.position = 0;
|
||||
var i:uint = 0;
|
||||
while(source.bytesAvailable > 0 && i < length)
|
||||
{
|
||||
destination.writeByte(source.readByte());
|
||||
i++;
|
||||
}
|
||||
source.position = oldPosition;
|
||||
destination.position = 0;
|
||||
}
|
||||
|
||||
public function decode(encoded:String) : void
|
||||
{
|
||||
var c:Number = NaN;
|
||||
for(var i:uint = 0; i < encoded.length; i++)
|
||||
{
|
||||
c = encoded.charCodeAt(i);
|
||||
if(c == ESCAPE_CHAR_CODE)
|
||||
{
|
||||
this.work[this.count++] = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(inverse[c] == 64)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
this.work[this.count++] = inverse[c];
|
||||
}
|
||||
if(this.count == 4)
|
||||
{
|
||||
this.count = 0;
|
||||
this.data.writeByte(this.work[0] << 2 | (this.work[1] & 0xFF) >> 4);
|
||||
++this.filled;
|
||||
if(this.work[2] == -1)
|
||||
{
|
||||
break;
|
||||
}
|
||||
this.data.writeByte(this.work[1] << 4 | (this.work[2] & 0xFF) >> 2);
|
||||
++this.filled;
|
||||
if(this.work[3] == -1)
|
||||
{
|
||||
break;
|
||||
}
|
||||
this.data.writeByte(this.work[2] << 6 | this.work[3]);
|
||||
++this.filled;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function drain() : ByteArray
|
||||
{
|
||||
var result:ByteArray = new ByteArray();
|
||||
copyByteArray(this.data,result,this.filled);
|
||||
this.filled = 0;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package org.osmf.elements.f4mClasses
|
||||
{
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
[ExcludeClass]
|
||||
public class BootstrapInfo
|
||||
{
|
||||
|
||||
public var data:ByteArray;
|
||||
|
||||
public var url:String;
|
||||
|
||||
public var profile:String;
|
||||
|
||||
public var id:String;
|
||||
|
||||
public function BootstrapInfo()
|
||||
{
|
||||
super();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
package org.osmf.elements.f4mClasses
|
||||
{
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
[ExcludeClass]
|
||||
public class DRMAdditionalHeader
|
||||
{
|
||||
|
||||
public var data:ByteArray;
|
||||
|
||||
public var url:String;
|
||||
|
||||
public var id:String;
|
||||
|
||||
public function DRMAdditionalHeader()
|
||||
{
|
||||
super();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
package org.osmf.elements.f4mClasses
|
||||
{
|
||||
[ExcludeClass]
|
||||
internal class DateUtil
|
||||
{
|
||||
|
||||
public function DateUtil()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public static function parseW3CDTF(str:String) : Date
|
||||
{
|
||||
var finalDate:Date = null;
|
||||
var dateStr:String = null;
|
||||
var timeStr:String = null;
|
||||
var dateArr:Array = null;
|
||||
var year:Number = NaN;
|
||||
var month:Number = NaN;
|
||||
var date:Number = NaN;
|
||||
var multiplier:Number = NaN;
|
||||
var offsetHours:Number = NaN;
|
||||
var offsetMinutes:Number = NaN;
|
||||
var offsetStr:String = null;
|
||||
var timeArr:Array = null;
|
||||
var hour:Number = NaN;
|
||||
var minutes:Number = NaN;
|
||||
var secondsArr:Array = null;
|
||||
var seconds:Number = NaN;
|
||||
var milliseconds:Number = NaN;
|
||||
var utc:Number = NaN;
|
||||
var offset:Number = NaN;
|
||||
var eStr:String = null;
|
||||
try
|
||||
{
|
||||
dateStr = str.substring(0,str.indexOf("T"));
|
||||
timeStr = str.substring(str.indexOf("T") + 1,str.length);
|
||||
dateArr = dateStr.split("-");
|
||||
year = Number(dateArr.shift());
|
||||
month = Number(dateArr.shift());
|
||||
date = Number(dateArr.shift());
|
||||
if(timeStr.indexOf("Z") != -1)
|
||||
{
|
||||
multiplier = 1;
|
||||
offsetHours = 0;
|
||||
offsetMinutes = 0;
|
||||
timeStr = timeStr.replace("Z","");
|
||||
}
|
||||
else if(timeStr.indexOf("+") != -1)
|
||||
{
|
||||
multiplier = 1;
|
||||
offsetStr = timeStr.substring(timeStr.indexOf("+") + 1,timeStr.length);
|
||||
offsetHours = Number(offsetStr.substring(0,offsetStr.indexOf(":")));
|
||||
offsetMinutes = Number(offsetStr.substring(offsetStr.indexOf(":") + 1,offsetStr.length));
|
||||
timeStr = timeStr.substring(0,timeStr.indexOf("+"));
|
||||
}
|
||||
else
|
||||
{
|
||||
multiplier = -1;
|
||||
offsetStr = timeStr.substring(timeStr.indexOf("-") + 1,timeStr.length);
|
||||
offsetHours = Number(offsetStr.substring(0,offsetStr.indexOf(":")));
|
||||
offsetMinutes = Number(offsetStr.substring(offsetStr.indexOf(":") + 1,offsetStr.length));
|
||||
timeStr = timeStr.substring(0,timeStr.indexOf("-"));
|
||||
}
|
||||
timeArr = timeStr.split(":");
|
||||
hour = Number(timeArr.shift());
|
||||
minutes = Number(timeArr.shift());
|
||||
secondsArr = timeArr.length > 0 ? String(timeArr.shift()).split(".") : null;
|
||||
seconds = secondsArr != null && secondsArr.length > 0 ? Number(secondsArr.shift()) : 0;
|
||||
milliseconds = secondsArr != null && secondsArr.length > 0 ? Number(secondsArr.shift()) : 0;
|
||||
utc = Date.UTC(year,month - 1,date,hour,minutes,seconds,milliseconds);
|
||||
offset = (offsetHours * 3600000 + offsetMinutes * 60000) * multiplier;
|
||||
finalDate = new Date(utc - offset);
|
||||
if(finalDate.toString() == "Invalid Date")
|
||||
{
|
||||
throw new Error("This date does not conform to W3CDTF.");
|
||||
}
|
||||
}
|
||||
catch(e:Error)
|
||||
{
|
||||
eStr = "Unable to parse the string [" + str + "] into a date. ";
|
||||
eStr += "The internal error was: " + e.toString();
|
||||
throw new Error(eStr);
|
||||
}
|
||||
return finalDate;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
package org.osmf.elements.f4mClasses
|
||||
{
|
||||
import org.osmf.net.httpstreaming.dvr.DVRInfo;
|
||||
|
||||
[ExcludeClass]
|
||||
public class Manifest
|
||||
{
|
||||
|
||||
public var id:String;
|
||||
|
||||
public var baseURL:String;
|
||||
|
||||
public var urlIncludesFMSApplicationInstance:Boolean = false;
|
||||
|
||||
public var duration:Number;
|
||||
|
||||
public var mimeType:String;
|
||||
|
||||
public var streamType:String;
|
||||
|
||||
public var deliveryType:String;
|
||||
|
||||
public var startTime:Date;
|
||||
|
||||
public var bootstrapInfos:Vector.<BootstrapInfo> = new Vector.<BootstrapInfo>();
|
||||
|
||||
public var drmAdditionalHeaders:Vector.<DRMAdditionalHeader> = new Vector.<DRMAdditionalHeader>();
|
||||
|
||||
public var media:Vector.<Media> = new Vector.<Media>();
|
||||
|
||||
public var dvrInfo:DVRInfo = null;
|
||||
|
||||
public function Manifest()
|
||||
{
|
||||
super();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,597 @@
|
||||
package org.osmf.elements.f4mClasses
|
||||
{
|
||||
import flash.utils.ByteArray;
|
||||
import org.osmf.media.MediaResourceBase;
|
||||
import org.osmf.media.MediaType;
|
||||
import org.osmf.media.URLResource;
|
||||
import org.osmf.metadata.Metadata;
|
||||
import org.osmf.metadata.MetadataNamespaces;
|
||||
import org.osmf.net.DynamicStreamingItem;
|
||||
import org.osmf.net.DynamicStreamingResource;
|
||||
import org.osmf.net.MulticastResource;
|
||||
import org.osmf.net.NetStreamUtils;
|
||||
import org.osmf.net.StreamType;
|
||||
import org.osmf.net.StreamingURLResource;
|
||||
import org.osmf.net.httpstreaming.dvr.DVRInfo;
|
||||
import org.osmf.utils.OSMFStrings;
|
||||
import org.osmf.utils.URL;
|
||||
|
||||
[ExcludeClass]
|
||||
public class ManifestParser
|
||||
{
|
||||
|
||||
internal namespace xmlns = "http://ns.adobe.com/f4m/1.0";
|
||||
|
||||
public function ManifestParser()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public function parse(value:String, rootUrl:String = null) : Manifest
|
||||
{
|
||||
var dvrInfo:XML = null;
|
||||
var bitrateMissing:Boolean = false;
|
||||
var multicastParameterInvalid:Boolean = false;
|
||||
var media:XML = null;
|
||||
var data:XML = null;
|
||||
var info:XML = null;
|
||||
var newMedia:Media = null;
|
||||
var manifest:Manifest = new Manifest();
|
||||
var isMulticast:Boolean = false;
|
||||
var root:XML = new XML(value);
|
||||
if(root.id.length() > 0)
|
||||
{
|
||||
manifest.id = root.id.text();
|
||||
}
|
||||
if(root.duration.length() > 0)
|
||||
{
|
||||
manifest.duration = root.duration.text();
|
||||
}
|
||||
if(root.startTime.length() > 0)
|
||||
{
|
||||
manifest.startTime = DateUtil.parseW3CDTF(root.startTime.text());
|
||||
}
|
||||
if(root.mimeType.length() > 0)
|
||||
{
|
||||
manifest.mimeType = root.mimeType.text();
|
||||
}
|
||||
if(root.streamType.length() > 0)
|
||||
{
|
||||
manifest.streamType = root.streamType.text();
|
||||
}
|
||||
if(root.deliveryType.length() > 0)
|
||||
{
|
||||
manifest.deliveryType = root.deliveryType.text();
|
||||
}
|
||||
if(root.baseURL.length() > 0)
|
||||
{
|
||||
manifest.baseURL = root.baseURL.text();
|
||||
}
|
||||
if(root.urlIncludesFMSApplicationInstance.length() > 0)
|
||||
{
|
||||
manifest.urlIncludesFMSApplicationInstance = root.urlIncludesFMSApplicationInstance.text() == "true";
|
||||
}
|
||||
var baseUrl:String = manifest.baseURL != null ? manifest.baseURL : rootUrl;
|
||||
var _loc14_:int = 0;
|
||||
var _loc15_:* = root.dvrInfo;
|
||||
for each(dvrInfo in _loc15_)
|
||||
{
|
||||
this.parseDVRInfo(dvrInfo,baseUrl,manifest);
|
||||
}
|
||||
bitrateMissing = false;
|
||||
multicastParameterInvalid = false;
|
||||
for each(media in root.media)
|
||||
{
|
||||
newMedia = this.parseMedia(media,baseUrl);
|
||||
if(newMedia.multicastGroupspec != null && newMedia.multicastGroupspec.length > 0 && (newMedia.multicastStreamName == null || newMedia.multicastStreamName.length <= 0) || newMedia.multicastStreamName != null && newMedia.multicastStreamName.length > 0 && (newMedia.multicastGroupspec == null || newMedia.multicastGroupspec.length <= 0))
|
||||
{
|
||||
multicastParameterInvalid = true;
|
||||
}
|
||||
if(newMedia.multicastGroupspec != null && newMedia.multicastGroupspec.length > 0)
|
||||
{
|
||||
isMulticast = true;
|
||||
}
|
||||
manifest.media.push(newMedia);
|
||||
bitrateMissing ||= isNaN(newMedia.bitrate);
|
||||
}
|
||||
if(multicastParameterInvalid)
|
||||
{
|
||||
throw new ArgumentError(OSMFStrings.getString(OSMFStrings.MULTICAST_PARAMETER_INVALID));
|
||||
}
|
||||
if(manifest.media.length > 1 && isMulticast)
|
||||
{
|
||||
throw new ArgumentError(OSMFStrings.getString(OSMFStrings.MULTICAST_NOT_SUPPORT_MBR));
|
||||
}
|
||||
if(isMulticast)
|
||||
{
|
||||
manifest.streamType = StreamType.LIVE;
|
||||
}
|
||||
if(manifest.media.length > 1 && bitrateMissing)
|
||||
{
|
||||
throw new ArgumentError(OSMFStrings.getString(OSMFStrings.F4M_PARSE_BITRATE_MISSING));
|
||||
}
|
||||
for each(data in root.drmAdditionalHeader)
|
||||
{
|
||||
this.parseDRMAdditionalHeader(data,manifest.media,baseUrl,manifest);
|
||||
}
|
||||
for each(info in root.bootstrapInfo)
|
||||
{
|
||||
this.parseBootstrapInfo(info,manifest.media,baseUrl,manifest);
|
||||
}
|
||||
this.generateRTMPBaseURL(manifest);
|
||||
return manifest;
|
||||
}
|
||||
|
||||
private function parseMedia(value:XML, baseUrl:String) : Media
|
||||
{
|
||||
var decoder:Base64Decoder = null;
|
||||
var data:ByteArray = null;
|
||||
var header:String = null;
|
||||
var metaInfo:Object = null;
|
||||
var media:Media = new Media();
|
||||
if(value.attribute("url").length() > 0)
|
||||
{
|
||||
media.url = value.@url;
|
||||
if(value.attribute("bitrate").length() > 0)
|
||||
{
|
||||
media.bitrate = value.@bitrate;
|
||||
}
|
||||
if(value.attribute("drmAdditionalHeaderId").length() > 0)
|
||||
{
|
||||
media.drmAdditionalHeader.id = value.@drmAdditionalHeaderId;
|
||||
}
|
||||
if(value.attribute("bootstrapInfoId").length() > 0)
|
||||
{
|
||||
media.bootstrapInfo = new BootstrapInfo();
|
||||
media.bootstrapInfo.id = value.@bootstrapInfoId;
|
||||
}
|
||||
if(value.attribute("height").length() > 0)
|
||||
{
|
||||
media.height = value.@height;
|
||||
}
|
||||
if(value.attribute("width").length() > 0)
|
||||
{
|
||||
media.width = value.@width;
|
||||
}
|
||||
if(value.attribute("groupspec").length() > 0)
|
||||
{
|
||||
media.multicastGroupspec = value.@groupspec;
|
||||
}
|
||||
if(value.attribute("multicastStreamName").length() > 0)
|
||||
{
|
||||
media.multicastStreamName = value.@multicastStreamName;
|
||||
}
|
||||
if(value.moov.length() > 0)
|
||||
{
|
||||
decoder = new Base64Decoder();
|
||||
decoder.decode(value.moov.text());
|
||||
media.moov = decoder.drain();
|
||||
}
|
||||
if(value.metadata.length() > 0)
|
||||
{
|
||||
decoder = new Base64Decoder();
|
||||
decoder.decode(value.metadata.text());
|
||||
data = decoder.drain();
|
||||
data.position = 0;
|
||||
data.objectEncoding = 0;
|
||||
try
|
||||
{
|
||||
header = data.readObject() as String;
|
||||
metaInfo = data.readObject();
|
||||
media.metadata = metaInfo;
|
||||
}
|
||||
catch(e:Error)
|
||||
{
|
||||
}
|
||||
}
|
||||
if(value.xmpMetadata.length() > 0)
|
||||
{
|
||||
decoder = new Base64Decoder();
|
||||
decoder.decode(value.xmpMetadata.text());
|
||||
media.xmp = decoder.drain();
|
||||
}
|
||||
return media;
|
||||
}
|
||||
throw new ArgumentError(OSMFStrings.getString(OSMFStrings.F4M_PARSE_MEDIA_URL_MISSING));
|
||||
}
|
||||
|
||||
private function parseDVRInfo(value:XML, baseUrl:String, manifest:Manifest) : void
|
||||
{
|
||||
var url:String = null;
|
||||
var v:Number = NaN;
|
||||
var s:String = null;
|
||||
var dvrInfo:DVRInfo = new DVRInfo();
|
||||
if(value.attribute("id").length() > 0)
|
||||
{
|
||||
dvrInfo.id = value.@id;
|
||||
}
|
||||
if(value.attribute("url").length() > 0)
|
||||
{
|
||||
url = value.@url;
|
||||
if(!this.isAbsoluteURL(url))
|
||||
{
|
||||
url = baseUrl + "/" + url;
|
||||
}
|
||||
dvrInfo.url = url;
|
||||
}
|
||||
if(value.attribute("beginOffset").length() > 0)
|
||||
{
|
||||
dvrInfo.beginOffset = Math.max(0,parseInt(value.@beginOffset));
|
||||
}
|
||||
if(value.attribute("endOffset").length() > 0)
|
||||
{
|
||||
v = new Number(value.@endOffset);
|
||||
if(v > 0 && v < 1)
|
||||
{
|
||||
dvrInfo.endOffset = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
dvrInfo.endOffset = Math.max(0,v);
|
||||
}
|
||||
}
|
||||
if(value.attribute("offline").length() > 0)
|
||||
{
|
||||
s = value.@offline;
|
||||
dvrInfo.offline = s.toLowerCase() == "true";
|
||||
}
|
||||
manifest.dvrInfo = dvrInfo;
|
||||
}
|
||||
|
||||
private function parseDRMAdditionalHeader(value:XML, allMedia:Vector.<Media>, baseUrl:String, manifest:Manifest) : void
|
||||
{
|
||||
var media:Media = null;
|
||||
var metadata:String = null;
|
||||
var decoder:Base64Decoder = null;
|
||||
var url:String = null;
|
||||
var drmAdditionalHeader:DRMAdditionalHeader = new DRMAdditionalHeader();
|
||||
if(value.attribute("id").length() > 0)
|
||||
{
|
||||
drmAdditionalHeader.id = value.@id;
|
||||
}
|
||||
if(value.attribute("url").length() > 0)
|
||||
{
|
||||
url = value.@url;
|
||||
if(!this.isAbsoluteURL(url))
|
||||
{
|
||||
url = baseUrl + "/" + url;
|
||||
}
|
||||
drmAdditionalHeader.url = url;
|
||||
}
|
||||
else
|
||||
{
|
||||
metadata = value.text();
|
||||
decoder = new Base64Decoder();
|
||||
decoder.decode(metadata);
|
||||
drmAdditionalHeader.data = decoder.drain();
|
||||
}
|
||||
manifest.drmAdditionalHeaders.push(drmAdditionalHeader);
|
||||
for each(media in allMedia)
|
||||
{
|
||||
if(media.drmAdditionalHeader.id == drmAdditionalHeader.id)
|
||||
{
|
||||
media.drmAdditionalHeader = drmAdditionalHeader;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function parseBootstrapInfo(value:XML, allMedia:Vector.<Media>, baseUrl:String, manifest:Manifest) : void
|
||||
{
|
||||
var media:Media = null;
|
||||
var metadata:String = null;
|
||||
var decoder:Base64Decoder = null;
|
||||
var url:String = null;
|
||||
var bootstrapInfo:BootstrapInfo = new BootstrapInfo();
|
||||
if(value.attribute("profile").length() > 0)
|
||||
{
|
||||
bootstrapInfo.profile = value.@profile;
|
||||
if(value.attribute("id").length() > 0)
|
||||
{
|
||||
bootstrapInfo.id = value.@id;
|
||||
}
|
||||
if(value.attribute("url").length() > 0)
|
||||
{
|
||||
url = value.@url;
|
||||
if(!this.isAbsoluteURL(url) && baseUrl != null)
|
||||
{
|
||||
url = baseUrl + "/" + url;
|
||||
}
|
||||
bootstrapInfo.url = url;
|
||||
}
|
||||
else
|
||||
{
|
||||
metadata = value.text();
|
||||
decoder = new Base64Decoder();
|
||||
decoder.decode(metadata);
|
||||
bootstrapInfo.data = decoder.drain();
|
||||
}
|
||||
for each(media in allMedia)
|
||||
{
|
||||
if(media.bootstrapInfo == null)
|
||||
{
|
||||
media.bootstrapInfo = bootstrapInfo;
|
||||
}
|
||||
else if(media.bootstrapInfo.id == bootstrapInfo.id)
|
||||
{
|
||||
media.bootstrapInfo = bootstrapInfo;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
throw new ArgumentError(OSMFStrings.getString(OSMFStrings.F4M_PARSE_PROFILE_MISSING));
|
||||
}
|
||||
|
||||
private function generateRTMPBaseURL(manifest:Manifest) : void
|
||||
{
|
||||
var media:Media = null;
|
||||
if(manifest.baseURL == null)
|
||||
{
|
||||
for each(media in manifest.media)
|
||||
{
|
||||
if(NetStreamUtils.isRTMPStream(media.url))
|
||||
{
|
||||
manifest.baseURL = media.url;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function createResource(value:Manifest, manifestResource:URLResource) : MediaResourceBase
|
||||
{
|
||||
var resource:StreamingURLResource = null;
|
||||
var media:Media = null;
|
||||
var serverBaseURLs:Vector.<String> = null;
|
||||
var url:String = null;
|
||||
var bootstrapInfoURLString:String = null;
|
||||
var baseURLString:String = null;
|
||||
var baseURL:String = null;
|
||||
var dynResource:DynamicStreamingResource = null;
|
||||
var streamItems:Vector.<DynamicStreamingItem> = null;
|
||||
var stream:String = null;
|
||||
var item:DynamicStreamingItem = null;
|
||||
var drmMetadata:Metadata = null;
|
||||
var httpMetadata:Metadata = null;
|
||||
var manifestURL:URL = new URL(manifestResource.url);
|
||||
var cleanedPath:String = "/" + manifestURL.path;
|
||||
cleanedPath = cleanedPath.substr(0,cleanedPath.lastIndexOf("/"));
|
||||
var manifestFolder:String = manifestURL.protocol + "://" + manifestURL.host + (manifestURL.port != "" ? ":" + manifestURL.port : "") + cleanedPath;
|
||||
if(value.media.length == 1)
|
||||
{
|
||||
media = value.media[0] as Media;
|
||||
url = media.url;
|
||||
baseURLString = null;
|
||||
if(this.isAbsoluteURL(url))
|
||||
{
|
||||
baseURLString = media.url.substr(0,media.url.lastIndexOf("/"));
|
||||
}
|
||||
else if(value.baseURL != null)
|
||||
{
|
||||
baseURLString = value.baseURL;
|
||||
}
|
||||
else
|
||||
{
|
||||
baseURLString = manifestFolder;
|
||||
}
|
||||
if(media.multicastGroupspec != null && media.multicastGroupspec.length > 0 && media.multicastStreamName != null && media.multicastStreamName.length > 0)
|
||||
{
|
||||
if(this.isAbsoluteURL(url))
|
||||
{
|
||||
resource = new MulticastResource(url,value.streamType);
|
||||
}
|
||||
else if(value.baseURL != null)
|
||||
{
|
||||
resource = new MulticastResource(value.baseURL + "/" + url,this.streamType(value));
|
||||
}
|
||||
else
|
||||
{
|
||||
resource = new MulticastResource(manifestFolder + "/" + url,this.streamType(value));
|
||||
}
|
||||
MulticastResource(resource).groupspec = media.multicastGroupspec;
|
||||
MulticastResource(resource).streamName = media.multicastStreamName;
|
||||
}
|
||||
else if(this.isAbsoluteURL(url))
|
||||
{
|
||||
resource = new StreamingURLResource(url,value.streamType);
|
||||
}
|
||||
else if(value.baseURL != null)
|
||||
{
|
||||
resource = new StreamingURLResource(value.baseURL + "/" + url,this.streamType(value));
|
||||
}
|
||||
else
|
||||
{
|
||||
resource = new StreamingURLResource(manifestFolder + "/" + url,this.streamType(value));
|
||||
}
|
||||
resource.urlIncludesFMSApplicationInstance = value.urlIncludesFMSApplicationInstance;
|
||||
if(media.bootstrapInfo != null)
|
||||
{
|
||||
serverBaseURLs = new Vector.<String>();
|
||||
serverBaseURLs.push(baseURLString);
|
||||
bootstrapInfoURLString = media.bootstrapInfo.url;
|
||||
if(media.bootstrapInfo.url != null && this.isAbsoluteURL(media.bootstrapInfo.url) == false)
|
||||
{
|
||||
bootstrapInfoURLString = manifestFolder + "/" + bootstrapInfoURLString;
|
||||
media.bootstrapInfo.url = bootstrapInfoURLString;
|
||||
}
|
||||
httpMetadata = new Metadata();
|
||||
httpMetadata.addValue(MetadataNamespaces.HTTP_STREAMING_BOOTSTRAP_KEY,media.bootstrapInfo);
|
||||
if(serverBaseURLs.length > 0)
|
||||
{
|
||||
httpMetadata.addValue(MetadataNamespaces.HTTP_STREAMING_SERVER_BASE_URLS_KEY,serverBaseURLs);
|
||||
}
|
||||
}
|
||||
if(media.metadata != null)
|
||||
{
|
||||
if(httpMetadata == null)
|
||||
{
|
||||
httpMetadata = new Metadata();
|
||||
}
|
||||
httpMetadata.addValue(MetadataNamespaces.HTTP_STREAMING_STREAM_METADATA_KEY,media.metadata);
|
||||
}
|
||||
if(media.xmp != null)
|
||||
{
|
||||
if(httpMetadata == null)
|
||||
{
|
||||
httpMetadata = new Metadata();
|
||||
}
|
||||
httpMetadata.addValue(MetadataNamespaces.HTTP_STREAMING_XMP_METADATA_KEY,media.xmp);
|
||||
}
|
||||
if(media.drmAdditionalHeader != null)
|
||||
{
|
||||
drmMetadata = new Metadata();
|
||||
if(Media(value.media[0]).drmAdditionalHeader != null && Media(value.media[0]).drmAdditionalHeader.data != null)
|
||||
{
|
||||
drmMetadata.addValue(MetadataNamespaces.DRM_ADDITIONAL_HEADER_KEY,Media(value.media[0]).drmAdditionalHeader.data);
|
||||
resource.drmContentData = this.extractDRMMetadata(Media(value.media[0]).drmAdditionalHeader.data);
|
||||
}
|
||||
}
|
||||
if(httpMetadata != null)
|
||||
{
|
||||
resource.addMetadataValue(MetadataNamespaces.HTTP_STREAMING_METADATA,httpMetadata);
|
||||
}
|
||||
if(drmMetadata != null)
|
||||
{
|
||||
resource.addMetadataValue(MetadataNamespaces.DRM_METADATA,drmMetadata);
|
||||
}
|
||||
}
|
||||
else if(value.media.length > 1)
|
||||
{
|
||||
baseURL = value.baseURL != null ? value.baseURL : manifestFolder;
|
||||
serverBaseURLs = new Vector.<String>();
|
||||
serverBaseURLs.push(baseURL);
|
||||
dynResource = new DynamicStreamingResource(baseURL,this.streamType(value));
|
||||
dynResource.urlIncludesFMSApplicationInstance = value.urlIncludesFMSApplicationInstance;
|
||||
streamItems = new Vector.<DynamicStreamingItem>();
|
||||
if(NetStreamUtils.isRTMPStream(baseURL) == false)
|
||||
{
|
||||
httpMetadata = new Metadata();
|
||||
dynResource.addMetadataValue(MetadataNamespaces.HTTP_STREAMING_METADATA,httpMetadata);
|
||||
httpMetadata.addValue(MetadataNamespaces.HTTP_STREAMING_SERVER_BASE_URLS_KEY,serverBaseURLs);
|
||||
}
|
||||
for each(media in value.media)
|
||||
{
|
||||
if(this.isAbsoluteURL(media.url))
|
||||
{
|
||||
stream = NetStreamUtils.getStreamNameFromURL(media.url);
|
||||
}
|
||||
else
|
||||
{
|
||||
stream = media.url;
|
||||
}
|
||||
item = new DynamicStreamingItem(stream,media.bitrate,media.width,media.height);
|
||||
streamItems.push(item);
|
||||
if(media.drmAdditionalHeader != null)
|
||||
{
|
||||
if(dynResource.getMetadataValue(MetadataNamespaces.DRM_METADATA) == null)
|
||||
{
|
||||
drmMetadata = new Metadata();
|
||||
dynResource.addMetadataValue(MetadataNamespaces.DRM_METADATA,drmMetadata);
|
||||
}
|
||||
if(media.drmAdditionalHeader != null && media.drmAdditionalHeader.data != null)
|
||||
{
|
||||
drmMetadata.addValue(item.streamName,this.extractDRMMetadata(media.drmAdditionalHeader.data));
|
||||
drmMetadata.addValue(MetadataNamespaces.DRM_ADDITIONAL_HEADER_KEY + item.streamName,media.drmAdditionalHeader.data);
|
||||
}
|
||||
}
|
||||
if(media.bootstrapInfo != null)
|
||||
{
|
||||
bootstrapInfoURLString = Boolean(media.bootstrapInfo.url) ? media.bootstrapInfo.url : null;
|
||||
if(media.bootstrapInfo.url != null && this.isAbsoluteURL(media.bootstrapInfo.url) == false)
|
||||
{
|
||||
bootstrapInfoURLString = manifestFolder + "/" + bootstrapInfoURLString;
|
||||
media.bootstrapInfo.url = bootstrapInfoURLString;
|
||||
}
|
||||
httpMetadata.addValue(MetadataNamespaces.HTTP_STREAMING_BOOTSTRAP_KEY + item.streamName,media.bootstrapInfo);
|
||||
}
|
||||
if(media.metadata != null)
|
||||
{
|
||||
httpMetadata.addValue(MetadataNamespaces.HTTP_STREAMING_STREAM_METADATA_KEY + item.streamName,media.metadata);
|
||||
}
|
||||
if(media.xmp != null)
|
||||
{
|
||||
httpMetadata.addValue(MetadataNamespaces.HTTP_STREAMING_XMP_METADATA_KEY + item.streamName,media.xmp);
|
||||
}
|
||||
}
|
||||
dynResource.streamItems = streamItems;
|
||||
resource = dynResource;
|
||||
}
|
||||
else if(value.baseURL == null)
|
||||
{
|
||||
throw new ArgumentError(OSMFStrings.getString(OSMFStrings.F4M_PARSE_MEDIA_URL_MISSING));
|
||||
}
|
||||
if(value.mimeType != null)
|
||||
{
|
||||
resource.mediaType = MediaType.VIDEO;
|
||||
resource.mimeType = value.mimeType;
|
||||
}
|
||||
var streamingManifestResource:StreamingURLResource = manifestResource as StreamingURLResource;
|
||||
if(streamingManifestResource != null)
|
||||
{
|
||||
resource.clipStartTime = streamingManifestResource.clipStartTime;
|
||||
resource.clipEndTime = streamingManifestResource.clipEndTime;
|
||||
}
|
||||
resource.addMetadataValue(MetadataNamespaces.DERIVED_RESOURCE_METADATA,manifestResource);
|
||||
this.addDVRInfo(value,resource);
|
||||
return resource;
|
||||
}
|
||||
|
||||
private function isAbsoluteURL(url:String) : Boolean
|
||||
{
|
||||
var theURL:URL = new URL(url);
|
||||
return theURL.absolute;
|
||||
}
|
||||
|
||||
private function extractDRMMetadata(data:ByteArray) : ByteArray
|
||||
{
|
||||
var header:Object = null;
|
||||
var encryption:Object = null;
|
||||
var enc:Object = null;
|
||||
var params:Object = null;
|
||||
var keyInfo:Object = null;
|
||||
var fmrmsMetadata:Object = null;
|
||||
var drmMetadata:String = null;
|
||||
var decoder:Base64Decoder = null;
|
||||
var metadata:ByteArray = null;
|
||||
data.position = 0;
|
||||
data.objectEncoding = 0;
|
||||
try
|
||||
{
|
||||
header = data.readObject();
|
||||
encryption = data.readObject();
|
||||
enc = encryption["Encryption"];
|
||||
params = enc["Params"];
|
||||
keyInfo = params["KeyInfo"];
|
||||
fmrmsMetadata = keyInfo["FMRMS_METADATA"];
|
||||
drmMetadata = fmrmsMetadata["Metadata"] as String;
|
||||
decoder = new Base64Decoder();
|
||||
decoder.decode(drmMetadata);
|
||||
metadata = decoder.drain();
|
||||
}
|
||||
catch(e:Error)
|
||||
{
|
||||
metadata = null;
|
||||
}
|
||||
return metadata;
|
||||
}
|
||||
|
||||
private function addDVRInfo(manifest:Manifest, resource:StreamingURLResource) : void
|
||||
{
|
||||
if(manifest.dvrInfo == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var metadata:Metadata = new Metadata();
|
||||
metadata.addValue(MetadataNamespaces.HTTP_STREAMING_DVR_BEGIN_OFFSET_KEY,manifest.dvrInfo.beginOffset);
|
||||
metadata.addValue(MetadataNamespaces.HTTP_STREAMING_DVR_END_OFFSET_KEY,manifest.dvrInfo.endOffset);
|
||||
metadata.addValue(MetadataNamespaces.HTTP_STREAMING_DVR_OFFLINE_KEY,manifest.dvrInfo.offline);
|
||||
metadata.addValue(MetadataNamespaces.HTTP_STREAMING_DVR_ID_KEY,manifest.dvrInfo.id);
|
||||
resource.addMetadataValue(MetadataNamespaces.DVR_METADATA,metadata);
|
||||
}
|
||||
|
||||
private function streamType(value:Manifest) : String
|
||||
{
|
||||
return value.streamType == StreamType.LIVE && value.dvrInfo != null ? StreamType.DVR : value.streamType;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package org.osmf.elements.f4mClasses
|
||||
{
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
internal class Media
|
||||
{
|
||||
|
||||
public var drmAdditionalHeader:DRMAdditionalHeader = new DRMAdditionalHeader();
|
||||
|
||||
public var bootstrapInfo:BootstrapInfo;
|
||||
|
||||
public var metadata:Object;
|
||||
|
||||
public var xmp:ByteArray;
|
||||
|
||||
public var url:String;
|
||||
|
||||
public var bitrate:Number;
|
||||
|
||||
public var moov:ByteArray;
|
||||
|
||||
public var width:Number;
|
||||
|
||||
public var height:Number;
|
||||
|
||||
public var multicastGroupspec:String;
|
||||
|
||||
public var multicastStreamName:String;
|
||||
|
||||
public function Media()
|
||||
{
|
||||
super();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
package org.osmf.elements.loaderClasses
|
||||
{
|
||||
import flash.display.Loader;
|
||||
import flash.events.ProgressEvent;
|
||||
import org.osmf.media.MediaResourceBase;
|
||||
import org.osmf.traits.LoadState;
|
||||
import org.osmf.traits.LoadTrait;
|
||||
import org.osmf.traits.LoaderBase;
|
||||
|
||||
[ExcludeClass]
|
||||
public class LoaderLoadTrait extends LoadTrait
|
||||
{
|
||||
|
||||
private var _loader:Loader;
|
||||
|
||||
public function LoaderLoadTrait(loader:LoaderBase, resource:MediaResourceBase)
|
||||
{
|
||||
super(loader,resource);
|
||||
}
|
||||
|
||||
public function get loader() : Loader
|
||||
{
|
||||
return this._loader;
|
||||
}
|
||||
|
||||
public function set loader(value:Loader) : void
|
||||
{
|
||||
this._loader = value;
|
||||
}
|
||||
|
||||
override protected function loadStateChangeStart(newState:String) : void
|
||||
{
|
||||
if(newState == LoadState.LOADING)
|
||||
{
|
||||
this.loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,this.onContentLoadProgress,false,0,true);
|
||||
}
|
||||
else if(newState == LoadState.READY)
|
||||
{
|
||||
setBytesTotal(this.loader.contentLoaderInfo.bytesTotal);
|
||||
setBytesLoaded(this.loader.contentLoaderInfo.bytesLoaded);
|
||||
this.loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,this.onContentLoadProgress,false,0,true);
|
||||
}
|
||||
else if(newState == LoadState.UNINITIALIZED)
|
||||
{
|
||||
setBytesLoaded(0);
|
||||
}
|
||||
}
|
||||
|
||||
private function onContentLoadProgress(event:ProgressEvent) : void
|
||||
{
|
||||
setBytesTotal(event.bytesTotal);
|
||||
setBytesLoaded(event.bytesLoaded);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,175 @@
|
||||
package org.osmf.elements.loaderClasses
|
||||
{
|
||||
import flash.display.DisplayObject;
|
||||
import flash.display.Loader;
|
||||
import flash.display.LoaderInfo;
|
||||
import flash.errors.IOError;
|
||||
import flash.events.Event;
|
||||
import flash.events.IOErrorEvent;
|
||||
import flash.events.SecurityErrorEvent;
|
||||
import flash.events.TimerEvent;
|
||||
import flash.geom.Rectangle;
|
||||
import flash.net.URLRequest;
|
||||
import flash.system.ApplicationDomain;
|
||||
import flash.system.Capabilities;
|
||||
import flash.system.LoaderContext;
|
||||
import flash.system.SecurityDomain;
|
||||
import flash.utils.Timer;
|
||||
import org.osmf.events.MediaError;
|
||||
import org.osmf.events.MediaErrorCodes;
|
||||
import org.osmf.events.MediaErrorEvent;
|
||||
import org.osmf.media.MediaElement;
|
||||
import org.osmf.media.URLResource;
|
||||
import org.osmf.traits.DisplayObjectTrait;
|
||||
import org.osmf.traits.LoadState;
|
||||
import org.osmf.traits.LoadTrait;
|
||||
|
||||
[ExcludeClass]
|
||||
public class LoaderUtils
|
||||
{
|
||||
|
||||
private static const SWF_MIME_TYPE:String = "application/x-shockwave-flash";
|
||||
|
||||
public function LoaderUtils()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public static function createDisplayObjectTrait(loader:Loader, mediaElement:MediaElement) : DisplayObjectTrait
|
||||
{
|
||||
var displayObject:DisplayObject = null;
|
||||
var mediaWidth:Number = 0;
|
||||
var mediaHeight:Number = 0;
|
||||
var info:LoaderInfo = loader.contentLoaderInfo;
|
||||
displayObject = loader;
|
||||
displayObject.scrollRect = new Rectangle(0,0,info.width,info.height);
|
||||
mediaWidth = info.width;
|
||||
mediaHeight = info.height;
|
||||
return new DisplayObjectTrait(displayObject,mediaWidth,mediaHeight);
|
||||
}
|
||||
|
||||
public static function loadLoadTrait(loadTrait:LoadTrait, updateLoadTraitFunction:Function, useCurrentSecurityDomain:Boolean, checkPolicyFile:Boolean, validateLoadedContentFunction:Function = null) : void
|
||||
{
|
||||
var context:LoaderContext;
|
||||
var urlReq:URLRequest;
|
||||
var loader:Loader = null;
|
||||
var onLoadComplete:Function = null;
|
||||
var onIOError:Function = null;
|
||||
var onSecurityError:Function = null;
|
||||
var toggleLoaderListeners:Function = function(loader:Loader, on:Boolean):void
|
||||
{
|
||||
if(on)
|
||||
{
|
||||
loader.contentLoaderInfo.addEventListener(Event.COMPLETE,onLoadComplete);
|
||||
loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,onIOError);
|
||||
loader.contentLoaderInfo.addEventListener(SecurityErrorEvent.SECURITY_ERROR,onSecurityError);
|
||||
}
|
||||
else
|
||||
{
|
||||
loader.contentLoaderInfo.removeEventListener(Event.COMPLETE,onLoadComplete);
|
||||
loader.contentLoaderInfo.removeEventListener(IOErrorEvent.IO_ERROR,onIOError);
|
||||
loader.contentLoaderInfo.removeEventListener(SecurityErrorEvent.SECURITY_ERROR,onSecurityError);
|
||||
}
|
||||
};
|
||||
onLoadComplete = function(event:Event):void
|
||||
{
|
||||
var validated:Boolean = false;
|
||||
var timer:Timer = null;
|
||||
var onTimer:Function = null;
|
||||
toggleLoaderListeners(loader,false);
|
||||
if(loadTrait.loadState == LoadState.LOADING)
|
||||
{
|
||||
if(validateLoadedContentFunction != null)
|
||||
{
|
||||
validated = Boolean(validateLoadedContentFunction(loader.content));
|
||||
if(validated)
|
||||
{
|
||||
if(Capabilities.isDebugger)
|
||||
{
|
||||
onTimer = function(event:TimerEvent):void
|
||||
{
|
||||
timer.removeEventListener(TimerEvent.TIMER_COMPLETE,onTimer);
|
||||
timer = null;
|
||||
loader.unloadAndStop();
|
||||
loader = null;
|
||||
loadLoadTrait(loadTrait,updateLoadTraitFunction,useCurrentSecurityDomain,false,null);
|
||||
};
|
||||
timer = new Timer(250,1);
|
||||
timer.addEventListener(TimerEvent.TIMER_COMPLETE,onTimer);
|
||||
timer.start();
|
||||
}
|
||||
else
|
||||
{
|
||||
loader.unloadAndStop();
|
||||
loader = null;
|
||||
loadLoadTrait(loadTrait,updateLoadTraitFunction,useCurrentSecurityDomain,false,null);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
loader.unloadAndStop();
|
||||
loader = null;
|
||||
updateLoadTraitFunction(loadTrait,LoadState.LOAD_ERROR);
|
||||
loadTrait.dispatchEvent(new MediaErrorEvent(MediaErrorEvent.MEDIA_ERROR,false,false,new MediaError(MediaErrorCodes.IO_ERROR)));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
updateLoadTraitFunction(loadTrait,LoadState.READY);
|
||||
}
|
||||
}
|
||||
};
|
||||
onIOError = function(ioEvent:IOErrorEvent, ioEventDetail:String = null):void
|
||||
{
|
||||
toggleLoaderListeners(loader,false);
|
||||
loader = null;
|
||||
updateLoadTraitFunction(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);
|
||||
loader = null;
|
||||
updateLoadTraitFunction(loadTrait,LoadState.LOAD_ERROR);
|
||||
loadTrait.dispatchEvent(new MediaErrorEvent(MediaErrorEvent.MEDIA_ERROR,false,false,new MediaError(MediaErrorCodes.SECURITY_ERROR,Boolean(securityEvent) ? securityEvent.text : securityEventDetail)));
|
||||
};
|
||||
var loaderLoadTrait:LoaderLoadTrait = loadTrait as LoaderLoadTrait;
|
||||
loader = new Loader();
|
||||
loaderLoadTrait.loader = loader;
|
||||
updateLoadTraitFunction(loadTrait,LoadState.LOADING);
|
||||
context = new LoaderContext();
|
||||
urlReq = new URLRequest((loadTrait.resource as URLResource).url.toString());
|
||||
context.checkPolicyFile = checkPolicyFile;
|
||||
if(useCurrentSecurityDomain && urlReq.url.search(/^file:\//i) == -1)
|
||||
{
|
||||
context.securityDomain = SecurityDomain.currentDomain;
|
||||
}
|
||||
if(validateLoadedContentFunction != null)
|
||||
{
|
||||
context.applicationDomain = new ApplicationDomain();
|
||||
}
|
||||
toggleLoaderListeners(loader,true);
|
||||
try
|
||||
{
|
||||
loader.load(urlReq,context);
|
||||
}
|
||||
catch(ioError:IOError)
|
||||
{
|
||||
onIOError(null,ioError.message);
|
||||
}
|
||||
catch(securityError:SecurityError)
|
||||
{
|
||||
onSecurityError(null,securityError.message);
|
||||
}
|
||||
}
|
||||
|
||||
public static function unloadLoadTrait(loadTrait:LoadTrait, updateLoadTraitFunction:Function) : void
|
||||
{
|
||||
var loaderLoadTrait:LoaderLoadTrait = loadTrait as LoaderLoadTrait;
|
||||
updateLoadTraitFunction(loadTrait,LoadState.UNLOADING);
|
||||
loaderLoadTrait.loader.unloadAndStop();
|
||||
updateLoadTraitFunction(loadTrait,LoadState.UNINITIALIZED);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
package org.osmf.elements.proxyClasses
|
||||
{
|
||||
import org.osmf.events.LoadEvent;
|
||||
import org.osmf.media.MediaElement;
|
||||
import org.osmf.media.MediaResourceBase;
|
||||
import org.osmf.traits.LoadTrait;
|
||||
import org.osmf.traits.LoaderBase;
|
||||
|
||||
[ExcludeClass]
|
||||
public class LoadFromDocumentLoadTrait extends LoadTrait
|
||||
{
|
||||
|
||||
private var _mediaElement:MediaElement;
|
||||
|
||||
public function LoadFromDocumentLoadTrait(loader:LoaderBase, resource:MediaResourceBase)
|
||||
{
|
||||
super(loader,resource);
|
||||
}
|
||||
|
||||
override protected function loadStateChangeEnd() : void
|
||||
{
|
||||
dispatchEvent(new LoadEvent(LoadEvent.LOAD_STATE_CHANGE,false,false,loadState));
|
||||
}
|
||||
|
||||
public function set mediaElement(value:MediaElement) : void
|
||||
{
|
||||
this._mediaElement = value;
|
||||
}
|
||||
|
||||
public function get mediaElement() : MediaElement
|
||||
{
|
||||
return this._mediaElement;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
package org.osmf.elements.proxyClasses
|
||||
{
|
||||
import flash.events.Event;
|
||||
import org.osmf.events.MetadataEvent;
|
||||
import org.osmf.metadata.Metadata;
|
||||
|
||||
[ExcludeClass]
|
||||
public class ProxyMetadata extends Metadata
|
||||
{
|
||||
|
||||
private var proxiedMetadata:Metadata;
|
||||
|
||||
public function ProxyMetadata()
|
||||
{
|
||||
super();
|
||||
this.proxiedMetadata = new Metadata();
|
||||
this.proxiedMetadata.addEventListener(MetadataEvent.VALUE_ADD,this.redispatchEvent);
|
||||
this.proxiedMetadata.addEventListener(MetadataEvent.VALUE_CHANGE,this.redispatchEvent);
|
||||
this.proxiedMetadata.addEventListener(MetadataEvent.VALUE_REMOVE,this.redispatchEvent);
|
||||
}
|
||||
|
||||
public function set metadata(value:Metadata) : void
|
||||
{
|
||||
var url:String = null;
|
||||
this.proxiedMetadata.removeEventListener(MetadataEvent.VALUE_ADD,this.redispatchEvent);
|
||||
this.proxiedMetadata.removeEventListener(MetadataEvent.VALUE_CHANGE,this.redispatchEvent);
|
||||
this.proxiedMetadata.removeEventListener(MetadataEvent.VALUE_REMOVE,this.redispatchEvent);
|
||||
for each(url in this.proxiedMetadata.keys)
|
||||
{
|
||||
value.addValue(url,this.proxiedMetadata.getValue(url));
|
||||
}
|
||||
this.proxiedMetadata = value;
|
||||
this.proxiedMetadata.addEventListener(MetadataEvent.VALUE_ADD,this.redispatchEvent);
|
||||
this.proxiedMetadata.addEventListener(MetadataEvent.VALUE_CHANGE,this.redispatchEvent);
|
||||
this.proxiedMetadata.addEventListener(MetadataEvent.VALUE_REMOVE,this.redispatchEvent);
|
||||
}
|
||||
|
||||
override public function getValue(key:String) : *
|
||||
{
|
||||
return this.proxiedMetadata.getValue(key);
|
||||
}
|
||||
|
||||
override public function addValue(key:String, value:Object) : void
|
||||
{
|
||||
this.proxiedMetadata.addValue(key,value);
|
||||
}
|
||||
|
||||
override public function removeValue(key:String) : *
|
||||
{
|
||||
return this.proxiedMetadata.removeValue(key);
|
||||
}
|
||||
|
||||
override public function get keys() : Vector.<String>
|
||||
{
|
||||
return this.proxiedMetadata.keys;
|
||||
}
|
||||
|
||||
private function redispatchEvent(event:Event) : void
|
||||
{
|
||||
dispatchEvent(event.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
package org.osmf.events
|
||||
{
|
||||
import flash.events.Event;
|
||||
|
||||
public class AudioEvent extends Event
|
||||
{
|
||||
|
||||
public static const VOLUME_CHANGE:String = "volumeChange";
|
||||
|
||||
public static const MUTED_CHANGE:String = "mutedChange";
|
||||
|
||||
public static const PAN_CHANGE:String = "panChange";
|
||||
|
||||
private var _muted:Boolean;
|
||||
|
||||
private var _volume:Number;
|
||||
|
||||
private var _pan:Number;
|
||||
|
||||
public function AudioEvent(type:String, bubbles:Boolean, cancelable:Boolean, muted:Boolean = false, volume:Number = NaN, pan:Number = NaN)
|
||||
{
|
||||
super(type,bubbles,cancelable);
|
||||
this._muted = muted;
|
||||
this._volume = volume;
|
||||
this._pan = pan;
|
||||
}
|
||||
|
||||
public function get muted() : Boolean
|
||||
{
|
||||
return this._muted;
|
||||
}
|
||||
|
||||
public function get volume() : Number
|
||||
{
|
||||
return this._volume;
|
||||
}
|
||||
|
||||
public function get pan() : Number
|
||||
{
|
||||
return this._pan;
|
||||
}
|
||||
|
||||
override public function clone() : Event
|
||||
{
|
||||
return new AudioEvent(type,bubbles,cancelable,this._muted,this._volume,this._pan);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
package org.osmf.events
|
||||
{
|
||||
import flash.events.Event;
|
||||
|
||||
public class BufferEvent extends Event
|
||||
{
|
||||
|
||||
public static const BUFFERING_CHANGE:String = "bufferingChange";
|
||||
|
||||
public static const BUFFER_TIME_CHANGE:String = "bufferTimeChange";
|
||||
|
||||
public static const BUFFER_LENGTH_CHANGE:String = "bufferLengthChange";
|
||||
|
||||
private var _buffering:Boolean;
|
||||
|
||||
private var _bufferTime:Number;
|
||||
|
||||
private var _bufferLength:Number;
|
||||
|
||||
public function BufferEvent(type:String, bubbles:Boolean = false, cancelable:Boolean = false, buffering:Boolean = false, bufferTime:Number = NaN, bufferLength:Number = NaN)
|
||||
{
|
||||
super(type,bubbles,cancelable);
|
||||
this._buffering = buffering;
|
||||
this._bufferTime = bufferTime;
|
||||
this._bufferLength = bufferLength;
|
||||
}
|
||||
|
||||
public function get buffering() : Boolean
|
||||
{
|
||||
return this._buffering;
|
||||
}
|
||||
|
||||
public function get bufferTime() : Number
|
||||
{
|
||||
return this._bufferTime;
|
||||
}
|
||||
|
||||
public function get bufferLength() : Number
|
||||
{
|
||||
return this._bufferLength;
|
||||
}
|
||||
|
||||
override public function clone() : Event
|
||||
{
|
||||
return new BufferEvent(type,bubbles,cancelable,this._buffering,this._bufferTime,this._bufferLength);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
package org.osmf.events
|
||||
{
|
||||
import flash.events.Event;
|
||||
import org.osmf.containers.IMediaContainer;
|
||||
|
||||
public class ContainerChangeEvent extends Event
|
||||
{
|
||||
|
||||
public static const CONTAINER_CHANGE:String = "containerChange";
|
||||
|
||||
private var _oldContainer:IMediaContainer;
|
||||
|
||||
private var _newContainer:IMediaContainer;
|
||||
|
||||
public function ContainerChangeEvent(type:String, bubbles:Boolean = false, cancelable:Boolean = false, oldContainer:IMediaContainer = null, newContainer:IMediaContainer = null)
|
||||
{
|
||||
super(type,bubbles,cancelable);
|
||||
this._oldContainer = oldContainer;
|
||||
this._newContainer = newContainer;
|
||||
}
|
||||
|
||||
public function get oldContainer() : IMediaContainer
|
||||
{
|
||||
return this._oldContainer;
|
||||
}
|
||||
|
||||
public function get newContainer() : IMediaContainer
|
||||
{
|
||||
return this._newContainer;
|
||||
}
|
||||
|
||||
override public function clone() : Event
|
||||
{
|
||||
return new ContainerChangeEvent(type,bubbles,cancelable,this._oldContainer,this._newContainer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
package org.osmf.events
|
||||
{
|
||||
import flash.events.Event;
|
||||
|
||||
public class DRMEvent extends Event
|
||||
{
|
||||
|
||||
public static const DRM_STATE_CHANGE:String = "drmStateChange";
|
||||
|
||||
private var _drmState:String;
|
||||
|
||||
private var _startDate:Date;
|
||||
|
||||
private var _endDate:Date;
|
||||
|
||||
private var _period:Number;
|
||||
|
||||
private var _serverURL:String;
|
||||
|
||||
private var _token:Object;
|
||||
|
||||
private var _mediaError:MediaError;
|
||||
|
||||
public function DRMEvent(type:String, state:String, bubbles:Boolean = false, cancelable:Boolean = false, start:Date = null, end:Date = null, period:Number = 0, serverURL:String = null, token:Object = null, mediaError:MediaError = null)
|
||||
{
|
||||
super(type,bubbles,cancelable);
|
||||
this._drmState = state;
|
||||
this._token = token;
|
||||
this._mediaError = mediaError;
|
||||
this._startDate = start;
|
||||
this._endDate = end;
|
||||
this._period = period;
|
||||
this._serverURL = serverURL;
|
||||
}
|
||||
|
||||
public function get token() : Object
|
||||
{
|
||||
return this._token;
|
||||
}
|
||||
|
||||
public function get mediaError() : MediaError
|
||||
{
|
||||
return this._mediaError;
|
||||
}
|
||||
|
||||
public function get startDate() : Date
|
||||
{
|
||||
return this._startDate;
|
||||
}
|
||||
|
||||
public function get endDate() : Date
|
||||
{
|
||||
return this._endDate;
|
||||
}
|
||||
|
||||
public function get period() : Number
|
||||
{
|
||||
return this._period;
|
||||
}
|
||||
|
||||
public function get drmState() : String
|
||||
{
|
||||
return this._drmState;
|
||||
}
|
||||
|
||||
public function get serverURL() : String
|
||||
{
|
||||
return this._serverURL;
|
||||
}
|
||||
|
||||
override public function clone() : Event
|
||||
{
|
||||
return new DRMEvent(type,this._drmState,bubbles,cancelable,this._startDate,this._endDate,this._period,this._serverURL,this._token,this._mediaError);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package org.osmf.events
|
||||
{
|
||||
import flash.events.Event;
|
||||
|
||||
public class DVREvent extends Event
|
||||
{
|
||||
|
||||
public static const IS_RECORDING_CHANGE:String = "isRecordingChange";
|
||||
|
||||
public function DVREvent(type:String, bubbles:Boolean = false, cancelable:Boolean = false)
|
||||
{
|
||||
super(type,bubbles,cancelable);
|
||||
}
|
||||
|
||||
override public function clone() : Event
|
||||
{
|
||||
return new DVREvent(type,bubbles,cancelable);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package org.osmf.events
|
||||
{
|
||||
import flash.events.Event;
|
||||
|
||||
[ExcludeClass]
|
||||
public class DVRStreamInfoEvent extends Event
|
||||
{
|
||||
|
||||
public static const DVRSTREAMINFO:String = "DVRStreamInfo";
|
||||
|
||||
private var _info:Object;
|
||||
|
||||
public function DVRStreamInfoEvent(type:String, bubbles:Boolean = false, cancelable:Boolean = false, info:Object = null)
|
||||
{
|
||||
super(type,bubbles,cancelable);
|
||||
this._info = info;
|
||||
}
|
||||
|
||||
override public function clone() : Event
|
||||
{
|
||||
return new DVRStreamInfoEvent(type,bubbles,cancelable,this.info);
|
||||
}
|
||||
|
||||
public function get info() : Object
|
||||
{
|
||||
return this._info;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
package org.osmf.events
|
||||
{
|
||||
import flash.display.DisplayObject;
|
||||
import flash.events.Event;
|
||||
|
||||
public class DisplayObjectEvent extends Event
|
||||
{
|
||||
|
||||
public static const DISPLAY_OBJECT_CHANGE:String = "displayObjectChange";
|
||||
|
||||
public static const MEDIA_SIZE_CHANGE:String = "mediaSizeChange";
|
||||
|
||||
private var _oldDisplayObject:DisplayObject;
|
||||
|
||||
private var _newDisplayObject:DisplayObject;
|
||||
|
||||
private var _oldWidth:Number;
|
||||
|
||||
private var _oldHeight:Number;
|
||||
|
||||
private var _newWidth:Number;
|
||||
|
||||
private var _newHeight:Number;
|
||||
|
||||
public function DisplayObjectEvent(type:String, bubbles:Boolean = false, cancelable:Boolean = false, oldDisplayObject:DisplayObject = null, newDisplayObject:DisplayObject = null, oldWidth:Number = NaN, oldHeight:Number = NaN, newWidth:Number = NaN, newHeight:Number = NaN)
|
||||
{
|
||||
super(type,bubbles,cancelable);
|
||||
this._oldDisplayObject = oldDisplayObject;
|
||||
this._newDisplayObject = newDisplayObject;
|
||||
this._oldWidth = oldWidth;
|
||||
this._oldHeight = oldHeight;
|
||||
this._newWidth = newWidth;
|
||||
this._newHeight = newHeight;
|
||||
}
|
||||
|
||||
public function get oldDisplayObject() : DisplayObject
|
||||
{
|
||||
return this._oldDisplayObject;
|
||||
}
|
||||
|
||||
public function get newDisplayObject() : DisplayObject
|
||||
{
|
||||
return this._newDisplayObject;
|
||||
}
|
||||
|
||||
public function get oldWidth() : Number
|
||||
{
|
||||
return this._oldWidth;
|
||||
}
|
||||
|
||||
public function get oldHeight() : Number
|
||||
{
|
||||
return this._oldHeight;
|
||||
}
|
||||
|
||||
public function get newWidth() : Number
|
||||
{
|
||||
return this._newWidth;
|
||||
}
|
||||
|
||||
public function get newHeight() : Number
|
||||
{
|
||||
return this._newHeight;
|
||||
}
|
||||
|
||||
override public function clone() : Event
|
||||
{
|
||||
return new DisplayObjectEvent(type,bubbles,cancelable,this._oldDisplayObject,this._newDisplayObject,this._oldWidth,this._oldHeight,this._newWidth,this._newHeight);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
package org.osmf.events
|
||||
{
|
||||
import flash.events.Event;
|
||||
|
||||
public class DynamicStreamEvent extends Event
|
||||
{
|
||||
|
||||
public static const SWITCHING_CHANGE:String = "switchingChange";
|
||||
|
||||
public static const NUM_DYNAMIC_STREAMS_CHANGE:String = "numDynamicStreamsChange";
|
||||
|
||||
public static const AUTO_SWITCH_CHANGE:String = "autoSwitchChange";
|
||||
|
||||
private var _switching:Boolean;
|
||||
|
||||
private var _autoSwitch:Boolean;
|
||||
|
||||
public function DynamicStreamEvent(type:String, bubbles:Boolean = false, cancelable:Boolean = false, switching:Boolean = false, autoSwitch:Boolean = false)
|
||||
{
|
||||
super(type,bubbles,cancelable);
|
||||
this._switching = switching;
|
||||
this._autoSwitch = autoSwitch;
|
||||
}
|
||||
|
||||
public function get switching() : Boolean
|
||||
{
|
||||
return this._switching;
|
||||
}
|
||||
|
||||
public function get autoSwitch() : Boolean
|
||||
{
|
||||
return this._autoSwitch;
|
||||
}
|
||||
|
||||
override public function clone() : Event
|
||||
{
|
||||
return new DynamicStreamEvent(type,bubbles,cancelable,this._switching,this._autoSwitch);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
package org.osmf.events
|
||||
{
|
||||
import flash.events.Event;
|
||||
import org.osmf.net.httpstreaming.f4f.AdobeBootstrapBox;
|
||||
import org.osmf.net.httpstreaming.flv.FLVTagScriptDataObject;
|
||||
|
||||
[ExcludeClass]
|
||||
public class HTTPStreamingFileHandlerEvent extends Event
|
||||
{
|
||||
|
||||
public static const NOTIFY_SEGMENT_DURATION:String = "notifySegmentDuration";
|
||||
|
||||
public static const NOTIFY_SCRIPT_DATA:String = "notifyScriptData";
|
||||
|
||||
public static const NOTIFY_BOOTSTRAP_BOX:String = "notifyBootstrapBox";
|
||||
|
||||
public static const NOTIFY_ERROR:String = "notifyError";
|
||||
|
||||
private var _segmentDuration:Number;
|
||||
|
||||
private var _scriptDataObject:FLVTagScriptDataObject;
|
||||
|
||||
private var _scriptDataFirst:Boolean;
|
||||
|
||||
private var _scriptDataImmediate:Boolean;
|
||||
|
||||
private var _abst:AdobeBootstrapBox;
|
||||
|
||||
private var _error:Boolean;
|
||||
|
||||
public function HTTPStreamingFileHandlerEvent(type:String, bubbles:Boolean = false, cancelable:Boolean = false, segmentDuration:Number = 0, scriptDataObject:FLVTagScriptDataObject = null, scriptDataFirst:Boolean = false, scriptDataImmediate:Boolean = false, abst:AdobeBootstrapBox = null, error:Boolean = false)
|
||||
{
|
||||
super(type,bubbles,cancelable);
|
||||
this._segmentDuration = segmentDuration;
|
||||
this._scriptDataObject = scriptDataObject;
|
||||
this._scriptDataFirst = scriptDataFirst;
|
||||
this._scriptDataImmediate = scriptDataImmediate;
|
||||
this._abst = abst;
|
||||
this._error = error;
|
||||
}
|
||||
|
||||
public function get segmentDuration() : Number
|
||||
{
|
||||
return this._segmentDuration;
|
||||
}
|
||||
|
||||
public function get scriptDataObject() : FLVTagScriptDataObject
|
||||
{
|
||||
return this._scriptDataObject;
|
||||
}
|
||||
|
||||
public function get scriptDataFirst() : Boolean
|
||||
{
|
||||
return this._scriptDataFirst;
|
||||
}
|
||||
|
||||
public function get scriptDataImmediate() : Boolean
|
||||
{
|
||||
return this._scriptDataImmediate;
|
||||
}
|
||||
|
||||
public function get bootstrapBox() : AdobeBootstrapBox
|
||||
{
|
||||
return this._abst;
|
||||
}
|
||||
|
||||
public function get error() : Boolean
|
||||
{
|
||||
return this._error;
|
||||
}
|
||||
|
||||
override public function clone() : Event
|
||||
{
|
||||
return new HTTPStreamingFileHandlerEvent(type,bubbles,cancelable,this.segmentDuration,this.scriptDataObject,this.scriptDataFirst,this.scriptDataImmediate,this.bootstrapBox,this.error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+122
@@ -0,0 +1,122 @@
|
||||
package org.osmf.events
|
||||
{
|
||||
import flash.events.Event;
|
||||
import flash.net.URLRequest;
|
||||
import org.osmf.net.httpstreaming.flv.FLVTagScriptDataObject;
|
||||
|
||||
[ExcludeClass]
|
||||
public class HTTPStreamingIndexHandlerEvent extends Event
|
||||
{
|
||||
|
||||
public static const NOTIFY_INDEX_READY:String = "notifyIndexReady";
|
||||
|
||||
public static const NOTIFY_RATES:String = "notifyRates";
|
||||
|
||||
public static const REQUEST_LOAD_INDEX:String = "requestLoadIndex";
|
||||
|
||||
public static const NOTIFY_ERROR:String = "notifyError";
|
||||
|
||||
public static const NOTIFY_SEGMENT_DURATION:String = "notifySegmentDuration";
|
||||
|
||||
public static const NOTIFY_SCRIPT_DATA:String = "notifyScriptData";
|
||||
|
||||
private var _streamNames:Array;
|
||||
|
||||
private var _rates:Array;
|
||||
|
||||
private var _request:URLRequest;
|
||||
|
||||
private var _requestContext:Object;
|
||||
|
||||
private var _binaryData:Boolean;
|
||||
|
||||
private var _segmentDuration:Number;
|
||||
|
||||
private var _scriptDataObject:FLVTagScriptDataObject;
|
||||
|
||||
private var _scriptDataFirst:Boolean;
|
||||
|
||||
private var _scriptDataImmediate:Boolean;
|
||||
|
||||
private var _live:Boolean;
|
||||
|
||||
private var _offset:Number;
|
||||
|
||||
public function HTTPStreamingIndexHandlerEvent(type:String, bubbles:Boolean = false, cancelable:Boolean = false, live:Boolean = false, offset:Number = NaN, streamNames:Array = null, rates:Array = null, request:URLRequest = null, requestContext:Object = null, binaryData:Boolean = true, segmentDuration:Number = 0, scriptDataObject:FLVTagScriptDataObject = null, scriptDataFirst:Boolean = false, scriptDataImmediate:Boolean = false)
|
||||
{
|
||||
super(type,bubbles,cancelable);
|
||||
this._live = live;
|
||||
this._offset = offset;
|
||||
this._streamNames = streamNames;
|
||||
this._rates = rates;
|
||||
this._request = request;
|
||||
this._requestContext = requestContext;
|
||||
this._binaryData = binaryData;
|
||||
this._segmentDuration = segmentDuration;
|
||||
this._scriptDataObject = scriptDataObject;
|
||||
this._scriptDataFirst = scriptDataFirst;
|
||||
this._scriptDataImmediate = scriptDataImmediate;
|
||||
}
|
||||
|
||||
public function get live() : Boolean
|
||||
{
|
||||
return this._live;
|
||||
}
|
||||
|
||||
public function get offset() : Number
|
||||
{
|
||||
return this._offset;
|
||||
}
|
||||
|
||||
public function get streamNames() : Array
|
||||
{
|
||||
return this._streamNames;
|
||||
}
|
||||
|
||||
public function get rates() : Array
|
||||
{
|
||||
return this._rates;
|
||||
}
|
||||
|
||||
public function get request() : URLRequest
|
||||
{
|
||||
return this._request;
|
||||
}
|
||||
|
||||
public function get requestContext() : Object
|
||||
{
|
||||
return this._requestContext;
|
||||
}
|
||||
|
||||
public function get binaryData() : Boolean
|
||||
{
|
||||
return this._binaryData;
|
||||
}
|
||||
|
||||
public function get segmentDuration() : Number
|
||||
{
|
||||
return this._segmentDuration;
|
||||
}
|
||||
|
||||
public function get scriptDataObject() : FLVTagScriptDataObject
|
||||
{
|
||||
return this._scriptDataObject;
|
||||
}
|
||||
|
||||
public function get scriptDataFirst() : Boolean
|
||||
{
|
||||
return this._scriptDataFirst;
|
||||
}
|
||||
|
||||
public function get scriptDataImmediate() : Boolean
|
||||
{
|
||||
return this._scriptDataImmediate;
|
||||
}
|
||||
|
||||
override public function clone() : Event
|
||||
{
|
||||
return new HTTPStreamingIndexHandlerEvent(type,bubbles,cancelable,this.live,this.offset,this.streamNames,this.rates,this.request,this.requestContext,this.binaryData,this.segmentDuration,this.scriptDataObject,this.scriptDataFirst,this.scriptDataImmediate);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
package org.osmf.events
|
||||
{
|
||||
import flash.events.Event;
|
||||
|
||||
public class LoadEvent extends Event
|
||||
{
|
||||
|
||||
public static const LOAD_STATE_CHANGE:String = "loadStateChange";
|
||||
|
||||
public static const BYTES_LOADED_CHANGE:String = "bytesLoadedChange";
|
||||
|
||||
public static const BYTES_TOTAL_CHANGE:String = "bytesTotalChange";
|
||||
|
||||
private var _loadState:String;
|
||||
|
||||
private var _bytes:Number;
|
||||
|
||||
public function LoadEvent(type:String, bubbles:Boolean = false, cancelable:Boolean = false, loadState:String = null, bytes:Number = NaN)
|
||||
{
|
||||
super(type,bubbles,cancelable);
|
||||
this._loadState = loadState;
|
||||
this._bytes = bytes;
|
||||
}
|
||||
|
||||
override public function clone() : Event
|
||||
{
|
||||
return new LoadEvent(type,bubbles,cancelable,this.loadState,this.bytes);
|
||||
}
|
||||
|
||||
public function get loadState() : String
|
||||
{
|
||||
return this._loadState;
|
||||
}
|
||||
|
||||
public function get bytes() : Number
|
||||
{
|
||||
return this._bytes;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
package org.osmf.events
|
||||
{
|
||||
import flash.events.Event;
|
||||
import org.osmf.traits.LoadTrait;
|
||||
import org.osmf.traits.LoaderBase;
|
||||
|
||||
public class LoaderEvent extends Event
|
||||
{
|
||||
|
||||
public static const LOAD_STATE_CHANGE:String = "loadStateChange";
|
||||
|
||||
private var _loader:LoaderBase;
|
||||
|
||||
private var _loadTrait:LoadTrait;
|
||||
|
||||
private var _oldState:String;
|
||||
|
||||
private var _newState:String;
|
||||
|
||||
public function LoaderEvent(type:String, bubbles:Boolean = false, cancelable:Boolean = false, loader:LoaderBase = null, loadTrait:LoadTrait = null, oldState:String = null, newState:String = null)
|
||||
{
|
||||
super(type,bubbles,cancelable);
|
||||
this._loader = loader;
|
||||
this._loadTrait = loadTrait;
|
||||
this._oldState = oldState;
|
||||
this._newState = newState;
|
||||
}
|
||||
|
||||
public function get loader() : LoaderBase
|
||||
{
|
||||
return this._loader;
|
||||
}
|
||||
|
||||
public function get loadTrait() : LoadTrait
|
||||
{
|
||||
return this._loadTrait;
|
||||
}
|
||||
|
||||
public function get oldState() : String
|
||||
{
|
||||
return this._oldState;
|
||||
}
|
||||
|
||||
public function get newState() : String
|
||||
{
|
||||
return this._newState;
|
||||
}
|
||||
|
||||
override public function clone() : Event
|
||||
{
|
||||
return new LoaderEvent(type,bubbles,cancelable,this.loader,this.loadTrait,this.oldState,this.newState);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package org.osmf.events
|
||||
{
|
||||
import flash.events.Event;
|
||||
|
||||
[ExcludeClass]
|
||||
public class MediaElementChangeEvent extends Event
|
||||
{
|
||||
|
||||
public static const MEDIA_ELEMENT_CHANGE:String = "mediaElementChange";
|
||||
|
||||
public function MediaElementChangeEvent(type:String, bubbles:Boolean = false, cancelable:Boolean = false)
|
||||
{
|
||||
super(type,bubbles,cancelable);
|
||||
}
|
||||
|
||||
override public function clone() : Event
|
||||
{
|
||||
return new MediaElementChangeEvent(type,bubbles,cancelable);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
package org.osmf.events
|
||||
{
|
||||
import flash.events.Event;
|
||||
import org.osmf.metadata.Metadata;
|
||||
|
||||
public class MediaElementEvent extends Event
|
||||
{
|
||||
|
||||
public static const TRAIT_ADD:String = "traitAdd";
|
||||
|
||||
public static const TRAIT_REMOVE:String = "traitRemove";
|
||||
|
||||
public static const METADATA_ADD:String = "metadataAdd";
|
||||
|
||||
public static const METADATA_REMOVE:String = "metadataRemove";
|
||||
|
||||
private var _traitType:String;
|
||||
|
||||
private var _namespaceURL:String;
|
||||
|
||||
private var _metadata:Metadata;
|
||||
|
||||
public function MediaElementEvent(type:String, bubbles:Boolean = false, cancelable:Boolean = false, traitType:String = null, namespaceURL:String = null, metadata:Metadata = null)
|
||||
{
|
||||
super(type,bubbles,cancelable);
|
||||
this._traitType = traitType;
|
||||
this._namespaceURL = namespaceURL;
|
||||
this._metadata = metadata;
|
||||
}
|
||||
|
||||
override public function clone() : Event
|
||||
{
|
||||
return new MediaElementEvent(type,bubbles,cancelable,this.traitType,this.namespaceURL,this.metadata);
|
||||
}
|
||||
|
||||
public function get traitType() : String
|
||||
{
|
||||
return this._traitType;
|
||||
}
|
||||
|
||||
public function get namespaceURL() : String
|
||||
{
|
||||
return this._namespaceURL;
|
||||
}
|
||||
|
||||
public function get metadata() : Metadata
|
||||
{
|
||||
return this._metadata;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package org.osmf.events
|
||||
{
|
||||
public class MediaError extends Error
|
||||
{
|
||||
|
||||
private var _detail:String;
|
||||
|
||||
public function MediaError(errorID:int, detail:String = null)
|
||||
{
|
||||
super(this.getMessageForErrorID(errorID),errorID);
|
||||
this._detail = detail;
|
||||
}
|
||||
|
||||
public function get detail() : String
|
||||
{
|
||||
return this._detail;
|
||||
}
|
||||
|
||||
protected function getMessageForErrorID(errorID:int) : String
|
||||
{
|
||||
return MediaErrorCodes.getMessageForErrorID(errorID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,145 @@
|
||||
package org.osmf.events
|
||||
{
|
||||
import org.osmf.utils.OSMFStrings;
|
||||
|
||||
public final class MediaErrorCodes
|
||||
{
|
||||
|
||||
public static const IO_ERROR:int = 1;
|
||||
|
||||
public static const SECURITY_ERROR:int = 2;
|
||||
|
||||
public static const ASYNC_ERROR:int = 3;
|
||||
|
||||
public static const ARGUMENT_ERROR:int = 4;
|
||||
|
||||
public static const URL_SCHEME_INVALID:int = 5;
|
||||
|
||||
public static const HTTP_GET_FAILED:int = 6;
|
||||
|
||||
public static const MEDIA_LOAD_FAILED:int = 7;
|
||||
|
||||
public static const PLUGIN_VERSION_INVALID:int = 8;
|
||||
|
||||
public static const PLUGIN_IMPLEMENTATION_INVALID:int = 9;
|
||||
|
||||
public static const SOUND_PLAY_FAILED:int = 10;
|
||||
|
||||
public static const NETCONNECTION_REJECTED:int = 11;
|
||||
|
||||
public static const NETCONNECTION_APPLICATION_INVALID:int = 12;
|
||||
|
||||
public static const NETCONNECTION_FAILED:int = 13;
|
||||
|
||||
public static const NETCONNECTION_TIMEOUT:int = 14;
|
||||
|
||||
public static const NETSTREAM_PLAY_FAILED:int = 15;
|
||||
|
||||
public static const NETSTREAM_STREAM_NOT_FOUND:int = 16;
|
||||
|
||||
public static const NETSTREAM_FILE_STRUCTURE_INVALID:int = 17;
|
||||
|
||||
public static const NETSTREAM_NO_SUPPORTED_TRACK_FOUND:int = 18;
|
||||
|
||||
public static const DRM_SYSTEM_UPDATE_ERROR:int = 19;
|
||||
|
||||
public static const DVRCAST_SUBSCRIBE_FAILED:int = 20;
|
||||
|
||||
public static const DVRCAST_CONTENT_OFFLINE:int = 21;
|
||||
|
||||
public static const DVRCAST_STREAM_INFO_RETRIEVAL_FAILED:int = 22;
|
||||
|
||||
public static const F4M_FILE_INVALID:int = 23;
|
||||
|
||||
private static const errorMap:Array = [{
|
||||
"errorID":IO_ERROR,
|
||||
"message":OSMFStrings.IO_ERROR
|
||||
},{
|
||||
"errorID":SECURITY_ERROR,
|
||||
"message":OSMFStrings.SECURITY_ERROR
|
||||
},{
|
||||
"errorID":ASYNC_ERROR,
|
||||
"message":OSMFStrings.ASYNC_ERROR
|
||||
},{
|
||||
"errorID":ARGUMENT_ERROR,
|
||||
"message":OSMFStrings.ARGUMENT_ERROR
|
||||
},{
|
||||
"errorID":URL_SCHEME_INVALID,
|
||||
"message":OSMFStrings.URL_SCHEME_INVALID
|
||||
},{
|
||||
"errorID":HTTP_GET_FAILED,
|
||||
"message":OSMFStrings.HTTP_GET_FAILED
|
||||
},{
|
||||
"errorID":MEDIA_LOAD_FAILED,
|
||||
"message":OSMFStrings.MEDIA_LOAD_FAILED
|
||||
},{
|
||||
"errorID":PLUGIN_VERSION_INVALID,
|
||||
"message":OSMFStrings.PLUGIN_VERSION_INVALID
|
||||
},{
|
||||
"errorID":PLUGIN_IMPLEMENTATION_INVALID,
|
||||
"message":OSMFStrings.PLUGIN_IMPLEMENTATION_INVALID
|
||||
},{
|
||||
"errorID":SOUND_PLAY_FAILED,
|
||||
"message":OSMFStrings.SOUND_PLAY_FAILED
|
||||
},{
|
||||
"errorID":NETCONNECTION_REJECTED,
|
||||
"message":OSMFStrings.NETCONNECTION_REJECTED
|
||||
},{
|
||||
"errorID":NETCONNECTION_APPLICATION_INVALID,
|
||||
"message":OSMFStrings.NETCONNECTION_APPLICATION_INVALID
|
||||
},{
|
||||
"errorID":NETCONNECTION_FAILED,
|
||||
"message":OSMFStrings.NETCONNECTION_FAILED
|
||||
},{
|
||||
"errorID":NETCONNECTION_TIMEOUT,
|
||||
"message":OSMFStrings.NETCONNECTION_TIMEOUT
|
||||
},{
|
||||
"errorID":NETSTREAM_PLAY_FAILED,
|
||||
"message":OSMFStrings.NETSTREAM_PLAY_FAILED
|
||||
},{
|
||||
"errorID":NETSTREAM_STREAM_NOT_FOUND,
|
||||
"message":OSMFStrings.NETSTREAM_STREAM_NOT_FOUND
|
||||
},{
|
||||
"errorID":NETSTREAM_FILE_STRUCTURE_INVALID,
|
||||
"message":OSMFStrings.NETSTREAM_FILE_STRUCTURE_INVALID
|
||||
},{
|
||||
"errorID":NETSTREAM_NO_SUPPORTED_TRACK_FOUND,
|
||||
"message":OSMFStrings.NETSTREAM_NO_SUPPORTED_TRACK_FOUND
|
||||
},{
|
||||
"errorID":DRM_SYSTEM_UPDATE_ERROR,
|
||||
"message":OSMFStrings.DRM_SYSTEM_UPDATE_ERROR
|
||||
},{
|
||||
"errorID":DVRCAST_SUBSCRIBE_FAILED,
|
||||
"message":OSMFStrings.DVRCAST_SUBSCRIBE_FAILED
|
||||
},{
|
||||
"errorID":DVRCAST_CONTENT_OFFLINE,
|
||||
"message":OSMFStrings.DVRCAST_CONTENT_OFFLINE
|
||||
},{
|
||||
"errorID":DVRCAST_STREAM_INFO_RETRIEVAL_FAILED,
|
||||
"message":OSMFStrings.DVRCAST_STREAM_INFO_RETRIEVAL_FAILED
|
||||
},{
|
||||
"errorID":F4M_FILE_INVALID,
|
||||
"message":OSMFStrings.F4M_FILE_INVALID
|
||||
}];
|
||||
|
||||
public function MediaErrorCodes()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
internal static function getMessageForErrorID(errorID:int) : String
|
||||
{
|
||||
var message:String = "";
|
||||
for(var i:int = 0; i < errorMap.length; i++)
|
||||
{
|
||||
if(errorMap[i].errorID == errorID)
|
||||
{
|
||||
message = OSMFStrings.getString(errorMap[i].message);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return message;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package org.osmf.events
|
||||
{
|
||||
import flash.events.Event;
|
||||
|
||||
public class MediaErrorEvent extends Event
|
||||
{
|
||||
|
||||
public static const MEDIA_ERROR:String = "mediaError";
|
||||
|
||||
private var _error:MediaError;
|
||||
|
||||
public function MediaErrorEvent(type:String, bubbles:Boolean = false, cancelable:Boolean = false, error:MediaError = null)
|
||||
{
|
||||
super(type,bubbles,cancelable);
|
||||
this._error = error;
|
||||
}
|
||||
|
||||
override public function clone() : Event
|
||||
{
|
||||
return new MediaErrorEvent(type,bubbles,cancelable,this.error);
|
||||
}
|
||||
|
||||
public function get error() : MediaError
|
||||
{
|
||||
return this._error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
package org.osmf.events
|
||||
{
|
||||
import flash.events.Event;
|
||||
import org.osmf.media.MediaElement;
|
||||
import org.osmf.media.MediaResourceBase;
|
||||
|
||||
public class MediaFactoryEvent extends Event
|
||||
{
|
||||
|
||||
public static const PLUGIN_LOAD:String = "pluginLoad";
|
||||
|
||||
public static const PLUGIN_LOAD_ERROR:String = "pluginLoadError";
|
||||
|
||||
public static const MEDIA_ELEMENT_CREATE:String = "mediaElementCreate";
|
||||
|
||||
private var _resource:MediaResourceBase;
|
||||
|
||||
private var _mediaElement:MediaElement;
|
||||
|
||||
public function MediaFactoryEvent(type:String, bubbles:Boolean = false, cancelable:Boolean = false, resource:MediaResourceBase = null, mediaElement:MediaElement = null)
|
||||
{
|
||||
super(type,bubbles,cancelable);
|
||||
this._resource = resource;
|
||||
this._mediaElement = mediaElement;
|
||||
}
|
||||
|
||||
public function get resource() : MediaResourceBase
|
||||
{
|
||||
return this._resource;
|
||||
}
|
||||
|
||||
public function get mediaElement() : MediaElement
|
||||
{
|
||||
return this._mediaElement;
|
||||
}
|
||||
|
||||
override public function clone() : Event
|
||||
{
|
||||
return new MediaFactoryEvent(type,bubbles,cancelable,this._resource,this._mediaElement);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
package org.osmf.events
|
||||
{
|
||||
import flash.events.Event;
|
||||
|
||||
public class MediaPlayerCapabilityChangeEvent extends Event
|
||||
{
|
||||
|
||||
public static const CAN_PLAY_CHANGE:String = "canPlayChange";
|
||||
|
||||
public static const CAN_SEEK_CHANGE:String = "canSeekChange";
|
||||
|
||||
public static const TEMPORAL_CHANGE:String = "temporalChange";
|
||||
|
||||
public static const HAS_AUDIO_CHANGE:String = "hasAudioChange";
|
||||
|
||||
public static const IS_DYNAMIC_STREAM_CHANGE:String = "isDynamicStreamChange";
|
||||
|
||||
public static const CAN_LOAD_CHANGE:String = "canLoadChange";
|
||||
|
||||
public static const CAN_BUFFER_CHANGE:String = "canBufferChange";
|
||||
|
||||
public static const HAS_DRM_CHANGE:String = "hasDRMChange";
|
||||
|
||||
public static const HAS_DISPLAY_OBJECT_CHANGE:String = "hasDisplayObjectChange";
|
||||
|
||||
private var _enabled:Boolean;
|
||||
|
||||
public function MediaPlayerCapabilityChangeEvent(type:String, bubbles:Boolean = false, cancelable:Boolean = false, enabled:Boolean = false)
|
||||
{
|
||||
super(type,bubbles,cancelable);
|
||||
this._enabled = enabled;
|
||||
}
|
||||
|
||||
public function get enabled() : Boolean
|
||||
{
|
||||
return this._enabled;
|
||||
}
|
||||
|
||||
override public function clone() : Event
|
||||
{
|
||||
return new MediaPlayerCapabilityChangeEvent(type,bubbles,cancelable,this._enabled);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package org.osmf.events
|
||||
{
|
||||
import flash.events.Event;
|
||||
|
||||
public class MediaPlayerStateChangeEvent extends Event
|
||||
{
|
||||
|
||||
public static const MEDIA_PLAYER_STATE_CHANGE:String = "mediaPlayerStateChange";
|
||||
|
||||
private var _state:String;
|
||||
|
||||
public function MediaPlayerStateChangeEvent(type:String, bubbles:Boolean = false, cancelable:Boolean = false, state:String = null)
|
||||
{
|
||||
super(type,bubbles,cancelable);
|
||||
this._state = state;
|
||||
}
|
||||
|
||||
public function get state() : String
|
||||
{
|
||||
return this._state;
|
||||
}
|
||||
|
||||
override public function clone() : Event
|
||||
{
|
||||
return new MediaPlayerStateChangeEvent(type,bubbles,cancelable,this._state);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
package org.osmf.events
|
||||
{
|
||||
import flash.events.Event;
|
||||
|
||||
public class MetadataEvent extends Event
|
||||
{
|
||||
|
||||
public static const VALUE_ADD:String = "valueAdd";
|
||||
|
||||
public static const VALUE_REMOVE:String = "valueRemove";
|
||||
|
||||
public static const VALUE_CHANGE:String = "valueChange";
|
||||
|
||||
private var _key:String;
|
||||
|
||||
private var _value:*;
|
||||
|
||||
private var _oldValue:*;
|
||||
|
||||
public function MetadataEvent(type:String, bubbles:Boolean = false, cancelable:Boolean = false, key:String = null, value:* = null, oldValue:* = null)
|
||||
{
|
||||
super(type,bubbles,cancelable);
|
||||
this._key = key;
|
||||
this._value = value;
|
||||
this._oldValue = oldValue;
|
||||
}
|
||||
|
||||
public function get key() : String
|
||||
{
|
||||
return this._key;
|
||||
}
|
||||
|
||||
public function get value() : *
|
||||
{
|
||||
return this._value;
|
||||
}
|
||||
|
||||
public function get oldValue() : *
|
||||
{
|
||||
return this._oldValue;
|
||||
}
|
||||
|
||||
override public function clone() : Event
|
||||
{
|
||||
return new MetadataEvent(type,bubbles,cancelable,this._key,this._value,this._oldValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
package org.osmf.events
|
||||
{
|
||||
import flash.events.Event;
|
||||
import flash.net.NetConnection;
|
||||
import org.osmf.media.URLResource;
|
||||
|
||||
public class NetConnectionFactoryEvent extends Event
|
||||
{
|
||||
|
||||
public static const CREATION_COMPLETE:String = "creationComplete";
|
||||
|
||||
public static const CREATION_ERROR:String = "creationError";
|
||||
|
||||
private var _netConnection:NetConnection;
|
||||
|
||||
private var _resource:URLResource;
|
||||
|
||||
private var _mediaError:MediaError;
|
||||
|
||||
public function NetConnectionFactoryEvent(type:String, bubbles:Boolean = false, cancelable:Boolean = false, netConnection:NetConnection = null, resource:URLResource = null, mediaError:MediaError = null)
|
||||
{
|
||||
super(type,bubbles,cancelable);
|
||||
this._netConnection = netConnection;
|
||||
this._resource = resource;
|
||||
this._mediaError = mediaError;
|
||||
}
|
||||
|
||||
public function get netConnection() : NetConnection
|
||||
{
|
||||
return this._netConnection;
|
||||
}
|
||||
|
||||
public function get resource() : URLResource
|
||||
{
|
||||
return this._resource;
|
||||
}
|
||||
|
||||
public function get mediaError() : MediaError
|
||||
{
|
||||
return this._mediaError;
|
||||
}
|
||||
|
||||
override public function clone() : Event
|
||||
{
|
||||
return new NetConnectionFactoryEvent(type,bubbles,cancelable,this._netConnection,this._resource,this._mediaError);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
package org.osmf.events
|
||||
{
|
||||
import flash.events.Event;
|
||||
|
||||
public class PlayEvent extends Event
|
||||
{
|
||||
|
||||
public static const CAN_PAUSE_CHANGE:String = "canPauseChange";
|
||||
|
||||
public static const PLAY_STATE_CHANGE:String = "playStateChange";
|
||||
|
||||
private var _playState:String;
|
||||
|
||||
private var _canPause:Boolean;
|
||||
|
||||
public function PlayEvent(type:String, bubbles:Boolean = false, cancelable:Boolean = false, playState:String = null, canPause:Boolean = false)
|
||||
{
|
||||
super(type,bubbles,cancelable);
|
||||
this._playState = playState;
|
||||
this._canPause = canPause;
|
||||
}
|
||||
|
||||
override public function clone() : Event
|
||||
{
|
||||
return new PlayEvent(type,bubbles,cancelable,this.playState,this.canPause);
|
||||
}
|
||||
|
||||
public function get playState() : String
|
||||
{
|
||||
return this._playState;
|
||||
}
|
||||
|
||||
public function get canPause() : Boolean
|
||||
{
|
||||
return this._canPause;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package org.osmf.events
|
||||
{
|
||||
import flash.events.Event;
|
||||
import org.osmf.media.MediaResourceBase;
|
||||
|
||||
[ExcludeClass]
|
||||
public class PluginManagerEvent extends Event
|
||||
{
|
||||
|
||||
public static const PLUGIN_LOAD:String = "pluginLoad";
|
||||
|
||||
public static const PLUGIN_LOAD_ERROR:String = "pluginLoadError";
|
||||
|
||||
private var _resource:MediaResourceBase;
|
||||
|
||||
public function PluginManagerEvent(type:String, bubbles:Boolean = false, cancelable:Boolean = false, resource:MediaResourceBase = null)
|
||||
{
|
||||
super(type,bubbles,cancelable);
|
||||
this._resource = resource;
|
||||
}
|
||||
|
||||
public function get resource() : MediaResourceBase
|
||||
{
|
||||
return this._resource;
|
||||
}
|
||||
|
||||
override public function clone() : Event
|
||||
{
|
||||
return new PluginManagerEvent(type,bubbles,cancelable,this._resource);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
package org.osmf.events
|
||||
{
|
||||
import flash.events.Event;
|
||||
|
||||
public class SeekEvent extends Event
|
||||
{
|
||||
|
||||
public static const SEEKING_CHANGE:String = "seekingChange";
|
||||
|
||||
private var _seeking:Boolean = false;
|
||||
|
||||
private var _time:Number;
|
||||
|
||||
public function SeekEvent(type:String, bubbles:Boolean = false, cancelable:Boolean = false, seeking:Boolean = false, time:Number = NaN)
|
||||
{
|
||||
super(type,bubbles,cancelable);
|
||||
this._seeking = seeking;
|
||||
this._time = time;
|
||||
}
|
||||
|
||||
public function get seeking() : Boolean
|
||||
{
|
||||
return this._seeking;
|
||||
}
|
||||
|
||||
public function get time() : Number
|
||||
{
|
||||
return this._time;
|
||||
}
|
||||
|
||||
override public function clone() : Event
|
||||
{
|
||||
return new SeekEvent(type,bubbles,cancelable,this._seeking,this._time);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package org.osmf.events
|
||||
{
|
||||
import flash.events.Event;
|
||||
|
||||
public class TimeEvent extends Event
|
||||
{
|
||||
|
||||
public static const CURRENT_TIME_CHANGE:String = "currentTimeChange";
|
||||
|
||||
public static const DURATION_CHANGE:String = "durationChange";
|
||||
|
||||
public static const COMPLETE:String = "complete";
|
||||
|
||||
private var _time:Number;
|
||||
|
||||
public function TimeEvent(type:String, bubbles:Boolean = false, cancelable:Boolean = false, time:Number = NaN)
|
||||
{
|
||||
super(type,bubbles,cancelable);
|
||||
this._time = time;
|
||||
}
|
||||
|
||||
public function get time() : Number
|
||||
{
|
||||
return this._time;
|
||||
}
|
||||
|
||||
override public function clone() : Event
|
||||
{
|
||||
return new TimeEvent(type,bubbles,cancelable,this.time);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package org.osmf.events
|
||||
{
|
||||
import flash.events.Event;
|
||||
import org.osmf.metadata.TimelineMarker;
|
||||
|
||||
public class TimelineMetadataEvent extends MetadataEvent
|
||||
{
|
||||
|
||||
public static const MARKER_TIME_REACHED:String = "markerTimeReached";
|
||||
|
||||
public static const MARKER_DURATION_REACHED:String = "markerDurationReached";
|
||||
|
||||
public static const MARKER_ADD:String = "markerAdd";
|
||||
|
||||
public static const MARKER_REMOVE:String = "markerRemove";
|
||||
|
||||
private var _marker:TimelineMarker;
|
||||
|
||||
public function TimelineMetadataEvent(type:String, bubbles:Boolean = false, cancelable:Boolean = false, marker:TimelineMarker = null)
|
||||
{
|
||||
super(type,bubbles,cancelable,"" + marker.time,marker);
|
||||
this._marker = marker;
|
||||
}
|
||||
|
||||
public function get marker() : TimelineMarker
|
||||
{
|
||||
return this._marker;
|
||||
}
|
||||
|
||||
override public function clone() : Event
|
||||
{
|
||||
return new TimelineMetadataEvent(type,bubbles,cancelable,this._marker);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
package org.osmf.layout
|
||||
{
|
||||
import org.osmf.events.MetadataEvent;
|
||||
import org.osmf.metadata.NonSynthesizingMetadata;
|
||||
|
||||
internal class AbsoluteLayoutMetadata extends NonSynthesizingMetadata
|
||||
{
|
||||
|
||||
public static const X:String = "x";
|
||||
|
||||
public static const Y:String = "y";
|
||||
|
||||
public static const WIDTH:String = "width";
|
||||
|
||||
public static const HEIGHT:String = "height";
|
||||
|
||||
private var _x:Number;
|
||||
|
||||
private var _y:Number;
|
||||
|
||||
private var _width:Number;
|
||||
|
||||
private var _height:Number;
|
||||
|
||||
public function AbsoluteLayoutMetadata()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
override public function getValue(key:String) : *
|
||||
{
|
||||
if(key == null)
|
||||
{
|
||||
return undefined;
|
||||
}
|
||||
if(key == X)
|
||||
{
|
||||
return this.x;
|
||||
}
|
||||
if(key == Y)
|
||||
{
|
||||
return this.y;
|
||||
}
|
||||
if(key == WIDTH)
|
||||
{
|
||||
return this.width;
|
||||
}
|
||||
if(key == HEIGHT)
|
||||
{
|
||||
return this.height;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
public function get x() : Number
|
||||
{
|
||||
return this._x;
|
||||
}
|
||||
|
||||
public function set x(value:Number) : void
|
||||
{
|
||||
var event:MetadataEvent = null;
|
||||
if(this._x != value)
|
||||
{
|
||||
event = new MetadataEvent(MetadataEvent.VALUE_CHANGE,false,false,X,value,this._x);
|
||||
this._x = value;
|
||||
dispatchEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
public function get y() : Number
|
||||
{
|
||||
return this._y;
|
||||
}
|
||||
|
||||
public function set y(value:Number) : void
|
||||
{
|
||||
var event:MetadataEvent = null;
|
||||
if(this._y != value)
|
||||
{
|
||||
event = new MetadataEvent(MetadataEvent.VALUE_CHANGE,false,false,Y,value,this._y);
|
||||
this._y = value;
|
||||
dispatchEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
public function get width() : Number
|
||||
{
|
||||
return this._width;
|
||||
}
|
||||
|
||||
public function set width(value:Number) : void
|
||||
{
|
||||
var event:MetadataEvent = null;
|
||||
if(this._width != value)
|
||||
{
|
||||
event = new MetadataEvent(MetadataEvent.VALUE_CHANGE,false,false,WIDTH,value,this._width);
|
||||
this._width = value;
|
||||
dispatchEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
public function get height() : Number
|
||||
{
|
||||
return this._height;
|
||||
}
|
||||
|
||||
public function set height(value:Number) : void
|
||||
{
|
||||
var event:MetadataEvent = null;
|
||||
if(this._height != value)
|
||||
{
|
||||
event = new MetadataEvent(MetadataEvent.VALUE_CHANGE,false,false,HEIGHT,value,this._height);
|
||||
this._height = value;
|
||||
dispatchEvent(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
package org.osmf.layout
|
||||
{
|
||||
import org.osmf.events.MetadataEvent;
|
||||
import org.osmf.metadata.NonSynthesizingMetadata;
|
||||
|
||||
internal class AnchorLayoutMetadata extends NonSynthesizingMetadata
|
||||
{
|
||||
|
||||
public static const LEFT:String = "left";
|
||||
|
||||
public static const TOP:String = "top";
|
||||
|
||||
public static const RIGHT:String = "right";
|
||||
|
||||
public static const BOTTOM:String = "bottom";
|
||||
|
||||
private var _left:Number;
|
||||
|
||||
private var _top:Number;
|
||||
|
||||
private var _right:Number;
|
||||
|
||||
private var _bottom:Number;
|
||||
|
||||
public function AnchorLayoutMetadata()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
override public function getValue(key:String) : *
|
||||
{
|
||||
if(key == null)
|
||||
{
|
||||
return undefined;
|
||||
}
|
||||
if(key == LEFT)
|
||||
{
|
||||
return this.left;
|
||||
}
|
||||
if(key == TOP)
|
||||
{
|
||||
return this.top;
|
||||
}
|
||||
if(key == RIGHT)
|
||||
{
|
||||
return this.right;
|
||||
}
|
||||
if(key == BOTTOM)
|
||||
{
|
||||
return this.bottom;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
public function get left() : Number
|
||||
{
|
||||
return this._left;
|
||||
}
|
||||
|
||||
public function set left(value:Number) : void
|
||||
{
|
||||
var event:MetadataEvent = null;
|
||||
if(this._left != value)
|
||||
{
|
||||
event = new MetadataEvent(MetadataEvent.VALUE_CHANGE,false,false,LEFT,value,this._left);
|
||||
this._left = value;
|
||||
dispatchEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
public function get top() : Number
|
||||
{
|
||||
return this._top;
|
||||
}
|
||||
|
||||
public function set top(value:Number) : void
|
||||
{
|
||||
var event:MetadataEvent = null;
|
||||
if(this._top != value)
|
||||
{
|
||||
event = new MetadataEvent(MetadataEvent.VALUE_CHANGE,false,false,TOP,value,this._top);
|
||||
this._top = value;
|
||||
dispatchEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
public function get right() : Number
|
||||
{
|
||||
return this._right;
|
||||
}
|
||||
|
||||
public function set right(value:Number) : void
|
||||
{
|
||||
var event:MetadataEvent = null;
|
||||
if(this._right != value)
|
||||
{
|
||||
event = new MetadataEvent(MetadataEvent.VALUE_CHANGE,false,false,RIGHT,value,this._right);
|
||||
this._right = value;
|
||||
dispatchEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
public function get bottom() : Number
|
||||
{
|
||||
return this._bottom;
|
||||
}
|
||||
|
||||
public function set bottom(value:Number) : void
|
||||
{
|
||||
var event:MetadataEvent = null;
|
||||
if(this._bottom != value)
|
||||
{
|
||||
event = new MetadataEvent(MetadataEvent.VALUE_CHANGE,false,false,BOTTOM,value,this._bottom);
|
||||
this._bottom = value;
|
||||
dispatchEvent(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
package org.osmf.layout
|
||||
{
|
||||
import org.osmf.utils.OSMFStrings;
|
||||
|
||||
[ExcludeClass]
|
||||
internal class BinarySearch
|
||||
{
|
||||
|
||||
public function BinarySearch()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public static function search(list:Object, compare:Function, item:*, firstIndex:int = 0, lastIndex:int = -2147483648) : int
|
||||
{
|
||||
var middle:int = 0;
|
||||
var listItem:* = undefined;
|
||||
if(list == null || compare == null)
|
||||
{
|
||||
throw new ArgumentError(OSMFStrings.getString(OSMFStrings.NULL_PARAM));
|
||||
}
|
||||
var result:int = -firstIndex;
|
||||
lastIndex = lastIndex == int.MIN_VALUE ? int(list.length - 1) : lastIndex;
|
||||
if(list.length > 0 && firstIndex <= lastIndex)
|
||||
{
|
||||
middle = (firstIndex + lastIndex) / 2;
|
||||
listItem = list[middle];
|
||||
switch(compare(item,listItem))
|
||||
{
|
||||
case -1:
|
||||
result = search(list,compare,item,firstIndex,middle - 1);
|
||||
break;
|
||||
case 0:
|
||||
result = middle;
|
||||
break;
|
||||
case 1:
|
||||
result = search(list,compare,item,middle + 1,lastIndex);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
package org.osmf.layout
|
||||
{
|
||||
import org.osmf.events.MetadataEvent;
|
||||
import org.osmf.metadata.NonSynthesizingMetadata;
|
||||
|
||||
internal class BoxAttributesMetadata extends NonSynthesizingMetadata
|
||||
{
|
||||
|
||||
public static const RELATIVE_SUM:String = "relativeSum";
|
||||
|
||||
public static const ABSOLUTE_SUM:String = "absoluteSum";
|
||||
|
||||
private var _relativeSum:Number;
|
||||
|
||||
private var _absoluteSum:Number;
|
||||
|
||||
public function BoxAttributesMetadata()
|
||||
{
|
||||
super();
|
||||
this._relativeSum = 0;
|
||||
this._absoluteSum = 0;
|
||||
}
|
||||
|
||||
override public function getValue(key:String) : *
|
||||
{
|
||||
if(key == null)
|
||||
{
|
||||
return undefined;
|
||||
}
|
||||
if(key == RELATIVE_SUM)
|
||||
{
|
||||
return this.relativeSum;
|
||||
}
|
||||
if(key == ABSOLUTE_SUM)
|
||||
{
|
||||
return this.absoluteSum;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
public function get relativeSum() : Number
|
||||
{
|
||||
return this._relativeSum;
|
||||
}
|
||||
|
||||
public function set relativeSum(value:Number) : void
|
||||
{
|
||||
var event:MetadataEvent = null;
|
||||
if(this._relativeSum != value)
|
||||
{
|
||||
event = new MetadataEvent(MetadataEvent.VALUE_CHANGE,false,false,RELATIVE_SUM,value,this._relativeSum);
|
||||
this._relativeSum = value;
|
||||
dispatchEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
public function get absoluteSum() : Number
|
||||
{
|
||||
return this._absoluteSum;
|
||||
}
|
||||
|
||||
public function set absoluteSum(value:Number) : void
|
||||
{
|
||||
var event:MetadataEvent = null;
|
||||
if(this._absoluteSum != value)
|
||||
{
|
||||
event = new MetadataEvent(MetadataEvent.VALUE_CHANGE,false,false,ABSOLUTE_SUM,value,this._absoluteSum);
|
||||
this._absoluteSum = value;
|
||||
dispatchEvent(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package org.osmf.layout
|
||||
{
|
||||
public final class HorizontalAlign
|
||||
{
|
||||
|
||||
public static const LEFT:String = "left";
|
||||
|
||||
public static const CENTER:String = "center";
|
||||
|
||||
public static const RIGHT:String = "right";
|
||||
|
||||
public function HorizontalAlign()
|
||||
{
|
||||
super();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package org.osmf.layout
|
||||
{
|
||||
import flash.display.DisplayObject;
|
||||
import flash.events.IEventDispatcher;
|
||||
|
||||
[Event(name="removeChild",type="org.osmf.layout.LayoutTargetEvent")]
|
||||
[Event(name="setChildIndex",type="org.osmf.layout.LayoutTargetEvent")]
|
||||
[Event(name="addChildAt",type="org.osmf.layout.LayoutTargetEvent")]
|
||||
[Event(name="removeFromLayoutRenderer",type="org.osmf.layout.LayoutTargetEvent")]
|
||||
[Event(name="addToLayoutRenderer",type="org.osmf.layout.LayoutTargetEvent")]
|
||||
[Event(name="unsetAsLayoutRendererContainer",type="org.osmf.layout.LayoutTargetEvent")]
|
||||
[Event(name="setAsLayoutRendererContainer",type="org.osmf.layout.LayoutTargetEvent")]
|
||||
[Event(name="mediaSizeChange",type="org.osmf.events.DisplayObjectEvent")]
|
||||
[Event(name="displayObjectChange",type="org.osmf.events.DisplayObjectEvent")]
|
||||
public interface ILayoutTarget extends IEventDispatcher
|
||||
{
|
||||
|
||||
function get displayObject() : DisplayObject;
|
||||
|
||||
function get layoutMetadata() : LayoutMetadata;
|
||||
|
||||
function get measuredWidth() : Number;
|
||||
|
||||
function get measuredHeight() : Number;
|
||||
|
||||
function measure(param1:Boolean = true) : void;
|
||||
|
||||
function layout(param1:Number, param2:Number, param3:Boolean = true) : void;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,194 @@
|
||||
package org.osmf.layout
|
||||
{
|
||||
import org.osmf.events.MetadataEvent;
|
||||
import org.osmf.metadata.NonSynthesizingMetadata;
|
||||
|
||||
internal class LayoutAttributesMetadata extends NonSynthesizingMetadata
|
||||
{
|
||||
|
||||
public static const INDEX:String = "index";
|
||||
|
||||
public static const SCALE_MODE:String = "scaleMode";
|
||||
|
||||
public static const VERTICAL_ALIGN:String = "verticalAlign";
|
||||
|
||||
public static const HORIZONTAL_ALIGN:String = "horizontalAlign";
|
||||
|
||||
public static const SNAP_TO_PIXEL:String = "snapToPixel";
|
||||
|
||||
public static const MODE:String = "layoutMode";
|
||||
|
||||
public static const INCLUDE_IN_LAYOUT:String = "includeInLayout";
|
||||
|
||||
private var _index:Number = NaN;
|
||||
|
||||
private var _scaleMode:String;
|
||||
|
||||
private var _verticalAlign:String;
|
||||
|
||||
private var _horizontalAlign:String;
|
||||
|
||||
private var _snapToPixel:Boolean;
|
||||
|
||||
private var _layoutMode:String;
|
||||
|
||||
private var _includeInLayout:Boolean;
|
||||
|
||||
public function LayoutAttributesMetadata()
|
||||
{
|
||||
super();
|
||||
this._verticalAlign = null;
|
||||
this._horizontalAlign = null;
|
||||
this._scaleMode = null;
|
||||
this._snapToPixel = true;
|
||||
this._layoutMode = LayoutMode.NONE;
|
||||
this._includeInLayout = true;
|
||||
}
|
||||
|
||||
override public function getValue(key:String) : *
|
||||
{
|
||||
if(key == null)
|
||||
{
|
||||
return undefined;
|
||||
}
|
||||
if(key == INDEX)
|
||||
{
|
||||
return this.index;
|
||||
}
|
||||
if(key == SCALE_MODE)
|
||||
{
|
||||
return this.scaleMode;
|
||||
}
|
||||
if(key == VERTICAL_ALIGN)
|
||||
{
|
||||
return this.verticalAlign;
|
||||
}
|
||||
if(key == HORIZONTAL_ALIGN)
|
||||
{
|
||||
return this.horizontalAlign;
|
||||
}
|
||||
if(key == SNAP_TO_PIXEL)
|
||||
{
|
||||
return this.snapToPixel;
|
||||
}
|
||||
if(key == INCLUDE_IN_LAYOUT)
|
||||
{
|
||||
return this.snapToPixel;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
public function get index() : Number
|
||||
{
|
||||
return this._index;
|
||||
}
|
||||
|
||||
public function set index(value:Number) : void
|
||||
{
|
||||
var event:MetadataEvent = null;
|
||||
if(this._index != value)
|
||||
{
|
||||
event = new MetadataEvent(MetadataEvent.VALUE_CHANGE,false,false,INDEX,value,this._index);
|
||||
this._index = value;
|
||||
dispatchEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
public function get scaleMode() : String
|
||||
{
|
||||
return this._scaleMode;
|
||||
}
|
||||
|
||||
public function set scaleMode(value:String) : void
|
||||
{
|
||||
var event:MetadataEvent = null;
|
||||
if(this._scaleMode != value)
|
||||
{
|
||||
event = new MetadataEvent(MetadataEvent.VALUE_CHANGE,false,false,SCALE_MODE,value,this._scaleMode);
|
||||
this._scaleMode = value;
|
||||
dispatchEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
public function get verticalAlign() : String
|
||||
{
|
||||
return this._verticalAlign;
|
||||
}
|
||||
|
||||
public function set verticalAlign(value:String) : void
|
||||
{
|
||||
var event:MetadataEvent = null;
|
||||
if(this._verticalAlign != value)
|
||||
{
|
||||
event = new MetadataEvent(MetadataEvent.VALUE_CHANGE,false,false,VERTICAL_ALIGN,value,this._verticalAlign);
|
||||
this._verticalAlign = value;
|
||||
dispatchEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
public function get horizontalAlign() : String
|
||||
{
|
||||
return this._horizontalAlign;
|
||||
}
|
||||
|
||||
public function set horizontalAlign(value:String) : void
|
||||
{
|
||||
var event:MetadataEvent = null;
|
||||
if(this._horizontalAlign != value)
|
||||
{
|
||||
event = new MetadataEvent(MetadataEvent.VALUE_CHANGE,false,false,HORIZONTAL_ALIGN,value,this._horizontalAlign);
|
||||
this._horizontalAlign = value;
|
||||
dispatchEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
public function get snapToPixel() : Boolean
|
||||
{
|
||||
return this._snapToPixel;
|
||||
}
|
||||
|
||||
public function set snapToPixel(value:Boolean) : void
|
||||
{
|
||||
var event:MetadataEvent = null;
|
||||
if(this._snapToPixel != value)
|
||||
{
|
||||
event = new MetadataEvent(MetadataEvent.VALUE_CHANGE,false,false,SNAP_TO_PIXEL,value,this._snapToPixel);
|
||||
this._snapToPixel = value;
|
||||
dispatchEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
public function get layoutMode() : String
|
||||
{
|
||||
return this._layoutMode;
|
||||
}
|
||||
|
||||
public function set layoutMode(value:String) : void
|
||||
{
|
||||
var event:MetadataEvent = null;
|
||||
if(this._layoutMode != value)
|
||||
{
|
||||
event = new MetadataEvent(MetadataEvent.VALUE_CHANGE,false,false,MODE,value,this._layoutMode);
|
||||
this._layoutMode = value;
|
||||
dispatchEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
public function get includeInLayout() : Boolean
|
||||
{
|
||||
return this._includeInLayout;
|
||||
}
|
||||
|
||||
public function set includeInLayout(value:Boolean) : void
|
||||
{
|
||||
var event:MetadataEvent = null;
|
||||
if(this._includeInLayout != value)
|
||||
{
|
||||
event = new MetadataEvent(MetadataEvent.VALUE_CHANGE,false,false,INCLUDE_IN_LAYOUT,value,this._layoutMode);
|
||||
this._includeInLayout = value;
|
||||
dispatchEvent(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,341 @@
|
||||
package org.osmf.layout
|
||||
{
|
||||
import org.osmf.metadata.Metadata;
|
||||
import org.osmf.metadata.MetadataNamespaces;
|
||||
import org.osmf.metadata.MetadataSynthesizer;
|
||||
import org.osmf.metadata.NullMetadataSynthesizer;
|
||||
|
||||
public class LayoutMetadata extends Metadata
|
||||
{
|
||||
|
||||
public static const LAYOUT_NAMESPACE:String = "http://www.osmf.org/layout/1.0";
|
||||
|
||||
private const SYNTHESIZER:NullMetadataSynthesizer = new NullMetadataSynthesizer();
|
||||
|
||||
public function LayoutMetadata()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public function get index() : Number
|
||||
{
|
||||
return Boolean(this.lazyAttributes) ? this.lazyAttributes.index : NaN;
|
||||
}
|
||||
|
||||
public function set index(value:Number) : void
|
||||
{
|
||||
this.eagerAttributes.index = value;
|
||||
}
|
||||
|
||||
public function get scaleMode() : String
|
||||
{
|
||||
return Boolean(this.lazyAttributes) ? this.lazyAttributes.scaleMode : null;
|
||||
}
|
||||
|
||||
public function set scaleMode(value:String) : void
|
||||
{
|
||||
this.eagerAttributes.scaleMode = value;
|
||||
}
|
||||
|
||||
public function get horizontalAlign() : String
|
||||
{
|
||||
return Boolean(this.lazyAttributes) ? this.lazyAttributes.horizontalAlign : null;
|
||||
}
|
||||
|
||||
public function set horizontalAlign(value:String) : void
|
||||
{
|
||||
this.eagerAttributes.horizontalAlign = value;
|
||||
}
|
||||
|
||||
public function get verticalAlign() : String
|
||||
{
|
||||
return Boolean(this.lazyAttributes) ? this.lazyAttributes.verticalAlign : null;
|
||||
}
|
||||
|
||||
public function set verticalAlign(value:String) : void
|
||||
{
|
||||
this.eagerAttributes.verticalAlign = value;
|
||||
}
|
||||
|
||||
public function get snapToPixel() : Boolean
|
||||
{
|
||||
return Boolean(this.lazyAttributes) ? this.lazyAttributes.snapToPixel : true;
|
||||
}
|
||||
|
||||
public function set snapToPixel(value:Boolean) : void
|
||||
{
|
||||
this.eagerAttributes.snapToPixel = value;
|
||||
}
|
||||
|
||||
public function get layoutMode() : String
|
||||
{
|
||||
return Boolean(this.lazyAttributes) ? this.lazyAttributes.layoutMode : LayoutMode.NONE;
|
||||
}
|
||||
|
||||
public function set layoutMode(value:String) : void
|
||||
{
|
||||
this.eagerAttributes.layoutMode = value;
|
||||
}
|
||||
|
||||
public function get includeInLayout() : Boolean
|
||||
{
|
||||
return Boolean(this.lazyAttributes) ? this.lazyAttributes.includeInLayout : true;
|
||||
}
|
||||
|
||||
public function set includeInLayout(value:Boolean) : void
|
||||
{
|
||||
this.eagerAttributes.includeInLayout = value;
|
||||
}
|
||||
|
||||
public function get x() : Number
|
||||
{
|
||||
return Boolean(this.lazyAbsolute) ? this.lazyAbsolute.x : NaN;
|
||||
}
|
||||
|
||||
public function set x(value:Number) : void
|
||||
{
|
||||
this.eagerAbsolute.x = value;
|
||||
}
|
||||
|
||||
public function get y() : Number
|
||||
{
|
||||
return Boolean(this.lazyAbsolute) ? this.lazyAbsolute.y : NaN;
|
||||
}
|
||||
|
||||
public function set y(value:Number) : void
|
||||
{
|
||||
this.eagerAbsolute.y = value;
|
||||
}
|
||||
|
||||
public function get width() : Number
|
||||
{
|
||||
return Boolean(this.lazyAbsolute) ? this.lazyAbsolute.width : NaN;
|
||||
}
|
||||
|
||||
public function set width(value:Number) : void
|
||||
{
|
||||
this.eagerAbsolute.width = value;
|
||||
}
|
||||
|
||||
public function get height() : Number
|
||||
{
|
||||
return Boolean(this.lazyAbsolute) ? this.lazyAbsolute.height : NaN;
|
||||
}
|
||||
|
||||
public function set height(value:Number) : void
|
||||
{
|
||||
this.eagerAbsolute.height = value;
|
||||
}
|
||||
|
||||
public function get percentX() : Number
|
||||
{
|
||||
return Boolean(this.lazyRelative) ? this.lazyRelative.x : NaN;
|
||||
}
|
||||
|
||||
public function set percentX(value:Number) : void
|
||||
{
|
||||
this.eagerRelative.x = value;
|
||||
}
|
||||
|
||||
public function get percentY() : Number
|
||||
{
|
||||
return Boolean(this.lazyRelative) ? this.lazyRelative.y : NaN;
|
||||
}
|
||||
|
||||
public function set percentY(value:Number) : void
|
||||
{
|
||||
this.eagerRelative.y = value;
|
||||
}
|
||||
|
||||
public function get percentWidth() : Number
|
||||
{
|
||||
return Boolean(this.lazyRelative) ? this.lazyRelative.width : NaN;
|
||||
}
|
||||
|
||||
public function set percentWidth(value:Number) : void
|
||||
{
|
||||
this.eagerRelative.width = value;
|
||||
}
|
||||
|
||||
public function get percentHeight() : Number
|
||||
{
|
||||
return Boolean(this.lazyRelative) ? this.lazyRelative.height : NaN;
|
||||
}
|
||||
|
||||
public function set percentHeight(value:Number) : void
|
||||
{
|
||||
this.eagerRelative.height = value;
|
||||
}
|
||||
|
||||
public function get left() : Number
|
||||
{
|
||||
return Boolean(this.lazyAnchor) ? this.lazyAnchor.left : NaN;
|
||||
}
|
||||
|
||||
public function set left(value:Number) : void
|
||||
{
|
||||
this.eagerAnchor.left = value;
|
||||
}
|
||||
|
||||
public function get top() : Number
|
||||
{
|
||||
return Boolean(this.lazyAnchor) ? this.lazyAnchor.top : NaN;
|
||||
}
|
||||
|
||||
public function set top(value:Number) : void
|
||||
{
|
||||
this.eagerAnchor.top = value;
|
||||
}
|
||||
|
||||
public function get right() : Number
|
||||
{
|
||||
return Boolean(this.lazyAnchor) ? this.lazyAnchor.right : NaN;
|
||||
}
|
||||
|
||||
public function set right(value:Number) : void
|
||||
{
|
||||
this.eagerAnchor.right = value;
|
||||
}
|
||||
|
||||
public function get bottom() : Number
|
||||
{
|
||||
return Boolean(this.lazyAnchor) ? this.lazyAnchor.bottom : NaN;
|
||||
}
|
||||
|
||||
public function set bottom(value:Number) : void
|
||||
{
|
||||
this.eagerAnchor.bottom = value;
|
||||
}
|
||||
|
||||
public function get paddingLeft() : Number
|
||||
{
|
||||
return Boolean(this.lazyPadding) ? this.lazyPadding.left : NaN;
|
||||
}
|
||||
|
||||
public function set paddingLeft(value:Number) : void
|
||||
{
|
||||
this.eagerPadding.left = value;
|
||||
}
|
||||
|
||||
public function get paddingTop() : Number
|
||||
{
|
||||
return Boolean(this.lazyPadding) ? this.lazyPadding.top : NaN;
|
||||
}
|
||||
|
||||
public function set paddingTop(value:Number) : void
|
||||
{
|
||||
this.eagerPadding.top = value;
|
||||
}
|
||||
|
||||
public function get paddingRight() : Number
|
||||
{
|
||||
return Boolean(this.lazyPadding) ? this.lazyPadding.right : NaN;
|
||||
}
|
||||
|
||||
public function set paddingRight(value:Number) : void
|
||||
{
|
||||
this.eagerPadding.right = value;
|
||||
}
|
||||
|
||||
public function get paddingBottom() : Number
|
||||
{
|
||||
return Boolean(this.lazyPadding) ? this.lazyPadding.bottom : NaN;
|
||||
}
|
||||
|
||||
public function set paddingBottom(value:Number) : void
|
||||
{
|
||||
this.eagerPadding.bottom = value;
|
||||
}
|
||||
|
||||
override public function toString() : String
|
||||
{
|
||||
return "abs [" + this.x + ", " + this.y + ", " + this.width + ", " + this.height + "] " + "rel [" + this.percentX + ", " + this.percentY + ", " + this.percentWidth + ", " + this.percentHeight + "] " + "anch (" + this.left + ", " + this.top + ")(" + this.right + ", " + this.bottom + ") " + "pad [" + this.paddingLeft + ", " + this.paddingTop + ", " + this.paddingRight + ", " + this.paddingBottom + "] " + "layoutMode: " + this.layoutMode + " " + "index: " + this.index + " " + "scale: " + this.scaleMode + " " + "valign: " + this.verticalAlign + " " + "halign: " + this.horizontalAlign + " " + "snap: " + this.snapToPixel;
|
||||
}
|
||||
|
||||
override public function get synthesizer() : MetadataSynthesizer
|
||||
{
|
||||
return this.SYNTHESIZER;
|
||||
}
|
||||
|
||||
private function get lazyAttributes() : LayoutAttributesMetadata
|
||||
{
|
||||
return getValue(MetadataNamespaces.LAYOUT_ATTRIBUTES) as LayoutAttributesMetadata;
|
||||
}
|
||||
|
||||
private function get eagerAttributes() : LayoutAttributesMetadata
|
||||
{
|
||||
var result:LayoutAttributesMetadata = this.lazyAttributes;
|
||||
if(result == null)
|
||||
{
|
||||
result = new LayoutAttributesMetadata();
|
||||
addValue(MetadataNamespaces.LAYOUT_ATTRIBUTES,result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private function get lazyAbsolute() : AbsoluteLayoutMetadata
|
||||
{
|
||||
return getValue(MetadataNamespaces.ABSOLUTE_LAYOUT_PARAMETERS) as AbsoluteLayoutMetadata;
|
||||
}
|
||||
|
||||
private function get eagerAbsolute() : AbsoluteLayoutMetadata
|
||||
{
|
||||
var result:AbsoluteLayoutMetadata = this.lazyAbsolute;
|
||||
if(result == null)
|
||||
{
|
||||
result = new AbsoluteLayoutMetadata();
|
||||
addValue(MetadataNamespaces.ABSOLUTE_LAYOUT_PARAMETERS,result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private function get lazyRelative() : RelativeLayoutMetadata
|
||||
{
|
||||
return getValue(MetadataNamespaces.RELATIVE_LAYOUT_PARAMETERS) as RelativeLayoutMetadata;
|
||||
}
|
||||
|
||||
private function get eagerRelative() : RelativeLayoutMetadata
|
||||
{
|
||||
var result:RelativeLayoutMetadata = this.lazyRelative;
|
||||
if(result == null)
|
||||
{
|
||||
result = new RelativeLayoutMetadata();
|
||||
addValue(MetadataNamespaces.RELATIVE_LAYOUT_PARAMETERS,result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private function get lazyAnchor() : AnchorLayoutMetadata
|
||||
{
|
||||
return getValue(MetadataNamespaces.ANCHOR_LAYOUT_PARAMETERS) as AnchorLayoutMetadata;
|
||||
}
|
||||
|
||||
private function get eagerAnchor() : AnchorLayoutMetadata
|
||||
{
|
||||
var result:AnchorLayoutMetadata = this.lazyAnchor;
|
||||
if(result == null)
|
||||
{
|
||||
result = new AnchorLayoutMetadata();
|
||||
addValue(MetadataNamespaces.ANCHOR_LAYOUT_PARAMETERS,result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private function get lazyPadding() : PaddingLayoutMetadata
|
||||
{
|
||||
return getValue(MetadataNamespaces.PADDING_LAYOUT_PARAMETERS) as PaddingLayoutMetadata;
|
||||
}
|
||||
|
||||
private function get eagerPadding() : PaddingLayoutMetadata
|
||||
{
|
||||
var result:PaddingLayoutMetadata = this.lazyPadding;
|
||||
if(result == null)
|
||||
{
|
||||
result = new PaddingLayoutMetadata();
|
||||
addValue(MetadataNamespaces.PADDING_LAYOUT_PARAMETERS,result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package org.osmf.layout
|
||||
{
|
||||
public final class LayoutMode
|
||||
{
|
||||
|
||||
public static const NONE:String = "none";
|
||||
|
||||
public static const VERTICAL:String = "vertical";
|
||||
|
||||
public static const HORIZONTAL:String = "horizontal";
|
||||
|
||||
public function LayoutMode()
|
||||
{
|
||||
super();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,440 @@
|
||||
package org.osmf.layout
|
||||
{
|
||||
import flash.geom.Point;
|
||||
import flash.geom.Rectangle;
|
||||
import flash.utils.Dictionary;
|
||||
import org.osmf.metadata.MetadataNamespaces;
|
||||
import org.osmf.metadata.MetadataWatcher;
|
||||
|
||||
public class LayoutRenderer extends LayoutRendererBase
|
||||
{
|
||||
|
||||
private static const USED_METADATAS:Vector.<String> = new Vector.<String>(5,true);
|
||||
|
||||
private static const X:int = 1;
|
||||
|
||||
private static const Y:int = 2;
|
||||
|
||||
private static const WIDTH:int = 4;
|
||||
|
||||
private static const HEIGHT:int = 8;
|
||||
|
||||
private static const POSITION:int = X + Y;
|
||||
|
||||
private static const DIMENSIONS:int = WIDTH + HEIGHT;
|
||||
|
||||
private static const ALL:int = POSITION + DIMENSIONS;
|
||||
|
||||
USED_METADATAS[0] = MetadataNamespaces.ABSOLUTE_LAYOUT_PARAMETERS;
|
||||
USED_METADATAS[1] = MetadataNamespaces.RELATIVE_LAYOUT_PARAMETERS;
|
||||
USED_METADATAS[2] = MetadataNamespaces.ANCHOR_LAYOUT_PARAMETERS;
|
||||
USED_METADATAS[3] = MetadataNamespaces.PADDING_LAYOUT_PARAMETERS;
|
||||
USED_METADATAS[4] = MetadataNamespaces.LAYOUT_ATTRIBUTES;
|
||||
|
||||
private var layoutMode:String = "none";
|
||||
|
||||
private var lastCalculatedBounds:Rectangle;
|
||||
|
||||
private var targetMetadataWatchers:Dictionary = new Dictionary();
|
||||
|
||||
private var containerAbsoluteWatcher:MetadataWatcher;
|
||||
|
||||
private var containerAttributesWatcher:MetadataWatcher;
|
||||
|
||||
public function LayoutRenderer()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
override protected function get usedMetadatas() : Vector.<String>
|
||||
{
|
||||
return USED_METADATAS;
|
||||
}
|
||||
|
||||
override protected function processContainerChange(oldContainer:ILayoutTarget, newContainer:ILayoutTarget) : void
|
||||
{
|
||||
if(Boolean(oldContainer))
|
||||
{
|
||||
this.containerAbsoluteWatcher.unwatch();
|
||||
this.containerAttributesWatcher.unwatch();
|
||||
}
|
||||
if(Boolean(newContainer))
|
||||
{
|
||||
this.containerAbsoluteWatcher = new MetadataWatcher(newContainer.layoutMetadata,MetadataNamespaces.ABSOLUTE_LAYOUT_PARAMETERS,null,function(... _):void
|
||||
{
|
||||
invalidate();
|
||||
});
|
||||
this.containerAbsoluteWatcher.watch();
|
||||
this.containerAttributesWatcher = new MetadataWatcher(newContainer.layoutMetadata,MetadataNamespaces.LAYOUT_ATTRIBUTES,null,function(facet:LayoutAttributesMetadata):void
|
||||
{
|
||||
layoutMode = Boolean(facet) ? facet.layoutMode : LayoutMode.NONE;
|
||||
invalidate();
|
||||
});
|
||||
this.containerAttributesWatcher.watch();
|
||||
}
|
||||
invalidate();
|
||||
}
|
||||
|
||||
override protected function processUpdateMediaDisplayBegin(targets:Vector.<ILayoutTarget>) : void
|
||||
{
|
||||
this.lastCalculatedBounds = null;
|
||||
}
|
||||
|
||||
override protected function processUpdateMediaDisplayEnd() : void
|
||||
{
|
||||
this.lastCalculatedBounds = null;
|
||||
}
|
||||
|
||||
override protected function processTargetAdded(target:ILayoutTarget) : void
|
||||
{
|
||||
var watcher:MetadataWatcher;
|
||||
var attributes:LayoutAttributesMetadata = target.layoutMetadata.getValue(MetadataNamespaces.LAYOUT_ATTRIBUTES) as LayoutAttributesMetadata;
|
||||
var relative:RelativeLayoutMetadata = target.layoutMetadata.getValue(MetadataNamespaces.RELATIVE_LAYOUT_PARAMETERS) as RelativeLayoutMetadata;
|
||||
if(this.layoutMode == LayoutMode.NONE && relative == null && attributes == null && target.layoutMetadata.getValue(MetadataNamespaces.ABSOLUTE_LAYOUT_PARAMETERS) == null && target.layoutMetadata.getValue(MetadataNamespaces.ANCHOR_LAYOUT_PARAMETERS) == null)
|
||||
{
|
||||
relative = new RelativeLayoutMetadata();
|
||||
relative.width = 100;
|
||||
relative.height = 100;
|
||||
target.layoutMetadata.addValue(MetadataNamespaces.RELATIVE_LAYOUT_PARAMETERS,relative);
|
||||
attributes = new LayoutAttributesMetadata();
|
||||
attributes.scaleMode = attributes.scaleMode || ScaleMode.LETTERBOX;
|
||||
attributes.verticalAlign = attributes.verticalAlign || VerticalAlign.MIDDLE;
|
||||
attributes.horizontalAlign = attributes.horizontalAlign || HorizontalAlign.CENTER;
|
||||
target.layoutMetadata.addValue(MetadataNamespaces.LAYOUT_ATTRIBUTES,attributes);
|
||||
}
|
||||
watcher = new MetadataWatcher(target.layoutMetadata,MetadataNamespaces.LAYOUT_ATTRIBUTES,LayoutAttributesMetadata.INDEX,function(... _):void
|
||||
{
|
||||
updateTargetOrder(target);
|
||||
});
|
||||
watcher.watch();
|
||||
this.targetMetadataWatchers[target] = watcher;
|
||||
}
|
||||
|
||||
override protected function processTargetRemoved(target:ILayoutTarget) : void
|
||||
{
|
||||
var watcher:MetadataWatcher = this.targetMetadataWatchers[target];
|
||||
delete this.targetMetadataWatchers[target];
|
||||
watcher.unwatch();
|
||||
watcher = null;
|
||||
}
|
||||
|
||||
override protected function compareTargets(x:ILayoutTarget, y:ILayoutTarget) : Number
|
||||
{
|
||||
var attributesX:LayoutAttributesMetadata = x.layoutMetadata.getValue(MetadataNamespaces.LAYOUT_ATTRIBUTES) as LayoutAttributesMetadata;
|
||||
var attributesY:LayoutAttributesMetadata = y.layoutMetadata.getValue(MetadataNamespaces.LAYOUT_ATTRIBUTES) as LayoutAttributesMetadata;
|
||||
var indexX:Number = Boolean(attributesX) ? attributesX.index : NaN;
|
||||
var indexY:Number = Boolean(attributesY) ? attributesY.index : NaN;
|
||||
if(isNaN(indexX) && isNaN(indexY))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
indexX ||= 0;
|
||||
indexY ||= 0;
|
||||
return indexX < indexY ? -1 : (indexX > indexY ? 1 : 0);
|
||||
}
|
||||
|
||||
override protected function calculateTargetBounds(target:ILayoutTarget, availableWidth:Number, availableHeight:Number) : Rectangle
|
||||
{
|
||||
var deltaX:Number = NaN;
|
||||
var deltaY:Number = NaN;
|
||||
var box:BoxAttributesMetadata = null;
|
||||
var relative:RelativeLayoutMetadata = null;
|
||||
var anchors:AnchorLayoutMetadata = null;
|
||||
var size:Point = null;
|
||||
var attributes:LayoutAttributesMetadata = target.layoutMetadata.getValue(MetadataNamespaces.LAYOUT_ATTRIBUTES) as LayoutAttributesMetadata || new LayoutAttributesMetadata();
|
||||
if(attributes.includeInLayout == false)
|
||||
{
|
||||
return new Rectangle();
|
||||
}
|
||||
var rect:Rectangle = new Rectangle(0,0,target.measuredWidth,target.measuredHeight);
|
||||
var absolute:AbsoluteLayoutMetadata = target.layoutMetadata.getValue(MetadataNamespaces.ABSOLUTE_LAYOUT_PARAMETERS) as AbsoluteLayoutMetadata;
|
||||
var deltaXExclude:Number = 0;
|
||||
var deltaYExclude:Number = 0;
|
||||
var toDo:int = ALL;
|
||||
if(Boolean(absolute))
|
||||
{
|
||||
if(!isNaN(absolute.x))
|
||||
{
|
||||
rect.x = absolute.x;
|
||||
toDo ^= X;
|
||||
}
|
||||
if(!isNaN(absolute.y))
|
||||
{
|
||||
rect.y = absolute.y;
|
||||
toDo ^= Y;
|
||||
}
|
||||
if(!isNaN(absolute.width))
|
||||
{
|
||||
rect.width = absolute.width;
|
||||
toDo ^= WIDTH;
|
||||
}
|
||||
if(!isNaN(absolute.height))
|
||||
{
|
||||
rect.height = absolute.height;
|
||||
toDo ^= HEIGHT;
|
||||
}
|
||||
}
|
||||
if(toDo != 0)
|
||||
{
|
||||
relative = target.layoutMetadata.getValue(MetadataNamespaces.RELATIVE_LAYOUT_PARAMETERS) as RelativeLayoutMetadata;
|
||||
if(Boolean(relative))
|
||||
{
|
||||
if(Boolean(toDo & X) && !isNaN(relative.x))
|
||||
{
|
||||
rect.x = availableWidth * relative.x / 100 || 0;
|
||||
toDo ^= X;
|
||||
}
|
||||
if(Boolean(toDo & WIDTH) && !isNaN(relative.width))
|
||||
{
|
||||
if(this.layoutMode == LayoutMode.HORIZONTAL)
|
||||
{
|
||||
box = container.layoutMetadata.getValue(MetadataNamespaces.BOX_LAYOUT_ATTRIBUTES) as BoxAttributesMetadata || new BoxAttributesMetadata();
|
||||
rect.width = Math.max(0,availableWidth - box.absoluteSum) * relative.width / box.relativeSum;
|
||||
}
|
||||
else
|
||||
{
|
||||
rect.width = availableWidth * relative.width / 100;
|
||||
}
|
||||
toDo ^= WIDTH;
|
||||
}
|
||||
if(Boolean(toDo & Y) && !isNaN(relative.y))
|
||||
{
|
||||
rect.y = availableHeight * relative.y / 100 || 0;
|
||||
toDo ^= Y;
|
||||
}
|
||||
if(Boolean(toDo & HEIGHT) && !isNaN(relative.height))
|
||||
{
|
||||
if(this.layoutMode == LayoutMode.VERTICAL)
|
||||
{
|
||||
box = container.layoutMetadata.getValue(MetadataNamespaces.BOX_LAYOUT_ATTRIBUTES) as BoxAttributesMetadata || new BoxAttributesMetadata();
|
||||
rect.height = Math.max(0,availableHeight - box.absoluteSum) * relative.height / box.relativeSum;
|
||||
}
|
||||
else
|
||||
{
|
||||
rect.height = availableHeight * relative.height / 100;
|
||||
}
|
||||
toDo ^= HEIGHT;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(toDo != 0)
|
||||
{
|
||||
anchors = target.layoutMetadata.getValue(MetadataNamespaces.ANCHOR_LAYOUT_PARAMETERS) as AnchorLayoutMetadata;
|
||||
if(Boolean(anchors))
|
||||
{
|
||||
if(Boolean(toDo & X) && !isNaN(anchors.left))
|
||||
{
|
||||
rect.x = anchors.left;
|
||||
toDo ^= X;
|
||||
}
|
||||
if(Boolean(toDo & Y) && !isNaN(anchors.top))
|
||||
{
|
||||
rect.y = anchors.top;
|
||||
toDo ^= Y;
|
||||
}
|
||||
if(!isNaN(anchors.right) && Boolean(availableWidth))
|
||||
{
|
||||
if(Boolean(toDo & X) && !(toDo & WIDTH))
|
||||
{
|
||||
rect.x = Math.max(0,availableWidth - rect.width - anchors.right);
|
||||
toDo ^= X;
|
||||
}
|
||||
else if(Boolean(toDo & WIDTH) && !(toDo & X))
|
||||
{
|
||||
rect.width = Math.max(0,availableWidth - anchors.right - rect.x);
|
||||
toDo ^= WIDTH;
|
||||
}
|
||||
else
|
||||
{
|
||||
rect.x = Math.max(0,availableWidth - target.measuredWidth - anchors.right);
|
||||
toDo ^= X;
|
||||
}
|
||||
deltaXExclude += anchors.right;
|
||||
}
|
||||
if(!isNaN(anchors.bottom) && Boolean(availableHeight))
|
||||
{
|
||||
if(Boolean(toDo & Y) && !(toDo & HEIGHT))
|
||||
{
|
||||
rect.y = Math.max(0,availableHeight - rect.height - anchors.bottom);
|
||||
toDo ^= Y;
|
||||
}
|
||||
else if(Boolean(toDo & HEIGHT) && !(toDo & Y))
|
||||
{
|
||||
rect.height = Math.max(0,availableHeight - anchors.bottom - rect.y);
|
||||
toDo ^= HEIGHT;
|
||||
}
|
||||
else
|
||||
{
|
||||
rect.y = Math.max(0,availableHeight - target.measuredHeight - anchors.bottom);
|
||||
toDo ^= Y;
|
||||
}
|
||||
deltaYExclude += anchors.bottom;
|
||||
}
|
||||
}
|
||||
}
|
||||
var padding:PaddingLayoutMetadata = target.layoutMetadata.getValue(MetadataNamespaces.PADDING_LAYOUT_PARAMETERS) as PaddingLayoutMetadata;
|
||||
if(Boolean(padding))
|
||||
{
|
||||
if(!isNaN(padding.left))
|
||||
{
|
||||
rect.x += padding.left;
|
||||
}
|
||||
if(!isNaN(padding.top))
|
||||
{
|
||||
rect.y += padding.top;
|
||||
}
|
||||
if(!isNaN(padding.right) && !(toDo & WIDTH))
|
||||
{
|
||||
rect.width -= padding.right + (padding.left || 0);
|
||||
}
|
||||
if(!isNaN(padding.bottom) && !(toDo & HEIGHT))
|
||||
{
|
||||
rect.height -= padding.bottom + (padding.top || 0);
|
||||
}
|
||||
}
|
||||
if(Boolean(attributes.scaleMode))
|
||||
{
|
||||
if(Boolean(!(toDo & WIDTH || toDo & HEIGHT)) && Boolean(target.measuredWidth) && Boolean(target.measuredHeight))
|
||||
{
|
||||
size = ScaleModeUtils.getScaledSize(attributes.scaleMode,rect.width,rect.height,target.measuredWidth,target.measuredHeight);
|
||||
deltaX = rect.width - size.x;
|
||||
deltaY = rect.height - size.y;
|
||||
rect.width = size.x;
|
||||
rect.height = size.y;
|
||||
}
|
||||
}
|
||||
if(this.layoutMode != LayoutMode.HORIZONTAL)
|
||||
{
|
||||
deltaX ||= availableWidth - (rect.x || 0) - (rect.width || 0) - deltaXExclude;
|
||||
}
|
||||
if(this.layoutMode != LayoutMode.VERTICAL)
|
||||
{
|
||||
deltaY ||= availableHeight - (rect.y || 0) - (rect.height || 0) - deltaYExclude;
|
||||
}
|
||||
if(Boolean(deltaY))
|
||||
{
|
||||
switch(attributes.verticalAlign)
|
||||
{
|
||||
case null:
|
||||
case VerticalAlign.TOP:
|
||||
break;
|
||||
case VerticalAlign.MIDDLE:
|
||||
rect.y += deltaY / 2;
|
||||
break;
|
||||
case VerticalAlign.BOTTOM:
|
||||
rect.y += deltaY;
|
||||
}
|
||||
}
|
||||
if(Boolean(deltaX))
|
||||
{
|
||||
switch(attributes.horizontalAlign)
|
||||
{
|
||||
case null:
|
||||
case HorizontalAlign.LEFT:
|
||||
break;
|
||||
case HorizontalAlign.CENTER:
|
||||
rect.x += deltaX / 2;
|
||||
break;
|
||||
case HorizontalAlign.RIGHT:
|
||||
rect.x += deltaX;
|
||||
}
|
||||
}
|
||||
if(attributes.snapToPixel)
|
||||
{
|
||||
rect.x = Math.round(rect.x);
|
||||
rect.y = Math.round(rect.y);
|
||||
rect.width = Math.round(rect.width);
|
||||
rect.height = Math.round(rect.height);
|
||||
}
|
||||
if(this.layoutMode == LayoutMode.HORIZONTAL || this.layoutMode == LayoutMode.VERTICAL)
|
||||
{
|
||||
if(this.lastCalculatedBounds != null)
|
||||
{
|
||||
if(this.layoutMode == LayoutMode.HORIZONTAL)
|
||||
{
|
||||
rect.x = this.lastCalculatedBounds.x + this.lastCalculatedBounds.width;
|
||||
}
|
||||
else
|
||||
{
|
||||
rect.y = this.lastCalculatedBounds.y + this.lastCalculatedBounds.height;
|
||||
}
|
||||
}
|
||||
this.lastCalculatedBounds = rect;
|
||||
}
|
||||
return rect;
|
||||
}
|
||||
|
||||
override protected function calculateContainerSize(targets:Vector.<ILayoutTarget>) : Point
|
||||
{
|
||||
var boxAttributes:BoxAttributesMetadata = null;
|
||||
var containerBounds:Rectangle = null;
|
||||
var targetBounds:Rectangle = null;
|
||||
var lastBounds:Rectangle = null;
|
||||
var target:ILayoutTarget = null;
|
||||
var size:Point = new Point(NaN,NaN);
|
||||
var absolute:AbsoluteLayoutMetadata = container.layoutMetadata.getValue(MetadataNamespaces.ABSOLUTE_LAYOUT_PARAMETERS) as AbsoluteLayoutMetadata;
|
||||
if(Boolean(absolute))
|
||||
{
|
||||
size.x = absolute.width;
|
||||
size.y = absolute.height;
|
||||
}
|
||||
if(this.layoutMode != LayoutMode.NONE)
|
||||
{
|
||||
boxAttributes = new BoxAttributesMetadata();
|
||||
container.layoutMetadata.addValue(MetadataNamespaces.BOX_LAYOUT_ATTRIBUTES,boxAttributes);
|
||||
}
|
||||
if(isNaN(size.x) || isNaN(size.y) || this.layoutMode != LayoutMode.NONE)
|
||||
{
|
||||
containerBounds = new Rectangle();
|
||||
for each(target in targets)
|
||||
{
|
||||
if(target.layoutMetadata.includeInLayout)
|
||||
{
|
||||
targetBounds = this.calculateTargetBounds(target,size.x,size.y);
|
||||
targetBounds.x = targetBounds.x || 0;
|
||||
targetBounds.y = targetBounds.y || 0;
|
||||
targetBounds.width = targetBounds.width || (target.measuredWidth || 0);
|
||||
targetBounds.height = targetBounds.height || (target.measuredHeight || 0);
|
||||
if(this.layoutMode == LayoutMode.HORIZONTAL)
|
||||
{
|
||||
if(!isNaN(target.layoutMetadata.percentWidth))
|
||||
{
|
||||
boxAttributes.relativeSum += target.layoutMetadata.percentWidth;
|
||||
}
|
||||
else
|
||||
{
|
||||
boxAttributes.absoluteSum += targetBounds.width;
|
||||
}
|
||||
if(Boolean(lastBounds))
|
||||
{
|
||||
targetBounds.x = lastBounds.x + lastBounds.width;
|
||||
}
|
||||
lastBounds = targetBounds;
|
||||
}
|
||||
else if(this.layoutMode == LayoutMode.VERTICAL)
|
||||
{
|
||||
if(!isNaN(target.layoutMetadata.percentHeight))
|
||||
{
|
||||
boxAttributes.relativeSum += target.layoutMetadata.percentHeight;
|
||||
}
|
||||
else
|
||||
{
|
||||
boxAttributes.absoluteSum += targetBounds.height;
|
||||
}
|
||||
if(Boolean(lastBounds))
|
||||
{
|
||||
targetBounds.y = lastBounds.y + lastBounds.height;
|
||||
}
|
||||
lastBounds = targetBounds;
|
||||
}
|
||||
containerBounds = containerBounds.union(targetBounds);
|
||||
}
|
||||
}
|
||||
size.x = size.x || (absolute == null || isNaN(absolute.width) ? containerBounds.width : absolute.width);
|
||||
size.y = size.y || (absolute == null || isNaN(absolute.height) ? containerBounds.height : absolute.height);
|
||||
}
|
||||
return size;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,446 @@
|
||||
package org.osmf.layout
|
||||
{
|
||||
import flash.display.DisplayObject;
|
||||
import flash.display.Sprite;
|
||||
import flash.errors.IllegalOperationError;
|
||||
import flash.events.Event;
|
||||
import flash.events.EventDispatcher;
|
||||
import flash.geom.Point;
|
||||
import flash.geom.Rectangle;
|
||||
import flash.utils.Dictionary;
|
||||
import org.osmf.events.DisplayObjectEvent;
|
||||
import org.osmf.metadata.Metadata;
|
||||
import org.osmf.metadata.MetadataWatcher;
|
||||
import org.osmf.utils.OSMFStrings;
|
||||
|
||||
public class LayoutRendererBase extends EventDispatcher
|
||||
{
|
||||
|
||||
private static var cleaningRenderers:Boolean;
|
||||
|
||||
private static var dispatcher:DisplayObject = new Sprite();
|
||||
|
||||
private static var dirtyRenderers:Vector.<LayoutRendererBase> = new Vector.<LayoutRendererBase>();
|
||||
|
||||
private var _parent:LayoutRendererBase;
|
||||
|
||||
private var _container:ILayoutTarget;
|
||||
|
||||
private var layoutMetadata:LayoutMetadata;
|
||||
|
||||
private var layoutTargets:Vector.<ILayoutTarget> = new Vector.<ILayoutTarget>();
|
||||
|
||||
private var stagedDisplayObjects:Dictionary = new Dictionary(true);
|
||||
|
||||
private var _measuredWidth:Number;
|
||||
|
||||
private var _measuredHeight:Number;
|
||||
|
||||
private var dirty:Boolean;
|
||||
|
||||
private var cleaning:Boolean;
|
||||
|
||||
private var metaDataWatchers:Dictionary = new Dictionary();
|
||||
|
||||
public function LayoutRendererBase()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
private static function flagDirty(renderer:LayoutRendererBase) : void
|
||||
{
|
||||
if(renderer == null || dirtyRenderers.indexOf(renderer) != -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
dirtyRenderers.push(renderer);
|
||||
if(cleaningRenderers == false)
|
||||
{
|
||||
dispatcher.addEventListener(Event.EXIT_FRAME,onExitFrame);
|
||||
}
|
||||
}
|
||||
|
||||
private static function flagClean(renderer:LayoutRendererBase) : void
|
||||
{
|
||||
var index:Number = dirtyRenderers.indexOf(renderer);
|
||||
if(index != -1)
|
||||
{
|
||||
dirtyRenderers.splice(index,1);
|
||||
}
|
||||
}
|
||||
|
||||
private static function onExitFrame(event:Event) : void
|
||||
{
|
||||
var renderer:LayoutRendererBase = null;
|
||||
dispatcher.removeEventListener(Event.EXIT_FRAME,onExitFrame);
|
||||
cleaningRenderers = true;
|
||||
while(dirtyRenderers.length != 0)
|
||||
{
|
||||
renderer = dirtyRenderers.shift();
|
||||
if(renderer.parent == null)
|
||||
{
|
||||
renderer.validateNow();
|
||||
}
|
||||
else
|
||||
{
|
||||
renderer.dirty = false;
|
||||
}
|
||||
}
|
||||
cleaningRenderers = false;
|
||||
}
|
||||
|
||||
final public function get parent() : LayoutRendererBase
|
||||
{
|
||||
return this._parent;
|
||||
}
|
||||
|
||||
final internal function setParent(value:LayoutRendererBase) : void
|
||||
{
|
||||
this._parent = value;
|
||||
this.processParentChange(this._parent);
|
||||
}
|
||||
|
||||
final public function get container() : ILayoutTarget
|
||||
{
|
||||
return this._container;
|
||||
}
|
||||
|
||||
final public function set container(value:ILayoutTarget) : void
|
||||
{
|
||||
var oldContainer:ILayoutTarget = null;
|
||||
if(value != this._container)
|
||||
{
|
||||
oldContainer = this._container;
|
||||
if(oldContainer != null)
|
||||
{
|
||||
this.reset();
|
||||
oldContainer.dispatchEvent(new LayoutTargetEvent(LayoutTargetEvent.UNSET_AS_LAYOUT_RENDERER_CONTAINER,false,false,this));
|
||||
oldContainer.removeEventListener(DisplayObjectEvent.MEDIA_SIZE_CHANGE,this.invalidatingEventHandler);
|
||||
}
|
||||
this._container = value;
|
||||
if(Boolean(this._container))
|
||||
{
|
||||
this.layoutMetadata = this._container.layoutMetadata;
|
||||
this._container.addEventListener(DisplayObjectEvent.MEDIA_SIZE_CHANGE,this.invalidatingEventHandler,false,0,true);
|
||||
this._container.dispatchEvent(new LayoutTargetEvent(LayoutTargetEvent.SET_AS_LAYOUT_RENDERER_CONTAINER,false,false,this));
|
||||
this.invalidate();
|
||||
}
|
||||
this.processContainerChange(oldContainer,value);
|
||||
}
|
||||
}
|
||||
|
||||
final public function addTarget(target:ILayoutTarget) : ILayoutTarget
|
||||
{
|
||||
var namespaceURL:String = null;
|
||||
var watcher:MetadataWatcher = null;
|
||||
if(target == null)
|
||||
{
|
||||
throw new IllegalOperationError(OSMFStrings.getString(OSMFStrings.NULL_PARAM));
|
||||
}
|
||||
if(this.layoutTargets.indexOf(target) != -1)
|
||||
{
|
||||
throw new IllegalOperationError(OSMFStrings.getString(OSMFStrings.INVALID_PARAM));
|
||||
}
|
||||
target.dispatchEvent(new LayoutTargetEvent(LayoutTargetEvent.ADD_TO_LAYOUT_RENDERER,false,false,this));
|
||||
var index:int = Math.abs(BinarySearch.search(this.layoutTargets,this.compareTargets,target));
|
||||
this.layoutTargets.splice(index,0,target);
|
||||
var watchers:Array = this.metaDataWatchers[target] = new Array();
|
||||
for each(namespaceURL in this.usedMetadatas)
|
||||
{
|
||||
watcher = new MetadataWatcher(target.layoutMetadata,namespaceURL,null,this.targetMetadataChangeCallback);
|
||||
watcher.watch();
|
||||
watchers.push(watcher);
|
||||
}
|
||||
target.addEventListener(DisplayObjectEvent.DISPLAY_OBJECT_CHANGE,this.invalidatingEventHandler);
|
||||
target.addEventListener(DisplayObjectEvent.MEDIA_SIZE_CHANGE,this.invalidatingEventHandler);
|
||||
target.addEventListener(LayoutTargetEvent.ADD_TO_LAYOUT_RENDERER,this.onTargetAddedToRenderer);
|
||||
target.addEventListener(LayoutTargetEvent.SET_AS_LAYOUT_RENDERER_CONTAINER,this.onTargetSetAsContainer);
|
||||
this.invalidate();
|
||||
this.processTargetAdded(target);
|
||||
return target;
|
||||
}
|
||||
|
||||
final public function removeTarget(target:ILayoutTarget) : ILayoutTarget
|
||||
{
|
||||
var removedTarget:ILayoutTarget = null;
|
||||
var watcher:MetadataWatcher = null;
|
||||
if(target == null)
|
||||
{
|
||||
throw new IllegalOperationError(OSMFStrings.getString(OSMFStrings.NULL_PARAM));
|
||||
}
|
||||
var index:Number = this.layoutTargets.indexOf(target);
|
||||
if(index != -1)
|
||||
{
|
||||
this.removeFromStage(target);
|
||||
removedTarget = this.layoutTargets.splice(index,1)[0];
|
||||
target.removeEventListener(DisplayObjectEvent.DISPLAY_OBJECT_CHANGE,this.invalidatingEventHandler);
|
||||
target.removeEventListener(DisplayObjectEvent.MEDIA_SIZE_CHANGE,this.invalidatingEventHandler);
|
||||
target.removeEventListener(LayoutTargetEvent.ADD_TO_LAYOUT_RENDERER,this.onTargetAddedToRenderer);
|
||||
target.removeEventListener(LayoutTargetEvent.SET_AS_LAYOUT_RENDERER_CONTAINER,this.onTargetSetAsContainer);
|
||||
for each(watcher in this.metaDataWatchers[target])
|
||||
{
|
||||
watcher.unwatch();
|
||||
}
|
||||
delete this.metaDataWatchers[target];
|
||||
this.processTargetRemoved(target);
|
||||
target.dispatchEvent(new LayoutTargetEvent(LayoutTargetEvent.REMOVE_FROM_LAYOUT_RENDERER,false,false,this));
|
||||
this.invalidate();
|
||||
return removedTarget;
|
||||
}
|
||||
throw new IllegalOperationError(OSMFStrings.getString(OSMFStrings.INVALID_PARAM));
|
||||
}
|
||||
|
||||
final public function hasTarget(target:ILayoutTarget) : Boolean
|
||||
{
|
||||
return this.layoutTargets.indexOf(target) != -1;
|
||||
}
|
||||
|
||||
final public function get measuredWidth() : Number
|
||||
{
|
||||
return this._measuredWidth;
|
||||
}
|
||||
|
||||
final public function get measuredHeight() : Number
|
||||
{
|
||||
return this._measuredHeight;
|
||||
}
|
||||
|
||||
final public function invalidate() : void
|
||||
{
|
||||
if(this.cleaning == false && this.dirty == false)
|
||||
{
|
||||
this.dirty = true;
|
||||
if(this._parent != null)
|
||||
{
|
||||
this._parent.invalidate();
|
||||
}
|
||||
else
|
||||
{
|
||||
flagDirty(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final public function validateNow() : void
|
||||
{
|
||||
if(this._container == null || this.cleaning == true)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if(Boolean(this._parent))
|
||||
{
|
||||
this._parent.validateNow();
|
||||
return;
|
||||
}
|
||||
this.cleaning = true;
|
||||
this.measure();
|
||||
this.layout(this._measuredWidth,this._measuredHeight);
|
||||
this.cleaning = false;
|
||||
}
|
||||
|
||||
internal function measure() : void
|
||||
{
|
||||
var target:ILayoutTarget = null;
|
||||
var size:Point = null;
|
||||
this.prepareTargets();
|
||||
for each(target in this.layoutTargets)
|
||||
{
|
||||
target.measure(true);
|
||||
}
|
||||
size = this.calculateContainerSize(this.layoutTargets);
|
||||
this._measuredWidth = size.x;
|
||||
this._measuredHeight = size.y;
|
||||
this._container.measure(false);
|
||||
}
|
||||
|
||||
internal function layout(availableWidth:Number, availableHeight:Number) : void
|
||||
{
|
||||
var target:ILayoutTarget = null;
|
||||
var bounds:Rectangle = null;
|
||||
var displayObject:DisplayObject = null;
|
||||
this.processUpdateMediaDisplayBegin(this.layoutTargets);
|
||||
this._container.layout(availableWidth,availableHeight,false);
|
||||
for each(target in this.layoutTargets)
|
||||
{
|
||||
bounds = this.calculateTargetBounds(target,availableWidth,availableHeight);
|
||||
target.layout(bounds.width,bounds.height,true);
|
||||
displayObject = target.displayObject;
|
||||
if(Boolean(displayObject))
|
||||
{
|
||||
displayObject.x = bounds.x;
|
||||
displayObject.y = bounds.y;
|
||||
}
|
||||
}
|
||||
this.dirty = false;
|
||||
this.processUpdateMediaDisplayEnd();
|
||||
}
|
||||
|
||||
protected function get usedMetadatas() : Vector.<String>
|
||||
{
|
||||
return new Vector.<String>();
|
||||
}
|
||||
|
||||
protected function compareTargets(x:ILayoutTarget, y:ILayoutTarget) : Number
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
protected function processContainerChange(oldContainer:ILayoutTarget, newContainer:ILayoutTarget) : void
|
||||
{
|
||||
}
|
||||
|
||||
protected function processTargetAdded(target:ILayoutTarget) : void
|
||||
{
|
||||
}
|
||||
|
||||
protected function processTargetRemoved(target:ILayoutTarget) : void
|
||||
{
|
||||
}
|
||||
|
||||
protected function processStagedTarget(target:ILayoutTarget) : void
|
||||
{
|
||||
}
|
||||
|
||||
protected function processUnstagedTarget(target:ILayoutTarget) : void
|
||||
{
|
||||
}
|
||||
|
||||
protected function processUpdateMediaDisplayBegin(targets:Vector.<ILayoutTarget>) : void
|
||||
{
|
||||
}
|
||||
|
||||
protected function processUpdateMediaDisplayEnd() : void
|
||||
{
|
||||
}
|
||||
|
||||
protected function updateTargetOrder(target:ILayoutTarget) : void
|
||||
{
|
||||
var index:int = this.layoutTargets.indexOf(target);
|
||||
if(index != -1)
|
||||
{
|
||||
this.layoutTargets.splice(index,1);
|
||||
index = Math.abs(BinarySearch.search(this.layoutTargets,this.compareTargets,target));
|
||||
this.layoutTargets.splice(index,0,target);
|
||||
}
|
||||
}
|
||||
|
||||
protected function calculateTargetBounds(target:ILayoutTarget, availableWidth:Number, availableHeight:Number) : Rectangle
|
||||
{
|
||||
return new Rectangle();
|
||||
}
|
||||
|
||||
protected function calculateContainerSize(targets:Vector.<ILayoutTarget>) : Point
|
||||
{
|
||||
return new Point();
|
||||
}
|
||||
|
||||
protected function processParentChange(value:LayoutRendererBase) : void
|
||||
{
|
||||
}
|
||||
|
||||
private function reset() : void
|
||||
{
|
||||
var target:ILayoutTarget = null;
|
||||
for each(target in this.layoutTargets)
|
||||
{
|
||||
this.removeTarget(target);
|
||||
}
|
||||
if(Boolean(this._container))
|
||||
{
|
||||
this._container.removeEventListener(DisplayObjectEvent.MEDIA_SIZE_CHANGE,this.invalidatingEventHandler);
|
||||
this.validateNow();
|
||||
}
|
||||
this._container = null;
|
||||
this.layoutMetadata = null;
|
||||
}
|
||||
|
||||
private function targetMetadataChangeCallback(metadata:Metadata) : void
|
||||
{
|
||||
this.invalidate();
|
||||
}
|
||||
|
||||
private function invalidatingEventHandler(event:Event) : void
|
||||
{
|
||||
this.invalidate();
|
||||
}
|
||||
|
||||
private function onTargetAddedToRenderer(event:LayoutTargetEvent) : void
|
||||
{
|
||||
var target:ILayoutTarget = null;
|
||||
if(event.layoutRenderer != this)
|
||||
{
|
||||
target = event.target as ILayoutTarget;
|
||||
if(this.hasTarget(target))
|
||||
{
|
||||
this.removeTarget(target);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function onTargetSetAsContainer(event:LayoutTargetEvent) : void
|
||||
{
|
||||
var target:ILayoutTarget = null;
|
||||
if(event.layoutRenderer != this)
|
||||
{
|
||||
target = event.target as ILayoutTarget;
|
||||
if(this.container == target)
|
||||
{
|
||||
this.container = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function prepareTargets() : void
|
||||
{
|
||||
var target:ILayoutTarget = null;
|
||||
var displayObject:DisplayObject = null;
|
||||
var displayListCounter:int = 0;
|
||||
for each(target in this.layoutTargets)
|
||||
{
|
||||
displayObject = target.displayObject;
|
||||
if(Boolean(displayObject))
|
||||
{
|
||||
this.addToStage(target,target.displayObject,displayListCounter);
|
||||
displayListCounter++;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.removeFromStage(target);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function addToStage(target:ILayoutTarget, object:DisplayObject, index:Number) : void
|
||||
{
|
||||
var currentObject:DisplayObject = this.stagedDisplayObjects[target];
|
||||
if(currentObject == object)
|
||||
{
|
||||
this._container.dispatchEvent(new LayoutTargetEvent(LayoutTargetEvent.SET_CHILD_INDEX,false,false,this,target,currentObject,index));
|
||||
}
|
||||
else
|
||||
{
|
||||
if(currentObject != null)
|
||||
{
|
||||
this._container.dispatchEvent(new LayoutTargetEvent(LayoutTargetEvent.REMOVE_CHILD,false,false,this,target,currentObject));
|
||||
}
|
||||
this.stagedDisplayObjects[target] = object;
|
||||
this._container.dispatchEvent(new LayoutTargetEvent(LayoutTargetEvent.ADD_CHILD_AT,false,false,this,target,object,index));
|
||||
if(currentObject == null)
|
||||
{
|
||||
this.processStagedTarget(target);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function removeFromStage(target:ILayoutTarget) : void
|
||||
{
|
||||
var currentObject:DisplayObject = this.stagedDisplayObjects[target];
|
||||
if(currentObject != null)
|
||||
{
|
||||
delete this.stagedDisplayObjects[target];
|
||||
this._container.dispatchEvent(new LayoutTargetEvent(LayoutTargetEvent.REMOVE_CHILD,false,false,this,target,currentObject));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
package org.osmf.layout
|
||||
{
|
||||
import flash.display.DisplayObject;
|
||||
import flash.events.Event;
|
||||
|
||||
public class LayoutTargetEvent extends Event
|
||||
{
|
||||
|
||||
public static const SET_AS_LAYOUT_RENDERER_CONTAINER:String = "setAsLayoutRendererContainer";
|
||||
|
||||
public static const UNSET_AS_LAYOUT_RENDERER_CONTAINER:String = "unsetAsLayoutRendererContainer";
|
||||
|
||||
public static const ADD_TO_LAYOUT_RENDERER:String = "addToLayoutRenderer";
|
||||
|
||||
public static const REMOVE_FROM_LAYOUT_RENDERER:String = "removeFromLayoutRenderer";
|
||||
|
||||
public static const ADD_CHILD_AT:String = "addChildAt";
|
||||
|
||||
public static const REMOVE_CHILD:String = "removeChild";
|
||||
|
||||
public static const SET_CHILD_INDEX:String = "setChildIndex";
|
||||
|
||||
private var _layoutRenderer:LayoutRendererBase;
|
||||
|
||||
private var _layoutTarget:ILayoutTarget;
|
||||
|
||||
private var _displayObject:DisplayObject;
|
||||
|
||||
private var _index:int;
|
||||
|
||||
public function LayoutTargetEvent(type:String, bubbles:Boolean = false, cancelable:Boolean = false, layoutRenderer:LayoutRendererBase = null, layoutTarget:ILayoutTarget = null, displayObject:DisplayObject = null, index:int = -1)
|
||||
{
|
||||
this._layoutRenderer = layoutRenderer;
|
||||
this._layoutTarget = layoutTarget;
|
||||
this._displayObject = displayObject;
|
||||
this._index = index;
|
||||
super(type,bubbles,cancelable);
|
||||
}
|
||||
|
||||
public function get layoutRenderer() : LayoutRendererBase
|
||||
{
|
||||
return this._layoutRenderer;
|
||||
}
|
||||
|
||||
public function get layoutTarget() : ILayoutTarget
|
||||
{
|
||||
return this._layoutTarget;
|
||||
}
|
||||
|
||||
public function get displayObject() : DisplayObject
|
||||
{
|
||||
return this._displayObject;
|
||||
}
|
||||
|
||||
public function get index() : int
|
||||
{
|
||||
return this._index;
|
||||
}
|
||||
|
||||
override public function clone() : Event
|
||||
{
|
||||
return new LayoutTargetEvent(type,bubbles,cancelable,this._layoutRenderer,this._layoutTarget,this._displayObject,this._index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
package org.osmf.layout
|
||||
{
|
||||
internal class LayoutTargetRenderers
|
||||
{
|
||||
|
||||
public var containerRenderer:LayoutRendererBase;
|
||||
|
||||
public var parentRenderer:LayoutRendererBase;
|
||||
|
||||
public function LayoutTargetRenderers(target:ILayoutTarget)
|
||||
{
|
||||
super();
|
||||
target.addEventListener(LayoutTargetEvent.ADD_TO_LAYOUT_RENDERER,this.onAddedToLayoutRenderer);
|
||||
target.addEventListener(LayoutTargetEvent.REMOVE_FROM_LAYOUT_RENDERER,this.onRemovedFromLayoutRenderer);
|
||||
target.addEventListener(LayoutTargetEvent.SET_AS_LAYOUT_RENDERER_CONTAINER,this.onSetAsLayoutRendererContainer);
|
||||
target.addEventListener(LayoutTargetEvent.UNSET_AS_LAYOUT_RENDERER_CONTAINER,this.onUnsetAsLayoutRendererContainer);
|
||||
}
|
||||
|
||||
private function onSetAsLayoutRendererContainer(event:LayoutTargetEvent) : void
|
||||
{
|
||||
if(this.containerRenderer != event.layoutRenderer)
|
||||
{
|
||||
this.containerRenderer = event.layoutRenderer;
|
||||
this.containerRenderer.setParent(this.parentRenderer);
|
||||
}
|
||||
}
|
||||
|
||||
private function onUnsetAsLayoutRendererContainer(event:LayoutTargetEvent) : void
|
||||
{
|
||||
if(this.containerRenderer != null && this.containerRenderer == event.layoutRenderer)
|
||||
{
|
||||
this.containerRenderer.setParent(null);
|
||||
this.containerRenderer = null;
|
||||
}
|
||||
}
|
||||
|
||||
private function onAddedToLayoutRenderer(event:LayoutTargetEvent) : void
|
||||
{
|
||||
if(this.parentRenderer != event.layoutRenderer)
|
||||
{
|
||||
this.parentRenderer = event.layoutRenderer;
|
||||
if(Boolean(this.containerRenderer))
|
||||
{
|
||||
this.containerRenderer.setParent(this.parentRenderer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function onRemovedFromLayoutRenderer(event:LayoutTargetEvent) : void
|
||||
{
|
||||
if(this.parentRenderer == event.layoutRenderer)
|
||||
{
|
||||
this.parentRenderer = null;
|
||||
if(Boolean(this.containerRenderer))
|
||||
{
|
||||
this.containerRenderer.setParent(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,141 @@
|
||||
package org.osmf.layout
|
||||
{
|
||||
import flash.display.DisplayObject;
|
||||
import flash.display.Sprite;
|
||||
import org.osmf.events.DisplayObjectEvent;
|
||||
|
||||
[Event(name="removeChild",type="org.osmf.layout.LayoutTargetEvent")]
|
||||
[Event(name="setChildIndex",type="org.osmf.layout.LayoutTargetEvent")]
|
||||
[Event(name="addChildAt",type="org.osmf.layout.LayoutTargetEvent")]
|
||||
[Event(name="removeFromLayoutRenderer",type="org.osmf.layout.LayoutTargetEvent")]
|
||||
[Event(name="addToLayoutRenderer",type="org.osmf.layout.LayoutTargetEvent")]
|
||||
[Event(name="unsetAsLayoutRendererContainer",type="org.osmf.layout.LayoutTargetEvent")]
|
||||
[Event(name="setAsLayoutRendererContainer",type="org.osmf.layout.LayoutTargetEvent")]
|
||||
public class LayoutTargetSprite extends Sprite implements ILayoutTarget
|
||||
{
|
||||
|
||||
private var _layoutMetadata:LayoutMetadata;
|
||||
|
||||
private var _measuredWidth:Number = NaN;
|
||||
|
||||
private var _measuredHeight:Number = NaN;
|
||||
|
||||
private var renderers:LayoutTargetRenderers = new LayoutTargetRenderers(this);
|
||||
|
||||
public function LayoutTargetSprite(layoutMetadata:LayoutMetadata = null)
|
||||
{
|
||||
this._layoutMetadata = layoutMetadata || new LayoutMetadata();
|
||||
addEventListener(LayoutTargetEvent.ADD_CHILD_AT,this.onAddChildAt);
|
||||
addEventListener(LayoutTargetEvent.SET_CHILD_INDEX,this.onSetChildIndex);
|
||||
addEventListener(LayoutTargetEvent.REMOVE_CHILD,this.onRemoveChild);
|
||||
mouseEnabled = true;
|
||||
mouseChildren = true;
|
||||
super();
|
||||
}
|
||||
|
||||
public function get displayObject() : DisplayObject
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
public function get layoutMetadata() : LayoutMetadata
|
||||
{
|
||||
return this._layoutMetadata;
|
||||
}
|
||||
|
||||
public function get measuredWidth() : Number
|
||||
{
|
||||
return this._measuredWidth;
|
||||
}
|
||||
|
||||
public function get measuredHeight() : Number
|
||||
{
|
||||
return this._measuredHeight;
|
||||
}
|
||||
|
||||
public function measure(deep:Boolean = true) : void
|
||||
{
|
||||
var newMeasuredWidth:Number = NaN;
|
||||
var newMeasuredHeight:Number = NaN;
|
||||
var event:DisplayObjectEvent = null;
|
||||
if(deep && Boolean(this.renderers.containerRenderer))
|
||||
{
|
||||
this.renderers.containerRenderer.measure();
|
||||
}
|
||||
if(Boolean(this.renderers.containerRenderer))
|
||||
{
|
||||
newMeasuredWidth = this.renderers.containerRenderer.measuredWidth;
|
||||
newMeasuredHeight = this.renderers.containerRenderer.measuredHeight;
|
||||
}
|
||||
else
|
||||
{
|
||||
newMeasuredWidth = super.width / scaleX;
|
||||
newMeasuredHeight = super.height / scaleY;
|
||||
}
|
||||
if(newMeasuredWidth != this._measuredWidth || newMeasuredHeight != this._measuredHeight)
|
||||
{
|
||||
event = new DisplayObjectEvent(DisplayObjectEvent.MEDIA_SIZE_CHANGE,false,false,null,null,this._measuredWidth,this._measuredHeight,newMeasuredWidth,newMeasuredHeight);
|
||||
this._measuredWidth = newMeasuredWidth;
|
||||
this._measuredHeight = newMeasuredHeight;
|
||||
dispatchEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
public function layout(availableWidth:Number, availableHeight:Number, deep:Boolean = true) : void
|
||||
{
|
||||
if(this.renderers.containerRenderer == null)
|
||||
{
|
||||
super.width = availableWidth;
|
||||
super.height = availableHeight;
|
||||
}
|
||||
else if(deep)
|
||||
{
|
||||
this.renderers.containerRenderer.layout(availableWidth,availableHeight);
|
||||
}
|
||||
}
|
||||
|
||||
public function validateNow() : void
|
||||
{
|
||||
if(Boolean(this.renderers.containerRenderer))
|
||||
{
|
||||
this.renderers.containerRenderer.validateNow();
|
||||
}
|
||||
}
|
||||
|
||||
protected function onAddChildAt(event:LayoutTargetEvent) : void
|
||||
{
|
||||
addChildAt(event.displayObject,event.index);
|
||||
}
|
||||
|
||||
protected function onRemoveChild(event:LayoutTargetEvent) : void
|
||||
{
|
||||
removeChild(event.displayObject);
|
||||
}
|
||||
|
||||
protected function onSetChildIndex(event:LayoutTargetEvent) : void
|
||||
{
|
||||
setChildIndex(event.displayObject,event.index);
|
||||
}
|
||||
|
||||
override public function set width(value:Number) : void
|
||||
{
|
||||
this._layoutMetadata.width = value;
|
||||
}
|
||||
|
||||
override public function get width() : Number
|
||||
{
|
||||
return this._measuredWidth;
|
||||
}
|
||||
|
||||
override public function set height(value:Number) : void
|
||||
{
|
||||
this._layoutMetadata.height = value;
|
||||
}
|
||||
|
||||
override public function get height() : Number
|
||||
{
|
||||
return this._measuredHeight;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,236 @@
|
||||
package org.osmf.layout
|
||||
{
|
||||
import flash.display.DisplayObject;
|
||||
import flash.display.DisplayObjectContainer;
|
||||
import flash.errors.IllegalOperationError;
|
||||
import flash.events.EventDispatcher;
|
||||
import flash.utils.Dictionary;
|
||||
import org.osmf.events.DisplayObjectEvent;
|
||||
import org.osmf.events.MediaElementEvent;
|
||||
import org.osmf.media.MediaElement;
|
||||
import org.osmf.traits.DisplayObjectTrait;
|
||||
import org.osmf.traits.MediaTraitType;
|
||||
import org.osmf.utils.OSMFStrings;
|
||||
|
||||
[Event(name="removeChild",type="org.osmf.layout.LayoutTargetEvent")]
|
||||
[Event(name="setChildIndex",type="org.osmf.layout.LayoutTargetEvent")]
|
||||
[Event(name="addChildAt",type="org.osmf.layout.LayoutTargetEvent")]
|
||||
[Event(name="removeFromLayoutRenderer",type="org.osmf.layout.LayoutTargetEvent")]
|
||||
[Event(name="addToLayoutRenderer",type="org.osmf.layout.LayoutTargetEvent")]
|
||||
[Event(name="unsetAsLayoutRendererContainer",type="org.osmf.layout.LayoutTargetEvent")]
|
||||
[Event(name="setAsLayoutRendererContainer",type="org.osmf.layout.LayoutTargetEvent")]
|
||||
public class MediaElementLayoutTarget extends EventDispatcher implements ILayoutTarget
|
||||
{
|
||||
|
||||
private static const layoutTargets:Dictionary = new Dictionary(true);
|
||||
|
||||
private var _mediaElement:MediaElement;
|
||||
|
||||
private var _layoutMetadata:LayoutMetadata;
|
||||
|
||||
private var displayObjectTrait:DisplayObjectTrait;
|
||||
|
||||
private var _displayObject:DisplayObject;
|
||||
|
||||
private var renderers:LayoutTargetRenderers;
|
||||
|
||||
public function MediaElementLayoutTarget(mediaElement:MediaElement, constructorLock:Class)
|
||||
{
|
||||
super();
|
||||
if(constructorLock != ConstructorLock)
|
||||
{
|
||||
throw new IllegalOperationError(OSMFStrings.getString(OSMFStrings.ILLEGAL_CONSTRUCTOR_INVOCATION));
|
||||
}
|
||||
this._mediaElement = mediaElement;
|
||||
this._mediaElement.addEventListener(MediaElementEvent.TRAIT_ADD,this.onMediaElementTraitsChange);
|
||||
this._mediaElement.addEventListener(MediaElementEvent.TRAIT_REMOVE,this.onMediaElementTraitsChange);
|
||||
this._mediaElement.addEventListener(MediaElementEvent.METADATA_ADD,this.onMetadataAdd);
|
||||
this._mediaElement.addEventListener(MediaElementEvent.METADATA_REMOVE,this.onMetadataRemove);
|
||||
this.renderers = new LayoutTargetRenderers(this);
|
||||
this._layoutMetadata = this._mediaElement.getMetadata(LayoutMetadata.LAYOUT_NAMESPACE) as LayoutMetadata;
|
||||
addEventListener(LayoutTargetEvent.ADD_CHILD_AT,this.onAddChildAt);
|
||||
addEventListener(LayoutTargetEvent.SET_CHILD_INDEX,this.onSetChildIndex);
|
||||
addEventListener(LayoutTargetEvent.REMOVE_CHILD,this.onRemoveChild);
|
||||
this.onMediaElementTraitsChange();
|
||||
}
|
||||
|
||||
public static function getInstance(mediaElement:MediaElement) : MediaElementLayoutTarget
|
||||
{
|
||||
var instance:* = undefined;
|
||||
for(instance in layoutTargets)
|
||||
{
|
||||
if(instance.mediaElement == mediaElement)
|
||||
{
|
||||
break;
|
||||
}
|
||||
instance = null;
|
||||
}
|
||||
if(instance == null)
|
||||
{
|
||||
instance = new MediaElementLayoutTarget(mediaElement,ConstructorLock);
|
||||
layoutTargets[instance] = true;
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public function get mediaElement() : MediaElement
|
||||
{
|
||||
return this._mediaElement;
|
||||
}
|
||||
|
||||
public function get layoutMetadata() : LayoutMetadata
|
||||
{
|
||||
if(this._layoutMetadata == null)
|
||||
{
|
||||
this._layoutMetadata = new LayoutMetadata();
|
||||
this._mediaElement.addMetadata(LayoutMetadata.LAYOUT_NAMESPACE,this._layoutMetadata);
|
||||
}
|
||||
return this._layoutMetadata;
|
||||
}
|
||||
|
||||
public function get displayObject() : DisplayObject
|
||||
{
|
||||
return this._displayObject;
|
||||
}
|
||||
|
||||
public function get measuredWidth() : Number
|
||||
{
|
||||
return Boolean(this.displayObjectTrait) ? this.displayObjectTrait.mediaWidth : NaN;
|
||||
}
|
||||
|
||||
public function get measuredHeight() : Number
|
||||
{
|
||||
return Boolean(this.displayObjectTrait) ? this.displayObjectTrait.mediaHeight : NaN;
|
||||
}
|
||||
|
||||
public function measure(deep:Boolean = true) : void
|
||||
{
|
||||
if(this._displayObject is ILayoutTarget)
|
||||
{
|
||||
ILayoutTarget(this._displayObject).measure(deep);
|
||||
}
|
||||
}
|
||||
|
||||
public function layout(availableWidth:Number, availableHeight:Number, deep:Boolean = true) : void
|
||||
{
|
||||
if(this._displayObject is ILayoutTarget)
|
||||
{
|
||||
ILayoutTarget(this._displayObject).layout(availableWidth,availableHeight,deep);
|
||||
}
|
||||
else if(this._displayObject != null && this.renderers.containerRenderer == null)
|
||||
{
|
||||
this._displayObject.width = availableWidth;
|
||||
this._displayObject.height = availableHeight;
|
||||
}
|
||||
}
|
||||
|
||||
private function onMediaElementTraitsChange(event:MediaElementEvent = null) : void
|
||||
{
|
||||
var newDisplayObjectTrait:DisplayObjectTrait = null;
|
||||
if(event == null || Boolean(event) && Boolean(event.traitType == MediaTraitType.DISPLAY_OBJECT))
|
||||
{
|
||||
newDisplayObjectTrait = Boolean(event) && event.type == MediaElementEvent.TRAIT_REMOVE ? null : this._mediaElement.getTrait(MediaTraitType.DISPLAY_OBJECT) as DisplayObjectTrait;
|
||||
if(newDisplayObjectTrait != this.displayObjectTrait)
|
||||
{
|
||||
if(Boolean(this.displayObjectTrait))
|
||||
{
|
||||
this.displayObjectTrait.removeEventListener(DisplayObjectEvent.DISPLAY_OBJECT_CHANGE,this.onDisplayObjectTraitDisplayObjecChange);
|
||||
this.displayObjectTrait.removeEventListener(DisplayObjectEvent.MEDIA_SIZE_CHANGE,this.onDisplayObjectTraitMediaSizeChange);
|
||||
}
|
||||
this.displayObjectTrait = newDisplayObjectTrait;
|
||||
if(Boolean(this.displayObjectTrait))
|
||||
{
|
||||
this.displayObjectTrait.addEventListener(DisplayObjectEvent.DISPLAY_OBJECT_CHANGE,this.onDisplayObjectTraitDisplayObjecChange);
|
||||
this.displayObjectTrait.addEventListener(DisplayObjectEvent.MEDIA_SIZE_CHANGE,this.onDisplayObjectTraitMediaSizeChange);
|
||||
}
|
||||
this.updateDisplayObject(Boolean(this.displayObjectTrait) ? this.displayObjectTrait.displayObject : null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function onMetadataAdd(event:MediaElementEvent) : void
|
||||
{
|
||||
if(event.namespaceURL == LayoutMetadata.LAYOUT_NAMESPACE)
|
||||
{
|
||||
this._layoutMetadata = event.metadata as LayoutMetadata;
|
||||
}
|
||||
}
|
||||
|
||||
private function onMetadataRemove(event:MediaElementEvent) : void
|
||||
{
|
||||
if(event.namespaceURL == LayoutMetadata.LAYOUT_NAMESPACE)
|
||||
{
|
||||
this._layoutMetadata = null;
|
||||
}
|
||||
}
|
||||
|
||||
private function updateDisplayObject(newDisplayObject:DisplayObject) : void
|
||||
{
|
||||
var oldDisplayObject:DisplayObject = this._displayObject;
|
||||
if(newDisplayObject != this.displayObject)
|
||||
{
|
||||
this._displayObject = newDisplayObject;
|
||||
dispatchEvent(new DisplayObjectEvent(DisplayObjectEvent.DISPLAY_OBJECT_CHANGE,false,false,oldDisplayObject,newDisplayObject));
|
||||
}
|
||||
if(newDisplayObject is ILayoutTarget && Boolean(this.renderers.parentRenderer))
|
||||
{
|
||||
ILayoutTarget(newDisplayObject).dispatchEvent(new LayoutTargetEvent(LayoutTargetEvent.ADD_TO_LAYOUT_RENDERER,false,false,this.renderers.parentRenderer));
|
||||
}
|
||||
}
|
||||
|
||||
private function onDisplayObjectTraitDisplayObjecChange(event:DisplayObjectEvent) : void
|
||||
{
|
||||
this.updateDisplayObject(event.newDisplayObject);
|
||||
}
|
||||
|
||||
private function onDisplayObjectTraitMediaSizeChange(event:DisplayObjectEvent) : void
|
||||
{
|
||||
dispatchEvent(event.clone());
|
||||
}
|
||||
|
||||
private function onAddChildAt(event:LayoutTargetEvent) : void
|
||||
{
|
||||
if(this._displayObject is ILayoutTarget)
|
||||
{
|
||||
ILayoutTarget(this._displayObject).dispatchEvent(event.clone());
|
||||
}
|
||||
else if(this._displayObject is DisplayObjectContainer)
|
||||
{
|
||||
DisplayObjectContainer(this._displayObject).addChildAt(event.displayObject,event.index);
|
||||
}
|
||||
}
|
||||
|
||||
private function onRemoveChild(event:LayoutTargetEvent) : void
|
||||
{
|
||||
if(this._displayObject is ILayoutTarget)
|
||||
{
|
||||
ILayoutTarget(this._displayObject).dispatchEvent(event.clone());
|
||||
}
|
||||
else if(this._displayObject is DisplayObjectContainer)
|
||||
{
|
||||
DisplayObjectContainer(this._displayObject).removeChild(event.displayObject);
|
||||
}
|
||||
}
|
||||
|
||||
private function onSetChildIndex(event:LayoutTargetEvent) : void
|
||||
{
|
||||
if(this._displayObject is ILayoutTarget)
|
||||
{
|
||||
ILayoutTarget(this._displayObject).dispatchEvent(event.clone());
|
||||
}
|
||||
else if(this._displayObject is DisplayObjectContainer)
|
||||
{
|
||||
DisplayObjectContainer(this._displayObject).setChildIndex(event.displayObject,event.index);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class ConstructorLock
|
||||
{
|
||||
|
||||
public function ConstructorLock()
|
||||
{
|
||||
super();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
package org.osmf.layout
|
||||
{
|
||||
import org.osmf.events.MetadataEvent;
|
||||
import org.osmf.metadata.NonSynthesizingMetadata;
|
||||
|
||||
internal class PaddingLayoutMetadata extends NonSynthesizingMetadata
|
||||
{
|
||||
|
||||
public static const LEFT:String = "left";
|
||||
|
||||
public static const TOP:String = "top";
|
||||
|
||||
public static const RIGHT:String = "right";
|
||||
|
||||
public static const BOTTOM:String = "bottom";
|
||||
|
||||
private var _left:Number;
|
||||
|
||||
private var _top:Number;
|
||||
|
||||
private var _right:Number;
|
||||
|
||||
private var _bottom:Number;
|
||||
|
||||
public function PaddingLayoutMetadata()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
override public function getValue(key:String) : *
|
||||
{
|
||||
if(key == null)
|
||||
{
|
||||
return undefined;
|
||||
}
|
||||
if(key == LEFT)
|
||||
{
|
||||
return this.left;
|
||||
}
|
||||
if(key == TOP)
|
||||
{
|
||||
return this.top;
|
||||
}
|
||||
if(key == RIGHT)
|
||||
{
|
||||
return this.right;
|
||||
}
|
||||
if(key == BOTTOM)
|
||||
{
|
||||
return this.bottom;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
public function get left() : Number
|
||||
{
|
||||
return this._left;
|
||||
}
|
||||
|
||||
public function set left(value:Number) : void
|
||||
{
|
||||
var event:MetadataEvent = null;
|
||||
if(this._left != value)
|
||||
{
|
||||
event = new MetadataEvent(MetadataEvent.VALUE_CHANGE,false,false,LEFT,value,this._left);
|
||||
this._left = value;
|
||||
dispatchEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
public function get top() : Number
|
||||
{
|
||||
return this._top;
|
||||
}
|
||||
|
||||
public function set top(value:Number) : void
|
||||
{
|
||||
var event:MetadataEvent = null;
|
||||
if(this._top != value)
|
||||
{
|
||||
event = new MetadataEvent(MetadataEvent.VALUE_CHANGE,false,false,TOP,value,this._top);
|
||||
this._top = value;
|
||||
dispatchEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
public function get right() : Number
|
||||
{
|
||||
return this._right;
|
||||
}
|
||||
|
||||
public function set right(value:Number) : void
|
||||
{
|
||||
var event:MetadataEvent = null;
|
||||
if(this._right != value)
|
||||
{
|
||||
event = new MetadataEvent(MetadataEvent.VALUE_CHANGE,false,false,RIGHT,value,this._right);
|
||||
this._right = value;
|
||||
dispatchEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
public function get bottom() : Number
|
||||
{
|
||||
return this._bottom;
|
||||
}
|
||||
|
||||
public function set bottom(value:Number) : void
|
||||
{
|
||||
var event:MetadataEvent = null;
|
||||
if(this._bottom != value)
|
||||
{
|
||||
event = new MetadataEvent(MetadataEvent.VALUE_CHANGE,false,false,BOTTOM,value,this._bottom);
|
||||
this._bottom = value;
|
||||
dispatchEvent(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
package org.osmf.layout
|
||||
{
|
||||
import org.osmf.events.MetadataEvent;
|
||||
import org.osmf.metadata.NonSynthesizingMetadata;
|
||||
|
||||
internal class RelativeLayoutMetadata extends NonSynthesizingMetadata
|
||||
{
|
||||
|
||||
public static const X:String = "x";
|
||||
|
||||
public static const Y:String = "y";
|
||||
|
||||
public static const WIDTH:String = "width";
|
||||
|
||||
public static const HEIGHT:String = "height";
|
||||
|
||||
private var _x:Number;
|
||||
|
||||
private var _y:Number;
|
||||
|
||||
private var _width:Number;
|
||||
|
||||
private var _height:Number;
|
||||
|
||||
public function RelativeLayoutMetadata()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
override public function getValue(key:String) : *
|
||||
{
|
||||
if(key == null)
|
||||
{
|
||||
return undefined;
|
||||
}
|
||||
if(key == X)
|
||||
{
|
||||
return this.x;
|
||||
}
|
||||
if(key == Y)
|
||||
{
|
||||
return this.y;
|
||||
}
|
||||
if(key == WIDTH)
|
||||
{
|
||||
return this.width;
|
||||
}
|
||||
if(key == HEIGHT)
|
||||
{
|
||||
return this.height;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
public function get x() : Number
|
||||
{
|
||||
return this._x;
|
||||
}
|
||||
|
||||
public function set x(value:Number) : void
|
||||
{
|
||||
var event:MetadataEvent = null;
|
||||
if(this._x != value)
|
||||
{
|
||||
event = new MetadataEvent(MetadataEvent.VALUE_CHANGE,false,false,X,value,this._x);
|
||||
this._x = value;
|
||||
dispatchEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
public function get y() : Number
|
||||
{
|
||||
return this._y;
|
||||
}
|
||||
|
||||
public function set y(value:Number) : void
|
||||
{
|
||||
var event:MetadataEvent = null;
|
||||
if(this._y != value)
|
||||
{
|
||||
event = new MetadataEvent(MetadataEvent.VALUE_CHANGE,false,false,Y,value,this._y);
|
||||
this._y = value;
|
||||
dispatchEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
public function get width() : Number
|
||||
{
|
||||
return this._width;
|
||||
}
|
||||
|
||||
public function set width(value:Number) : void
|
||||
{
|
||||
var event:MetadataEvent = null;
|
||||
if(this._width != value)
|
||||
{
|
||||
event = new MetadataEvent(MetadataEvent.VALUE_CHANGE,false,false,WIDTH,value,this._width);
|
||||
this._width = value;
|
||||
dispatchEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
public function get height() : Number
|
||||
{
|
||||
return this._height;
|
||||
}
|
||||
|
||||
public function set height(value:Number) : void
|
||||
{
|
||||
var event:MetadataEvent = null;
|
||||
if(this._height != value)
|
||||
{
|
||||
event = new MetadataEvent(MetadataEvent.VALUE_CHANGE,false,false,HEIGHT,value,this._height);
|
||||
this._height = value;
|
||||
dispatchEvent(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package org.osmf.layout
|
||||
{
|
||||
public final class ScaleMode
|
||||
{
|
||||
|
||||
public static const NONE:String = "none";
|
||||
|
||||
public static const STRETCH:String = "stretch";
|
||||
|
||||
public static const LETTERBOX:String = "letterbox";
|
||||
|
||||
public static const ZOOM:String = "zoom";
|
||||
|
||||
public function ScaleMode()
|
||||
{
|
||||
super();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
package org.osmf.layout
|
||||
{
|
||||
import flash.geom.Point;
|
||||
|
||||
internal class ScaleModeUtils
|
||||
{
|
||||
|
||||
public function ScaleModeUtils()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public static function getScaledSize(scaleMode:String, availableWidth:Number, availableHeight:Number, intrinsicWidth:Number, intrinsicHeight:Number) : Point
|
||||
{
|
||||
var result:Point = null;
|
||||
var availableRatio:Number = NaN;
|
||||
var componentRatio:Number = NaN;
|
||||
switch(scaleMode)
|
||||
{
|
||||
case ScaleMode.ZOOM:
|
||||
case ScaleMode.LETTERBOX:
|
||||
availableRatio = availableWidth / availableHeight;
|
||||
componentRatio = (intrinsicWidth || availableWidth) / (intrinsicHeight || availableHeight);
|
||||
if(scaleMode == ScaleMode.ZOOM && componentRatio < availableRatio || scaleMode == ScaleMode.LETTERBOX && componentRatio > availableRatio)
|
||||
{
|
||||
result = new Point(availableWidth,availableWidth / componentRatio);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = new Point(availableHeight * componentRatio,availableHeight);
|
||||
}
|
||||
break;
|
||||
case ScaleMode.STRETCH:
|
||||
result = new Point(availableWidth,availableHeight);
|
||||
break;
|
||||
case ScaleMode.NONE:
|
||||
result = new Point(intrinsicWidth || availableWidth,intrinsicHeight || availableHeight);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package org.osmf.layout
|
||||
{
|
||||
public final class VerticalAlign
|
||||
{
|
||||
|
||||
public static const TOP:String = "top";
|
||||
|
||||
public static const MIDDLE:String = "middle";
|
||||
|
||||
public static const BOTTOM:String = "bottom";
|
||||
|
||||
public function VerticalAlign()
|
||||
{
|
||||
super();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
package org.osmf.media
|
||||
{
|
||||
import org.osmf.elements.AudioElement;
|
||||
import org.osmf.elements.F4MElement;
|
||||
import org.osmf.elements.F4MLoader;
|
||||
import org.osmf.elements.ImageElement;
|
||||
import org.osmf.elements.ImageLoader;
|
||||
import org.osmf.elements.SWFElement;
|
||||
import org.osmf.elements.SWFLoader;
|
||||
import org.osmf.elements.SoundLoader;
|
||||
import org.osmf.elements.VideoElement;
|
||||
import org.osmf.net.MulticastNetLoader;
|
||||
import org.osmf.net.NetLoader;
|
||||
import org.osmf.net.dvr.DVRCastNetLoader;
|
||||
import org.osmf.net.httpstreaming.HTTPStreamingNetLoader;
|
||||
import org.osmf.net.rtmpstreaming.RTMPDynamicStreamingNetLoader;
|
||||
|
||||
public class DefaultMediaFactory extends MediaFactory
|
||||
{
|
||||
|
||||
private var rtmpStreamingNetLoader:RTMPDynamicStreamingNetLoader;
|
||||
|
||||
private var f4mLoader:F4MLoader;
|
||||
|
||||
private var dvrCastLoader:DVRCastNetLoader;
|
||||
|
||||
private var netLoader:NetLoader;
|
||||
|
||||
private var imageLoader:ImageLoader;
|
||||
|
||||
private var swfLoader:SWFLoader;
|
||||
|
||||
private var soundLoader:SoundLoader;
|
||||
|
||||
private var httpStreamingNetLoader:HTTPStreamingNetLoader;
|
||||
|
||||
private var multicastLoader:MulticastNetLoader;
|
||||
|
||||
public function DefaultMediaFactory()
|
||||
{
|
||||
super();
|
||||
this.init();
|
||||
}
|
||||
|
||||
private function init() : void
|
||||
{
|
||||
this.f4mLoader = new F4MLoader(this);
|
||||
addItem(new MediaFactoryItem("org.osmf.elements.f4m",this.f4mLoader.canHandleResource,function():MediaElement
|
||||
{
|
||||
return new F4MElement(null,f4mLoader);
|
||||
}));
|
||||
this.dvrCastLoader = new DVRCastNetLoader();
|
||||
addItem(new MediaFactoryItem("org.osmf.elements.video.dvr.dvrcast",this.dvrCastLoader.canHandleResource,function():MediaElement
|
||||
{
|
||||
return new VideoElement(null,dvrCastLoader);
|
||||
}));
|
||||
this.httpStreamingNetLoader = new HTTPStreamingNetLoader();
|
||||
addItem(new MediaFactoryItem("org.osmf.elements.video.httpstreaming",this.httpStreamingNetLoader.canHandleResource,function():MediaElement
|
||||
{
|
||||
return new VideoElement(null,httpStreamingNetLoader);
|
||||
}));
|
||||
this.multicastLoader = new MulticastNetLoader();
|
||||
addItem(new MediaFactoryItem("org.osmf.elements.video.rtmfp.multicast",this.multicastLoader.canHandleResource,function():MediaElement
|
||||
{
|
||||
return new VideoElement(null,multicastLoader);
|
||||
}));
|
||||
this.rtmpStreamingNetLoader = new RTMPDynamicStreamingNetLoader();
|
||||
addItem(new MediaFactoryItem("org.osmf.elements.video.rtmpdynamicStreaming",this.rtmpStreamingNetLoader.canHandleResource,function():MediaElement
|
||||
{
|
||||
return new VideoElement(null,rtmpStreamingNetLoader);
|
||||
}));
|
||||
this.netLoader = new NetLoader();
|
||||
addItem(new MediaFactoryItem("org.osmf.elements.video",this.netLoader.canHandleResource,function():MediaElement
|
||||
{
|
||||
return new VideoElement(null,netLoader);
|
||||
}));
|
||||
this.soundLoader = new SoundLoader();
|
||||
addItem(new MediaFactoryItem("org.osmf.elements.audio",this.soundLoader.canHandleResource,function():MediaElement
|
||||
{
|
||||
return new AudioElement(null,soundLoader);
|
||||
}));
|
||||
addItem(new MediaFactoryItem("org.osmf.elements.audio.streaming",this.netLoader.canHandleResource,function():MediaElement
|
||||
{
|
||||
return new AudioElement(null,netLoader);
|
||||
}));
|
||||
this.imageLoader = new ImageLoader();
|
||||
addItem(new MediaFactoryItem("org.osmf.elements.image",this.imageLoader.canHandleResource,function():MediaElement
|
||||
{
|
||||
return new ImageElement(null,imageLoader);
|
||||
}));
|
||||
this.swfLoader = new SWFLoader();
|
||||
addItem(new MediaFactoryItem("org.osmf.elements.swf",this.swfLoader.canHandleResource,function():MediaElement
|
||||
{
|
||||
return new SWFElement(null,swfLoader);
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
package org.osmf.media
|
||||
{
|
||||
import org.osmf.traits.MediaTraitBase;
|
||||
import org.osmf.utils.OSMFStrings;
|
||||
|
||||
[ExcludeClass]
|
||||
public class DefaultTraitResolver extends MediaTraitResolver
|
||||
{
|
||||
|
||||
private var defaultTrait:MediaTraitBase;
|
||||
|
||||
private var trait:MediaTraitBase;
|
||||
|
||||
public function DefaultTraitResolver(type:String, defaultTrait:MediaTraitBase)
|
||||
{
|
||||
super(type);
|
||||
if(defaultTrait == null)
|
||||
{
|
||||
throw new ArgumentError(OSMFStrings.getString(OSMFStrings.NULL_PARAM));
|
||||
}
|
||||
if(defaultTrait.traitType != type)
|
||||
{
|
||||
throw new ArgumentError(OSMFStrings.getString(OSMFStrings.INVALID_PARAM));
|
||||
}
|
||||
this.defaultTrait = defaultTrait;
|
||||
setResolvedTrait(defaultTrait);
|
||||
}
|
||||
|
||||
override protected function processAddTrait(instance:MediaTraitBase) : void
|
||||
{
|
||||
if(this.trait == null)
|
||||
{
|
||||
setResolvedTrait(this.trait = instance);
|
||||
}
|
||||
}
|
||||
|
||||
override protected function processRemoveTrait(instance:MediaTraitBase) : MediaTraitBase
|
||||
{
|
||||
var result:MediaTraitBase = null;
|
||||
if(Boolean(instance) && instance == this.trait)
|
||||
{
|
||||
result = this.trait;
|
||||
this.trait = null;
|
||||
setResolvedTrait(this.defaultTrait);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,118 @@
|
||||
package org.osmf.media
|
||||
{
|
||||
import org.osmf.events.LoadEvent;
|
||||
import org.osmf.traits.LoadState;
|
||||
import org.osmf.traits.LoadTrait;
|
||||
import org.osmf.traits.LoaderBase;
|
||||
import org.osmf.traits.MediaTraitType;
|
||||
|
||||
public class LoadableElementBase extends MediaElement
|
||||
{
|
||||
|
||||
private var _loader:LoaderBase;
|
||||
|
||||
public function LoadableElementBase(resource:MediaResourceBase = null, loader:LoaderBase = null)
|
||||
{
|
||||
super();
|
||||
this._loader = loader;
|
||||
this.resource = resource;
|
||||
}
|
||||
|
||||
override public function set resource(value:MediaResourceBase) : void
|
||||
{
|
||||
super.resource = value;
|
||||
this.updateLoadTrait();
|
||||
}
|
||||
|
||||
final protected function get loader() : LoaderBase
|
||||
{
|
||||
return this._loader;
|
||||
}
|
||||
|
||||
final protected function set loader(value:LoaderBase) : void
|
||||
{
|
||||
this._loader = value;
|
||||
}
|
||||
|
||||
protected function createLoadTrait(resource:MediaResourceBase, loader:LoaderBase) : LoadTrait
|
||||
{
|
||||
return new LoadTrait(this._loader,resource);
|
||||
}
|
||||
|
||||
protected function processLoadingState() : void
|
||||
{
|
||||
}
|
||||
|
||||
protected function processReadyState() : void
|
||||
{
|
||||
}
|
||||
|
||||
protected function processUnloadingState() : void
|
||||
{
|
||||
}
|
||||
|
||||
protected function getLoaderForResource(resource:MediaResourceBase, alternateLoaders:Vector.<LoaderBase>) : LoaderBase
|
||||
{
|
||||
var loaderFound:Boolean = false;
|
||||
var alternateLoader:LoaderBase = null;
|
||||
var result:LoaderBase = this.loader;
|
||||
if(resource != null && (this.loader == null || this.loader.canHandleResource(resource) == false))
|
||||
{
|
||||
loaderFound = false;
|
||||
for each(alternateLoader in alternateLoaders)
|
||||
{
|
||||
if(this.loader == null || this.loader != alternateLoader)
|
||||
{
|
||||
if(alternateLoader.canHandleResource(resource))
|
||||
{
|
||||
result = alternateLoader;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(result == null && alternateLoaders != null)
|
||||
{
|
||||
result = alternateLoaders[alternateLoaders.length - 1];
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private function onLoadStateChange(event:LoadEvent) : void
|
||||
{
|
||||
if(event.loadState == LoadState.LOADING)
|
||||
{
|
||||
this.processLoadingState();
|
||||
}
|
||||
else if(event.loadState == LoadState.READY)
|
||||
{
|
||||
this.processReadyState();
|
||||
}
|
||||
else if(event.loadState == LoadState.UNLOADING)
|
||||
{
|
||||
this.processUnloadingState();
|
||||
}
|
||||
}
|
||||
|
||||
private function updateLoadTrait() : void
|
||||
{
|
||||
var loadTrait:LoadTrait = getTrait(MediaTraitType.LOAD) as LoadTrait;
|
||||
if(loadTrait != null)
|
||||
{
|
||||
if(loadTrait.loadState == LoadState.READY)
|
||||
{
|
||||
loadTrait.unload();
|
||||
}
|
||||
loadTrait.removeEventListener(LoadEvent.LOAD_STATE_CHANGE,this.onLoadStateChange);
|
||||
removeTrait(MediaTraitType.LOAD);
|
||||
}
|
||||
if(this.loader != null)
|
||||
{
|
||||
loadTrait = this.createLoadTrait(resource,this.loader);
|
||||
loadTrait.addEventListener(LoadEvent.LOAD_STATE_CHANGE,this.onLoadStateChange,false,10);
|
||||
addTrait(MediaTraitType.LOAD,loadTrait);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,288 @@
|
||||
package org.osmf.media
|
||||
{
|
||||
import flash.events.Event;
|
||||
import flash.events.EventDispatcher;
|
||||
import flash.utils.Dictionary;
|
||||
import org.osmf.containers.IMediaContainer;
|
||||
import org.osmf.events.ContainerChangeEvent;
|
||||
import org.osmf.events.MediaElementEvent;
|
||||
import org.osmf.events.MediaErrorEvent;
|
||||
import org.osmf.events.MetadataEvent;
|
||||
import org.osmf.metadata.Metadata;
|
||||
import org.osmf.traits.MediaTraitBase;
|
||||
import org.osmf.utils.OSMFStrings;
|
||||
|
||||
[Event(name="containerChange",type="org.osmf.events.ContainerChangeEvent")]
|
||||
[Event(name="mediaError",type="org.osmf.events.MediaErrorEvent")]
|
||||
[Event(name="metadataRemove",type="org.osmf.events.MediaElementEvent")]
|
||||
[Event(name="metadataAdd",type="org.osmf.events.MediaElementEvent")]
|
||||
[Event(name="traitRemove",type="org.osmf.events.MediaElementEvent")]
|
||||
[Event(name="traitAdd",type="org.osmf.events.MediaElementEvent")]
|
||||
public class MediaElement extends EventDispatcher
|
||||
{
|
||||
|
||||
private var traits:Dictionary = new Dictionary();
|
||||
|
||||
private var traitResolvers:Dictionary = new Dictionary();
|
||||
|
||||
private var unresolvedTraits:Dictionary = new Dictionary();
|
||||
|
||||
private var _traitTypes:Vector.<String> = new Vector.<String>();
|
||||
|
||||
private var _resource:MediaResourceBase;
|
||||
|
||||
private var _metadata:Metadata;
|
||||
|
||||
private var _container:IMediaContainer;
|
||||
|
||||
public function MediaElement()
|
||||
{
|
||||
super();
|
||||
this._metadata = this.createMetadata();
|
||||
this._metadata.addEventListener(MetadataEvent.VALUE_ADD,this.onMetadataValueAdd);
|
||||
this._metadata.addEventListener(MetadataEvent.VALUE_REMOVE,this.onMetadataValueRemove);
|
||||
this._metadata.addEventListener(MetadataEvent.VALUE_CHANGE,this.onMetadataValueChange);
|
||||
this.setupTraitResolvers();
|
||||
this.setupTraits();
|
||||
addEventListener(ContainerChangeEvent.CONTAINER_CHANGE,this.onContainerChange,false,Number.MAX_VALUE);
|
||||
}
|
||||
|
||||
public function get traitTypes() : Vector.<String>
|
||||
{
|
||||
return this._traitTypes.concat();
|
||||
}
|
||||
|
||||
public function hasTrait(type:String) : Boolean
|
||||
{
|
||||
if(type == null)
|
||||
{
|
||||
throw new ArgumentError(OSMFStrings.getString(OSMFStrings.INVALID_PARAM));
|
||||
}
|
||||
return this.traits[type] != null;
|
||||
}
|
||||
|
||||
public function getTrait(type:String) : MediaTraitBase
|
||||
{
|
||||
if(type == null)
|
||||
{
|
||||
throw new ArgumentError(OSMFStrings.getString(OSMFStrings.INVALID_PARAM));
|
||||
}
|
||||
return this.traits[type];
|
||||
}
|
||||
|
||||
public function get resource() : MediaResourceBase
|
||||
{
|
||||
return this._resource;
|
||||
}
|
||||
|
||||
public function set resource(value:MediaResourceBase) : void
|
||||
{
|
||||
this._resource = value;
|
||||
}
|
||||
|
||||
public function get container() : IMediaContainer
|
||||
{
|
||||
return this._container;
|
||||
}
|
||||
|
||||
public function addMetadata(namespaceURL:String, metadata:Metadata) : void
|
||||
{
|
||||
if(namespaceURL == null || metadata == null)
|
||||
{
|
||||
throw new ArgumentError(OSMFStrings.getString(OSMFStrings.NULL_PARAM));
|
||||
}
|
||||
this.metadata.addValue(namespaceURL,metadata);
|
||||
}
|
||||
|
||||
public function removeMetadata(namespaceURL:String) : Metadata
|
||||
{
|
||||
if(namespaceURL == null)
|
||||
{
|
||||
throw new ArgumentError(OSMFStrings.getString(OSMFStrings.NULL_PARAM));
|
||||
}
|
||||
return this.metadata.removeValue(namespaceURL) as Metadata;
|
||||
}
|
||||
|
||||
public function getMetadata(namespaceURL:String) : Metadata
|
||||
{
|
||||
if(namespaceURL == null)
|
||||
{
|
||||
throw new ArgumentError(OSMFStrings.getString(OSMFStrings.NULL_PARAM));
|
||||
}
|
||||
return this.metadata.getValue(namespaceURL) as Metadata;
|
||||
}
|
||||
|
||||
public function get metadataNamespaceURLs() : Vector.<String>
|
||||
{
|
||||
return this.metadata.keys;
|
||||
}
|
||||
|
||||
protected function createMetadata() : Metadata
|
||||
{
|
||||
return new Metadata();
|
||||
}
|
||||
|
||||
public function get metadata() : Metadata
|
||||
{
|
||||
return this._metadata;
|
||||
}
|
||||
|
||||
protected function addTrait(type:String, instance:MediaTraitBase) : void
|
||||
{
|
||||
if(type == null || instance == null || type != instance.traitType)
|
||||
{
|
||||
throw new ArgumentError(OSMFStrings.getString(OSMFStrings.INVALID_PARAM));
|
||||
}
|
||||
var traitResolver:MediaTraitResolver = this.traitResolvers[type];
|
||||
if(traitResolver != null)
|
||||
{
|
||||
traitResolver.addTrait(instance);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.setLocalTrait(type,instance);
|
||||
}
|
||||
}
|
||||
|
||||
protected function removeTrait(type:String) : MediaTraitBase
|
||||
{
|
||||
if(type == null)
|
||||
{
|
||||
throw new ArgumentError(OSMFStrings.getString(OSMFStrings.INVALID_PARAM));
|
||||
}
|
||||
var trait:MediaTraitBase = this.traits[type];
|
||||
var traitResolver:MediaTraitResolver = this.traitResolvers[type];
|
||||
if(traitResolver != null)
|
||||
{
|
||||
return traitResolver.removeTrait(trait);
|
||||
}
|
||||
return this.setLocalTrait(type,null);
|
||||
}
|
||||
|
||||
final protected function addTraitResolver(type:String, instance:MediaTraitResolver) : void
|
||||
{
|
||||
var currentlySetTrait:MediaTraitBase = null;
|
||||
if(instance == null || instance.type != type)
|
||||
{
|
||||
throw new ArgumentError(OSMFStrings.getString(OSMFStrings.INVALID_PARAM));
|
||||
}
|
||||
if(this.traitResolvers[type] == null)
|
||||
{
|
||||
this.unresolvedTraits[type] = this.traits[type];
|
||||
this.traitResolvers[type] = instance;
|
||||
currentlySetTrait = this.traits[type];
|
||||
if(Boolean(currentlySetTrait))
|
||||
{
|
||||
instance.addTrait(currentlySetTrait);
|
||||
}
|
||||
this.processResolvedTraitChange(type,instance.resolvedTrait);
|
||||
instance.addEventListener(Event.CHANGE,this.onTraitResolverChange);
|
||||
return;
|
||||
}
|
||||
throw new ArgumentError(OSMFStrings.getString(OSMFStrings.TRAIT_RESOLVER_ALREADY_ADDED));
|
||||
}
|
||||
|
||||
final protected function removeTraitResolver(type:String) : MediaTraitResolver
|
||||
{
|
||||
if(type == null || this.traitResolvers[type] == null)
|
||||
{
|
||||
throw new ArgumentError(OSMFStrings.getString(OSMFStrings.INVALID_PARAM));
|
||||
}
|
||||
var instance:MediaTraitResolver = this.traitResolvers[type];
|
||||
instance.removeEventListener(Event.CHANGE,this.onTraitResolverChange);
|
||||
delete this.traitResolvers[type];
|
||||
var unresolvedTrait:MediaTraitBase = this.unresolvedTraits[type];
|
||||
if(unresolvedTrait != this.traits[type])
|
||||
{
|
||||
this.setLocalTrait(type,unresolvedTrait);
|
||||
}
|
||||
delete this.unresolvedTraits[type];
|
||||
return instance;
|
||||
}
|
||||
|
||||
final protected function getTraitResolver(type:String) : MediaTraitResolver
|
||||
{
|
||||
return this.traitResolvers[type];
|
||||
}
|
||||
|
||||
protected function setupTraitResolvers() : void
|
||||
{
|
||||
}
|
||||
|
||||
protected function setupTraits() : void
|
||||
{
|
||||
}
|
||||
|
||||
private function onMediaError(event:MediaErrorEvent) : void
|
||||
{
|
||||
dispatchEvent(event.clone());
|
||||
}
|
||||
|
||||
private function setLocalTrait(type:String, instance:MediaTraitBase) : MediaTraitBase
|
||||
{
|
||||
var result:MediaTraitBase = this.traits[type];
|
||||
if(instance == null)
|
||||
{
|
||||
if(result != null)
|
||||
{
|
||||
result.removeEventListener(MediaErrorEvent.MEDIA_ERROR,this.onMediaError);
|
||||
result.dispose();
|
||||
dispatchEvent(new MediaElementEvent(MediaElementEvent.TRAIT_REMOVE,false,false,type));
|
||||
this._traitTypes.splice(this._traitTypes.indexOf(type),1);
|
||||
delete this.traits[type];
|
||||
}
|
||||
}
|
||||
else if(result == null)
|
||||
{
|
||||
this.traits[type] = result = instance;
|
||||
this._traitTypes.push(type);
|
||||
result.addEventListener(MediaErrorEvent.MEDIA_ERROR,this.onMediaError);
|
||||
dispatchEvent(new MediaElementEvent(MediaElementEvent.TRAIT_ADD,false,false,type));
|
||||
}
|
||||
else if(result != instance)
|
||||
{
|
||||
throw new ArgumentError(OSMFStrings.getString(OSMFStrings.TRAIT_INSTANCE_ALREADY_ADDED));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private function onTraitResolverChange(event:Event) : void
|
||||
{
|
||||
var resolver:MediaTraitResolver = event.target as MediaTraitResolver;
|
||||
this.processResolvedTraitChange(resolver.type,resolver.resolvedTrait);
|
||||
}
|
||||
|
||||
private function processResolvedTraitChange(type:String, resolvedTrait:MediaTraitBase) : void
|
||||
{
|
||||
if(resolvedTrait != this.traits[type])
|
||||
{
|
||||
this.setLocalTrait(type,resolvedTrait);
|
||||
}
|
||||
}
|
||||
|
||||
private function onContainerChange(event:ContainerChangeEvent) : void
|
||||
{
|
||||
if(this._container == event.oldContainer && this._container != event.newContainer)
|
||||
{
|
||||
this._container = event.newContainer;
|
||||
}
|
||||
}
|
||||
|
||||
private function onMetadataValueAdd(event:MetadataEvent) : void
|
||||
{
|
||||
dispatchEvent(new MediaElementEvent(MediaElementEvent.METADATA_ADD,false,false,null,event.key,event.value as Metadata));
|
||||
}
|
||||
|
||||
private function onMetadataValueChange(event:MetadataEvent) : void
|
||||
{
|
||||
dispatchEvent(new MediaElementEvent(MediaElementEvent.METADATA_REMOVE,false,false,null,event.key,event.oldValue as Metadata));
|
||||
dispatchEvent(new MediaElementEvent(MediaElementEvent.METADATA_ADD,false,false,null,event.key,event.value as Metadata));
|
||||
}
|
||||
|
||||
private function onMetadataValueRemove(event:MetadataEvent) : void
|
||||
{
|
||||
dispatchEvent(new MediaElementEvent(MediaElementEvent.METADATA_REMOVE,false,false,null,event.key,event.value as Metadata));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,278 @@
|
||||
package org.osmf.media
|
||||
{
|
||||
import flash.events.EventDispatcher;
|
||||
import flash.utils.Dictionary;
|
||||
import org.osmf.elements.ProxyElement;
|
||||
import org.osmf.events.MediaFactoryEvent;
|
||||
import org.osmf.events.PluginManagerEvent;
|
||||
import org.osmf.media.pluginClasses.PluginManager;
|
||||
import org.osmf.utils.OSMFStrings;
|
||||
|
||||
[Event(name="mediaElementCreate",type="org.osmf.events.MediaFactoryEvent")]
|
||||
[Event(name="pluginLoadError",type="org.osmf.events.MediaFactoryEvent")]
|
||||
[Event(name="pluginLoad",type="org.osmf.events.MediaFactoryEvent")]
|
||||
public class MediaFactory extends EventDispatcher
|
||||
{
|
||||
|
||||
private var pluginManager:PluginManager;
|
||||
|
||||
private var allItems:Dictionary;
|
||||
|
||||
public function MediaFactory()
|
||||
{
|
||||
super();
|
||||
this.allItems = new Dictionary();
|
||||
}
|
||||
|
||||
private static function getItemsByResource(resource:MediaResourceBase, items:Vector.<MediaFactoryItem>) : Vector.<MediaFactoryItem>
|
||||
{
|
||||
var item:MediaFactoryItem = null;
|
||||
var results:Vector.<MediaFactoryItem> = new Vector.<MediaFactoryItem>();
|
||||
for each(item in items)
|
||||
{
|
||||
if(Boolean(item.canHandleResourceFunction(resource)))
|
||||
{
|
||||
results.push(item);
|
||||
}
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
private static function getIndexOfItem(id:String, items:Vector.<MediaFactoryItem>) : int
|
||||
{
|
||||
var item:MediaFactoryItem = null;
|
||||
for(var i:int = 0; i < items.length; i++)
|
||||
{
|
||||
item = items[i] as MediaFactoryItem;
|
||||
if(item.id == id)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public function addItem(item:MediaFactoryItem) : void
|
||||
{
|
||||
if(item == null || item.id == null)
|
||||
{
|
||||
throw new ArgumentError(OSMFStrings.getString(OSMFStrings.INVALID_PARAM));
|
||||
}
|
||||
var items:Vector.<MediaFactoryItem> = this.findOrCreateItems(item.type);
|
||||
var existingIndex:int = getIndexOfItem(item.id,items);
|
||||
if(existingIndex != -1)
|
||||
{
|
||||
items[existingIndex] = item;
|
||||
}
|
||||
else
|
||||
{
|
||||
items.push(item);
|
||||
}
|
||||
}
|
||||
|
||||
public function removeItem(item:MediaFactoryItem) : void
|
||||
{
|
||||
var existingIndex:int = 0;
|
||||
if(item == null || item.id == null)
|
||||
{
|
||||
throw new ArgumentError(OSMFStrings.getString(OSMFStrings.INVALID_PARAM));
|
||||
}
|
||||
var items:Vector.<MediaFactoryItem> = this.allItems[item.type];
|
||||
if(items != null)
|
||||
{
|
||||
existingIndex = items.indexOf(item);
|
||||
if(existingIndex != -1)
|
||||
{
|
||||
items.splice(existingIndex,1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function get numItems() : int
|
||||
{
|
||||
var type:String = null;
|
||||
var items:Vector.<MediaFactoryItem> = null;
|
||||
var numItems:int = 0;
|
||||
for each(type in MediaFactoryItemType.ALL_TYPES)
|
||||
{
|
||||
items = this.allItems[type];
|
||||
if(items != null)
|
||||
{
|
||||
numItems += items.length;
|
||||
}
|
||||
}
|
||||
return numItems;
|
||||
}
|
||||
|
||||
public function getItemAt(index:int) : MediaFactoryItem
|
||||
{
|
||||
var type:String = null;
|
||||
var items:Vector.<MediaFactoryItem> = null;
|
||||
var result:MediaFactoryItem = null;
|
||||
if(index >= 0)
|
||||
{
|
||||
for each(type in MediaFactoryItemType.ALL_TYPES)
|
||||
{
|
||||
items = this.allItems[type];
|
||||
if(items != null)
|
||||
{
|
||||
if(index < items.length)
|
||||
{
|
||||
result = items[index];
|
||||
break;
|
||||
}
|
||||
index -= items.length;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public function getItemById(id:String) : MediaFactoryItem
|
||||
{
|
||||
var type:String = null;
|
||||
var items:Vector.<MediaFactoryItem> = null;
|
||||
var existingIndex:int = 0;
|
||||
var result:MediaFactoryItem = null;
|
||||
for each(type in MediaFactoryItemType.ALL_TYPES)
|
||||
{
|
||||
items = this.allItems[type];
|
||||
if(items != null)
|
||||
{
|
||||
existingIndex = getIndexOfItem(id,items);
|
||||
if(existingIndex != -1)
|
||||
{
|
||||
result = items[existingIndex];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public function loadPlugin(resource:MediaResourceBase) : void
|
||||
{
|
||||
this.createPluginManager();
|
||||
this.pluginManager.loadPlugin(resource);
|
||||
}
|
||||
|
||||
public function createMediaElement(resource:MediaResourceBase) : MediaElement
|
||||
{
|
||||
var proxyElement:MediaElement = null;
|
||||
this.createPluginManager();
|
||||
var mediaElement:MediaElement = this.createMediaElementByResource(resource,MediaFactoryItemType.STANDARD);
|
||||
if(mediaElement != null)
|
||||
{
|
||||
proxyElement = this.createMediaElementByResource(mediaElement.resource,MediaFactoryItemType.PROXY,mediaElement);
|
||||
mediaElement = proxyElement != null ? proxyElement : mediaElement;
|
||||
dispatchEvent(new MediaFactoryEvent(MediaFactoryEvent.MEDIA_ELEMENT_CREATE,false,false,null,mediaElement));
|
||||
}
|
||||
return mediaElement;
|
||||
}
|
||||
|
||||
protected function resolveItems(resource:MediaResourceBase, items:Vector.<MediaFactoryItem>) : MediaFactoryItem
|
||||
{
|
||||
var item:MediaFactoryItem = null;
|
||||
if(resource == null || items == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var firstNativeItem:MediaFactoryItem = null;
|
||||
for(var i:int = 0; i < items.length; i++)
|
||||
{
|
||||
item = items[i] as MediaFactoryItem;
|
||||
if(item.id.indexOf("org.osmf") == -1)
|
||||
{
|
||||
return item;
|
||||
}
|
||||
if(firstNativeItem == null)
|
||||
{
|
||||
firstNativeItem = item;
|
||||
}
|
||||
}
|
||||
return firstNativeItem;
|
||||
}
|
||||
|
||||
private function findOrCreateItems(type:String) : Vector.<MediaFactoryItem>
|
||||
{
|
||||
if(this.allItems[type] == null)
|
||||
{
|
||||
this.allItems[type] = new Vector.<MediaFactoryItem>();
|
||||
}
|
||||
return this.allItems[type] as Vector.<MediaFactoryItem>;
|
||||
}
|
||||
|
||||
private function createMediaElementByResource(resource:MediaResourceBase, itemType:String, wrappedElement:MediaElement = null) : MediaElement
|
||||
{
|
||||
var item:MediaFactoryItem = null;
|
||||
var nextElementToWrap:MediaElement = null;
|
||||
var i:int = 0;
|
||||
var proxyItem:MediaFactoryItem = null;
|
||||
var proxyElement:ProxyElement = null;
|
||||
var mediaElement:MediaElement = null;
|
||||
var items:Vector.<MediaFactoryItem> = getItemsByResource(resource,this.allItems[itemType]);
|
||||
if(itemType == MediaFactoryItemType.STANDARD)
|
||||
{
|
||||
item = this.resolveItems(resource,items) as MediaFactoryItem;
|
||||
if(item != null)
|
||||
{
|
||||
mediaElement = this.invokeMediaElementCreationFunction(item);
|
||||
}
|
||||
}
|
||||
else if(itemType == MediaFactoryItemType.PROXY)
|
||||
{
|
||||
nextElementToWrap = wrappedElement;
|
||||
for(i = int(items.length); i > 0; i--)
|
||||
{
|
||||
proxyItem = items[i - 1] as MediaFactoryItem;
|
||||
proxyElement = this.invokeMediaElementCreationFunction(proxyItem) as ProxyElement;
|
||||
if(proxyElement != null)
|
||||
{
|
||||
proxyElement.proxiedElement = nextElementToWrap;
|
||||
nextElementToWrap = proxyElement;
|
||||
}
|
||||
}
|
||||
mediaElement = nextElementToWrap;
|
||||
}
|
||||
if(mediaElement != null)
|
||||
{
|
||||
mediaElement.resource = resource;
|
||||
}
|
||||
return mediaElement;
|
||||
}
|
||||
|
||||
private function onPluginLoad(event:PluginManagerEvent) : void
|
||||
{
|
||||
dispatchEvent(new MediaFactoryEvent(MediaFactoryEvent.PLUGIN_LOAD,false,false,event.resource));
|
||||
}
|
||||
|
||||
private function onPluginLoadError(event:PluginManagerEvent) : void
|
||||
{
|
||||
dispatchEvent(new MediaFactoryEvent(MediaFactoryEvent.PLUGIN_LOAD_ERROR,false,false,event.resource));
|
||||
}
|
||||
|
||||
private function invokeMediaElementCreationFunction(item:MediaFactoryItem) : MediaElement
|
||||
{
|
||||
var mediaElement:MediaElement = null;
|
||||
try
|
||||
{
|
||||
mediaElement = item.mediaElementCreationFunction();
|
||||
}
|
||||
catch(error:Error)
|
||||
{
|
||||
}
|
||||
return mediaElement;
|
||||
}
|
||||
|
||||
private function createPluginManager() : void
|
||||
{
|
||||
if(this.pluginManager == null)
|
||||
{
|
||||
this.pluginManager = new PluginManager(this);
|
||||
this.pluginManager.addEventListener(PluginManagerEvent.PLUGIN_LOAD,this.onPluginLoad);
|
||||
this.pluginManager.addEventListener(PluginManagerEvent.PLUGIN_LOAD_ERROR,this.onPluginLoadError);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
package org.osmf.media
|
||||
{
|
||||
import org.osmf.utils.OSMFStrings;
|
||||
|
||||
public class MediaFactoryItem
|
||||
{
|
||||
|
||||
private var _id:String;
|
||||
|
||||
private var _canHandleResourceFunction:Function;
|
||||
|
||||
private var _mediaElementCreationFunction:Function;
|
||||
|
||||
private var _type:String;
|
||||
|
||||
public function MediaFactoryItem(id:String, canHandleResourceFunction:Function, mediaElementCreationFunction:Function, type:String = null)
|
||||
{
|
||||
super();
|
||||
if(id == null || canHandleResourceFunction == null || mediaElementCreationFunction == null)
|
||||
{
|
||||
throw new ArgumentError(OSMFStrings.getString(OSMFStrings.INVALID_PARAM));
|
||||
}
|
||||
type ||= MediaFactoryItemType.STANDARD;
|
||||
this._id = id;
|
||||
this._canHandleResourceFunction = canHandleResourceFunction;
|
||||
this._mediaElementCreationFunction = mediaElementCreationFunction;
|
||||
this._type = type;
|
||||
}
|
||||
|
||||
public function get id() : String
|
||||
{
|
||||
return this._id;
|
||||
}
|
||||
|
||||
public function get canHandleResourceFunction() : Function
|
||||
{
|
||||
return this._canHandleResourceFunction;
|
||||
}
|
||||
|
||||
public function get mediaElementCreationFunction() : Function
|
||||
{
|
||||
return this._mediaElementCreationFunction;
|
||||
}
|
||||
|
||||
public function get type() : String
|
||||
{
|
||||
return this._type;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package org.osmf.media
|
||||
{
|
||||
public class MediaFactoryItemType
|
||||
{
|
||||
|
||||
public static const STANDARD:String = "standard";
|
||||
|
||||
public static const PROXY:String = "proxy";
|
||||
|
||||
internal static const ALL_TYPES:Array = [STANDARD,PROXY];
|
||||
|
||||
public function MediaFactoryItemType()
|
||||
{
|
||||
super();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,26 @@
|
||||
package org.osmf.media
|
||||
{
|
||||
public final class MediaPlayerState
|
||||
{
|
||||
|
||||
public static const UNINITIALIZED:String = "uninitialized";
|
||||
|
||||
public static const LOADING:String = "loading";
|
||||
|
||||
public static const READY:String = "ready";
|
||||
|
||||
public static const PLAYING:String = "playing";
|
||||
|
||||
public static const PAUSED:String = "paused";
|
||||
|
||||
public static const BUFFERING:String = "buffering";
|
||||
|
||||
public static const PLAYBACK_ERROR:String = "playbackError";
|
||||
|
||||
public function MediaPlayerState()
|
||||
{
|
||||
super();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
package org.osmf.media
|
||||
{
|
||||
import flash.utils.Dictionary;
|
||||
|
||||
public class MediaResourceBase
|
||||
{
|
||||
|
||||
private var _metadata:Dictionary;
|
||||
|
||||
private var _mediaType:String;
|
||||
|
||||
private var _mimeType:String;
|
||||
|
||||
public function MediaResourceBase()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public function get mediaType() : String
|
||||
{
|
||||
return this._mediaType;
|
||||
}
|
||||
|
||||
public function set mediaType(value:String) : void
|
||||
{
|
||||
this._mediaType = value;
|
||||
}
|
||||
|
||||
public function get mimeType() : String
|
||||
{
|
||||
return this._mimeType;
|
||||
}
|
||||
|
||||
public function set mimeType(value:String) : void
|
||||
{
|
||||
this._mimeType = value;
|
||||
}
|
||||
|
||||
public function get metadataNamespaceURLs() : Vector.<String>
|
||||
{
|
||||
var key:String = null;
|
||||
var allKeys:Vector.<String> = new Vector.<String>();
|
||||
if(this._metadata != null)
|
||||
{
|
||||
for(key in this._metadata)
|
||||
{
|
||||
allKeys.push(key);
|
||||
}
|
||||
}
|
||||
return allKeys;
|
||||
}
|
||||
|
||||
public function addMetadataValue(namespaceURL:String, value:Object) : void
|
||||
{
|
||||
if(this._metadata == null)
|
||||
{
|
||||
this._metadata = new Dictionary();
|
||||
}
|
||||
this._metadata[namespaceURL] = value;
|
||||
}
|
||||
|
||||
public function getMetadataValue(namespaceURL:String) : Object
|
||||
{
|
||||
if(this._metadata != null)
|
||||
{
|
||||
return this._metadata[namespaceURL];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function removeMetadataValue(namespaceURL:String) : Object
|
||||
{
|
||||
var value:Object = null;
|
||||
if(this._metadata != null)
|
||||
{
|
||||
value = this._metadata[namespaceURL];
|
||||
delete this._metadata[namespaceURL];
|
||||
return value;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
package org.osmf.media
|
||||
{
|
||||
import flash.events.Event;
|
||||
import flash.events.EventDispatcher;
|
||||
import org.osmf.traits.MediaTraitBase;
|
||||
import org.osmf.utils.OSMFStrings;
|
||||
|
||||
[Event(name="change",type="flash.events.Event")]
|
||||
[ExcludeClass]
|
||||
internal class MediaTraitResolver extends EventDispatcher
|
||||
{
|
||||
|
||||
private var _type:String;
|
||||
|
||||
private var _resolvedTrait:MediaTraitBase;
|
||||
|
||||
public function MediaTraitResolver(type:String)
|
||||
{
|
||||
super();
|
||||
if(type == null)
|
||||
{
|
||||
throw new ArgumentError(OSMFStrings.getString(OSMFStrings.NULL_PARAM));
|
||||
}
|
||||
this._type = type;
|
||||
}
|
||||
|
||||
final public function get type() : String
|
||||
{
|
||||
return this._type;
|
||||
}
|
||||
|
||||
final protected function setResolvedTrait(value:MediaTraitBase) : void
|
||||
{
|
||||
if(value != this._resolvedTrait)
|
||||
{
|
||||
if(Boolean(this._resolvedTrait))
|
||||
{
|
||||
this._resolvedTrait = null;
|
||||
dispatchEvent(new Event(Event.CHANGE));
|
||||
}
|
||||
this._resolvedTrait = value;
|
||||
dispatchEvent(new Event(Event.CHANGE));
|
||||
}
|
||||
}
|
||||
|
||||
final public function get resolvedTrait() : MediaTraitBase
|
||||
{
|
||||
return this._resolvedTrait;
|
||||
}
|
||||
|
||||
final public function addTrait(instance:MediaTraitBase) : void
|
||||
{
|
||||
if(instance == null)
|
||||
{
|
||||
throw new ArgumentError(OSMFStrings.getString(OSMFStrings.NULL_PARAM));
|
||||
}
|
||||
if(instance.traitType != this.type)
|
||||
{
|
||||
throw new ArgumentError(OSMFStrings.getString(OSMFStrings.INVALID_PARAM));
|
||||
}
|
||||
this.processAddTrait(instance);
|
||||
}
|
||||
|
||||
final public function removeTrait(instance:MediaTraitBase) : MediaTraitBase
|
||||
{
|
||||
if(instance == null)
|
||||
{
|
||||
throw new ArgumentError(OSMFStrings.getString(OSMFStrings.NULL_PARAM));
|
||||
}
|
||||
if(instance.traitType != this.type)
|
||||
{
|
||||
throw new ArgumentError(OSMFStrings.getString(OSMFStrings.INVALID_PARAM));
|
||||
}
|
||||
return this.processRemoveTrait(instance);
|
||||
}
|
||||
|
||||
protected function processAddTrait(instance:MediaTraitBase) : void
|
||||
{
|
||||
}
|
||||
|
||||
protected function processRemoveTrait(instance:MediaTraitBase) : MediaTraitBase
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loaded 100 of 7925 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user