mirror of
https://github.com/burrow-dev/burrow-server.git
synced 2026-11-21 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,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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package org.osmf.media
|
||||
{
|
||||
public final class MediaType
|
||||
{
|
||||
|
||||
public static const VIDEO:String = "video";
|
||||
|
||||
public static const AUDIO:String = "audio";
|
||||
|
||||
public static const IMAGE:String = "image";
|
||||
|
||||
public static const SWF:String = "swf";
|
||||
|
||||
public function MediaType()
|
||||
{
|
||||
super();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
package org.osmf.media
|
||||
{
|
||||
[ExcludeClass]
|
||||
public class MediaTypeUtil
|
||||
{
|
||||
|
||||
public static const METADATA_MATCH_FOUND:int = 0;
|
||||
|
||||
public static const METADATA_CONFLICTS_FOUND:int = 1;
|
||||
|
||||
public static const METADATA_MATCH_UNKNOWN:int = 2;
|
||||
|
||||
public function MediaTypeUtil()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public static function checkMetadataMatchWithResource(resource:MediaResourceBase, mediaTypesSupported:Vector.<String>, mimeTypesSupported:Vector.<String>) : int
|
||||
{
|
||||
var mediaType:String = Boolean(resource) ? resource.mediaType : null;
|
||||
var mimeType:String = Boolean(resource) ? resource.mimeType : null;
|
||||
return checkMetadataMatch(mediaType,mimeType,mediaTypesSupported,mimeTypesSupported);
|
||||
}
|
||||
|
||||
public static function checkMetadataMatch(mediaType:String, mimeType:String, mediaTypesSupported:Vector.<String>, mimeTypesSupported:Vector.<String>) : int
|
||||
{
|
||||
if(mediaType != null)
|
||||
{
|
||||
if(mimeType != null)
|
||||
{
|
||||
return matchType(mediaType,mediaTypesSupported) && matchType(mimeType,mimeTypesSupported) ? METADATA_MATCH_FOUND : METADATA_CONFLICTS_FOUND;
|
||||
}
|
||||
return matchType(mediaType,mediaTypesSupported) ? METADATA_MATCH_FOUND : METADATA_CONFLICTS_FOUND;
|
||||
}
|
||||
if(mimeType != null)
|
||||
{
|
||||
return matchType(mimeType,mimeTypesSupported) ? METADATA_MATCH_FOUND : METADATA_CONFLICTS_FOUND;
|
||||
}
|
||||
return METADATA_MATCH_UNKNOWN;
|
||||
}
|
||||
|
||||
private static function matchType(type:String, typesSupported:Vector.<String>) : Boolean
|
||||
{
|
||||
for(var i:int = 0; i < typesSupported.length; i++)
|
||||
{
|
||||
if(type == typesSupported[i])
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
package org.osmf.media
|
||||
{
|
||||
import org.osmf.media.pluginClasses.VersionUtils;
|
||||
import org.osmf.utils.OSMFStrings;
|
||||
import org.osmf.utils.Version;
|
||||
|
||||
public class PluginInfo
|
||||
{
|
||||
|
||||
public static const PLUGIN_MEDIAFACTORY_NAMESPACE:String = "http://www.osmf.org/plugin/mediaFactory/1.0";
|
||||
|
||||
private var _mediaFactoryItems:Vector.<MediaFactoryItem>;
|
||||
|
||||
private var _mediaElementCreationNotificationFunction:Function;
|
||||
|
||||
public function PluginInfo(mediaFactoryItems:Vector.<MediaFactoryItem> = null, mediaElementCreationNotificationFunction:Function = null)
|
||||
{
|
||||
super();
|
||||
this._mediaFactoryItems = mediaFactoryItems != null ? mediaFactoryItems : new Vector.<MediaFactoryItem>();
|
||||
this._mediaElementCreationNotificationFunction = mediaElementCreationNotificationFunction;
|
||||
}
|
||||
|
||||
public function get numMediaFactoryItems() : int
|
||||
{
|
||||
return this._mediaFactoryItems.length;
|
||||
}
|
||||
|
||||
public function get frameworkVersion() : String
|
||||
{
|
||||
return Version.version;
|
||||
}
|
||||
|
||||
public function getMediaFactoryItemAt(index:int) : MediaFactoryItem
|
||||
{
|
||||
if(index < 0 || index >= this._mediaFactoryItems.length)
|
||||
{
|
||||
throw new RangeError(OSMFStrings.getString(OSMFStrings.INVALID_PARAM));
|
||||
}
|
||||
return this._mediaFactoryItems[index] as MediaFactoryItem;
|
||||
}
|
||||
|
||||
public function isFrameworkVersionSupported(version:String) : Boolean
|
||||
{
|
||||
if(version == null || version.length == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var playerFrameworkVersion:Object = VersionUtils.parseVersionString(version);
|
||||
var pluginFrameworkVersion:Object = VersionUtils.parseVersionString(this.frameworkVersion);
|
||||
return playerFrameworkVersion.major > pluginFrameworkVersion.major || playerFrameworkVersion.major == pluginFrameworkVersion.major && playerFrameworkVersion.minor >= pluginFrameworkVersion.minor;
|
||||
}
|
||||
|
||||
public function initializePlugin(resource:MediaResourceBase) : void
|
||||
{
|
||||
}
|
||||
|
||||
public function get mediaElementCreationNotificationFunction() : Function
|
||||
{
|
||||
return this._mediaElementCreationNotificationFunction;
|
||||
}
|
||||
|
||||
final protected function get mediaFactoryItems() : Vector.<MediaFactoryItem>
|
||||
{
|
||||
return this._mediaFactoryItems;
|
||||
}
|
||||
|
||||
final protected function set mediaFactoryItems(value:Vector.<MediaFactoryItem>) : void
|
||||
{
|
||||
this._mediaFactoryItems = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package org.osmf.media
|
||||
{
|
||||
public class PluginInfoResource extends MediaResourceBase
|
||||
{
|
||||
|
||||
private var _pluginInfo:PluginInfo;
|
||||
|
||||
public function PluginInfoResource(pluginInfo:PluginInfo)
|
||||
{
|
||||
super();
|
||||
this._pluginInfo = pluginInfo;
|
||||
}
|
||||
|
||||
public function get pluginInfo() : PluginInfo
|
||||
{
|
||||
return this._pluginInfo;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package org.osmf.media
|
||||
{
|
||||
public class URLResource extends MediaResourceBase
|
||||
{
|
||||
|
||||
private var _url:String;
|
||||
|
||||
public function URLResource(url:String)
|
||||
{
|
||||
super();
|
||||
this._url = url;
|
||||
}
|
||||
|
||||
public function get url() : String
|
||||
{
|
||||
return this._url;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
package org.osmf.media.pluginClasses
|
||||
{
|
||||
import flash.display.DisplayObject;
|
||||
import org.osmf.elements.SWFLoader;
|
||||
import org.osmf.elements.loaderClasses.LoaderLoadTrait;
|
||||
import org.osmf.events.LoaderEvent;
|
||||
import org.osmf.events.MediaErrorEvent;
|
||||
import org.osmf.media.MediaFactory;
|
||||
import org.osmf.media.MediaResourceBase;
|
||||
import org.osmf.media.PluginInfo;
|
||||
import org.osmf.traits.LoadState;
|
||||
import org.osmf.traits.LoadTrait;
|
||||
|
||||
internal class DynamicPluginLoader extends PluginLoader
|
||||
{
|
||||
|
||||
private static const PLUGININFO_PROPERTY_NAME:String = "pluginInfo";
|
||||
|
||||
public function DynamicPluginLoader(mediaFactory:MediaFactory, minimumSupportedFrameworkVersion:String)
|
||||
{
|
||||
super(mediaFactory,minimumSupportedFrameworkVersion);
|
||||
}
|
||||
|
||||
override public function canHandleResource(resource:MediaResourceBase) : Boolean
|
||||
{
|
||||
return new SWFLoader().canHandleResource(resource);
|
||||
}
|
||||
|
||||
override protected function executeLoad(loadTrait:LoadTrait) : void
|
||||
{
|
||||
var swfLoader:SWFLoader = null;
|
||||
var loaderLoadTrait:LoaderLoadTrait = null;
|
||||
var onSWFLoaderStateChange:Function = null;
|
||||
var onLoadError:Function = null;
|
||||
onSWFLoaderStateChange = function(event:LoaderEvent):void
|
||||
{
|
||||
var root:DisplayObject = null;
|
||||
var pluginInfo:PluginInfo = null;
|
||||
if(event.newState == LoadState.READY)
|
||||
{
|
||||
swfLoader.removeEventListener(LoaderEvent.LOAD_STATE_CHANGE,onSWFLoaderStateChange);
|
||||
loaderLoadTrait.removeEventListener(MediaErrorEvent.MEDIA_ERROR,onLoadError);
|
||||
root = loaderLoadTrait.loader.content;
|
||||
pluginInfo = root[PLUGININFO_PROPERTY_NAME] as PluginInfo;
|
||||
loadFromPluginInfo(loadTrait,pluginInfo,loaderLoadTrait.loader);
|
||||
}
|
||||
else if(event.newState == LoadState.LOAD_ERROR)
|
||||
{
|
||||
swfLoader.removeEventListener(LoaderEvent.LOAD_STATE_CHANGE,onSWFLoaderStateChange);
|
||||
updateLoadTrait(loadTrait,event.newState);
|
||||
}
|
||||
};
|
||||
onLoadError = function(event:MediaErrorEvent):void
|
||||
{
|
||||
loaderLoadTrait.removeEventListener(MediaErrorEvent.MEDIA_ERROR,onLoadError);
|
||||
loadTrait.dispatchEvent(event.clone());
|
||||
};
|
||||
updateLoadTrait(loadTrait,LoadState.LOADING);
|
||||
swfLoader = new SWFLoader(true);
|
||||
swfLoader.validateLoadedContentFunction = this.validateLoadedContent;
|
||||
swfLoader.addEventListener(LoaderEvent.LOAD_STATE_CHANGE,onSWFLoaderStateChange);
|
||||
loaderLoadTrait = new LoaderLoadTrait(swfLoader,loadTrait.resource);
|
||||
loaderLoadTrait.addEventListener(MediaErrorEvent.MEDIA_ERROR,onLoadError);
|
||||
swfLoader.load(loaderLoadTrait);
|
||||
}
|
||||
|
||||
override protected function executeUnload(loadTrait:LoadTrait) : void
|
||||
{
|
||||
updateLoadTrait(loadTrait,LoadState.UNLOADING);
|
||||
var pluginLoadTrait:PluginLoadTrait = loadTrait as PluginLoadTrait;
|
||||
unloadFromPluginInfo(pluginLoadTrait.pluginInfo);
|
||||
pluginLoadTrait.loader.unloadAndStop();
|
||||
updateLoadTrait(loadTrait,LoadState.UNINITIALIZED);
|
||||
}
|
||||
|
||||
private function validateLoadedContent(displayObject:DisplayObject) : Boolean
|
||||
{
|
||||
var pluginInfo:Object = displayObject.hasOwnProperty(PLUGININFO_PROPERTY_NAME) ? displayObject[PLUGININFO_PROPERTY_NAME] : null;
|
||||
return pluginInfo != null ? isPluginCompatible(pluginInfo) : false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package org.osmf.media.pluginClasses
|
||||
{
|
||||
import org.osmf.media.LoadableElementBase;
|
||||
import org.osmf.media.MediaResourceBase;
|
||||
import org.osmf.traits.LoadTrait;
|
||||
import org.osmf.traits.LoaderBase;
|
||||
|
||||
internal class PluginElement extends LoadableElementBase
|
||||
{
|
||||
|
||||
public function PluginElement(loader:PluginLoader, resource:MediaResourceBase = null)
|
||||
{
|
||||
super(resource,loader);
|
||||
}
|
||||
|
||||
override protected function createLoadTrait(resource:MediaResourceBase, loader:LoaderBase) : LoadTrait
|
||||
{
|
||||
return new PluginLoadTrait(loader,resource);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package org.osmf.media.pluginClasses
|
||||
{
|
||||
import org.osmf.media.MediaElement;
|
||||
|
||||
internal class PluginEntry
|
||||
{
|
||||
|
||||
private var _pluginElement:MediaElement;
|
||||
|
||||
private var _state:PluginLoadingState;
|
||||
|
||||
public function PluginEntry(pluginElement:MediaElement, state:PluginLoadingState)
|
||||
{
|
||||
super();
|
||||
this._pluginElement = pluginElement;
|
||||
this._state = state;
|
||||
}
|
||||
|
||||
public function get pluginElement() : MediaElement
|
||||
{
|
||||
return this._pluginElement;
|
||||
}
|
||||
|
||||
public function get state() : PluginLoadingState
|
||||
{
|
||||
return this._state;
|
||||
}
|
||||
|
||||
public function set state(value:PluginLoadingState) : void
|
||||
{
|
||||
this._state = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
package org.osmf.media.pluginClasses
|
||||
{
|
||||
import flash.display.Loader;
|
||||
import org.osmf.media.MediaResourceBase;
|
||||
import org.osmf.media.PluginInfo;
|
||||
import org.osmf.traits.LoadTrait;
|
||||
import org.osmf.traits.LoaderBase;
|
||||
|
||||
[ExcludeClass]
|
||||
internal class PluginLoadTrait extends LoadTrait
|
||||
{
|
||||
|
||||
private var _pluginInfo:PluginInfo;
|
||||
|
||||
private var _loader:Loader;
|
||||
|
||||
public function PluginLoadTrait(loader:LoaderBase, resource:MediaResourceBase)
|
||||
{
|
||||
super(loader,resource);
|
||||
}
|
||||
|
||||
public function get pluginInfo() : PluginInfo
|
||||
{
|
||||
return this._pluginInfo;
|
||||
}
|
||||
|
||||
public function set pluginInfo(value:PluginInfo) : void
|
||||
{
|
||||
this._pluginInfo = value;
|
||||
}
|
||||
|
||||
public function get loader() : Loader
|
||||
{
|
||||
return this._loader;
|
||||
}
|
||||
|
||||
public function set loader(value:Loader) : void
|
||||
{
|
||||
this._loader = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,142 @@
|
||||
package org.osmf.media.pluginClasses
|
||||
{
|
||||
import flash.display.Loader;
|
||||
import org.osmf.events.MediaError;
|
||||
import org.osmf.events.MediaErrorCodes;
|
||||
import org.osmf.events.MediaErrorEvent;
|
||||
import org.osmf.media.MediaFactory;
|
||||
import org.osmf.media.MediaFactoryItem;
|
||||
import org.osmf.media.PluginInfo;
|
||||
import org.osmf.traits.LoadState;
|
||||
import org.osmf.traits.LoadTrait;
|
||||
import org.osmf.traits.LoaderBase;
|
||||
import org.osmf.utils.Version;
|
||||
|
||||
internal class PluginLoader extends LoaderBase
|
||||
{
|
||||
|
||||
private static const FRAMEWORK_VERSION_PROPERTY_NAME:String = "frameworkVersion";
|
||||
|
||||
private static const IS_FRAMEWORK_VERSION_SUPPORTED_PROPERTY_NAME:String = "isFrameworkVersionSupported";
|
||||
|
||||
private var minimumSupportedFrameworkVersion:String;
|
||||
|
||||
private var mediaFactory:MediaFactory;
|
||||
|
||||
public function PluginLoader(mediaFactory:MediaFactory, minimumSupportedFrameworkVersion:String)
|
||||
{
|
||||
super();
|
||||
this.mediaFactory = mediaFactory;
|
||||
this.minimumSupportedFrameworkVersion = minimumSupportedFrameworkVersion;
|
||||
}
|
||||
|
||||
protected function unloadFromPluginInfo(pluginInfo:PluginInfo) : void
|
||||
{
|
||||
var i:int = 0;
|
||||
var item:MediaFactoryItem = null;
|
||||
var actualItem:MediaFactoryItem = null;
|
||||
if(pluginInfo != null)
|
||||
{
|
||||
for(i = 0; i < pluginInfo.numMediaFactoryItems; i++)
|
||||
{
|
||||
item = pluginInfo.getMediaFactoryItemAt(i);
|
||||
actualItem = this.mediaFactory.getItemById(item.id);
|
||||
if(actualItem != null)
|
||||
{
|
||||
this.mediaFactory.removeItem(actualItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function loadFromPluginInfo(loadTrait:LoadTrait, pluginInfo:PluginInfo, loader:Loader = null) : void
|
||||
{
|
||||
var passedMediaFactory:MediaFactory = null;
|
||||
var i:int = 0;
|
||||
var pluginLoadTrait:PluginLoadTrait = null;
|
||||
var item:MediaFactoryItem = null;
|
||||
var invalidImplementation:Boolean = false;
|
||||
if(pluginInfo != null)
|
||||
{
|
||||
if(this.isPluginCompatible(pluginInfo))
|
||||
{
|
||||
try
|
||||
{
|
||||
passedMediaFactory = loadTrait.resource.getMetadataValue(PluginInfo.PLUGIN_MEDIAFACTORY_NAMESPACE) as MediaFactory;
|
||||
if(passedMediaFactory == null)
|
||||
{
|
||||
loadTrait.resource.addMetadataValue(PluginInfo.PLUGIN_MEDIAFACTORY_NAMESPACE,this.mediaFactory);
|
||||
}
|
||||
pluginInfo.initializePlugin(loadTrait.resource);
|
||||
for(i = 0; i < pluginInfo.numMediaFactoryItems; i++)
|
||||
{
|
||||
item = pluginInfo.getMediaFactoryItemAt(i);
|
||||
if(item == null)
|
||||
{
|
||||
throw new RangeError();
|
||||
}
|
||||
this.mediaFactory.addItem(item);
|
||||
}
|
||||
pluginLoadTrait = loadTrait as PluginLoadTrait;
|
||||
pluginLoadTrait.pluginInfo = pluginInfo;
|
||||
pluginLoadTrait.loader = loader;
|
||||
updateLoadTrait(pluginLoadTrait,LoadState.READY);
|
||||
}
|
||||
catch(error:RangeError)
|
||||
{
|
||||
invalidImplementation = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
updateLoadTrait(loadTrait,LoadState.LOAD_ERROR);
|
||||
loadTrait.dispatchEvent(new MediaErrorEvent(MediaErrorEvent.MEDIA_ERROR,false,false,new MediaError(MediaErrorCodes.PLUGIN_VERSION_INVALID)));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
invalidImplementation = true;
|
||||
}
|
||||
if(invalidImplementation)
|
||||
{
|
||||
updateLoadTrait(loadTrait,LoadState.LOAD_ERROR);
|
||||
loadTrait.dispatchEvent(new MediaErrorEvent(MediaErrorEvent.MEDIA_ERROR,false,false,new MediaError(MediaErrorCodes.PLUGIN_IMPLEMENTATION_INVALID)));
|
||||
}
|
||||
}
|
||||
|
||||
protected function isPluginCompatible(pluginInfo:Object) : Boolean
|
||||
{
|
||||
var versionSupportedFunction:Function = null;
|
||||
var isCompatible:Boolean = false;
|
||||
var version:String = pluginInfo.hasOwnProperty(FRAMEWORK_VERSION_PROPERTY_NAME) ? pluginInfo[FRAMEWORK_VERSION_PROPERTY_NAME] : null;
|
||||
var isSupported:Boolean = this.isPluginVersionSupported(version);
|
||||
if(isSupported)
|
||||
{
|
||||
versionSupportedFunction = pluginInfo.hasOwnProperty(IS_FRAMEWORK_VERSION_SUPPORTED_PROPERTY_NAME) ? pluginInfo[IS_FRAMEWORK_VERSION_SUPPORTED_PROPERTY_NAME] as Function : null;
|
||||
if(versionSupportedFunction != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
isCompatible = versionSupportedFunction(Version.version);
|
||||
}
|
||||
catch(error:Error)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
return isCompatible;
|
||||
}
|
||||
|
||||
private function isPluginVersionSupported(pluginVersion:String) : Boolean
|
||||
{
|
||||
if(pluginVersion == null || pluginVersion.length == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var minVersion:Object = VersionUtils.parseVersionString(this.minimumSupportedFrameworkVersion);
|
||||
var pVersion:Object = VersionUtils.parseVersionString(pluginVersion);
|
||||
return pVersion.major > minVersion.major || pVersion.major == minVersion.major && pVersion.minor >= minVersion.minor;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
package org.osmf.media.pluginClasses
|
||||
{
|
||||
internal class PluginLoadingState
|
||||
{
|
||||
|
||||
public static const LOADING:PluginLoadingState = new PluginLoadingState("Loading");
|
||||
|
||||
public static const LOADED:PluginLoadingState = new PluginLoadingState("Loaded");
|
||||
|
||||
private var _state:String;
|
||||
|
||||
public function PluginLoadingState(state:String)
|
||||
{
|
||||
super();
|
||||
this._state = state;
|
||||
}
|
||||
|
||||
public function get state() : String
|
||||
{
|
||||
return this._state;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,213 @@
|
||||
package org.osmf.media.pluginClasses
|
||||
{
|
||||
import flash.events.EventDispatcher;
|
||||
import flash.utils.Dictionary;
|
||||
import org.osmf.events.LoadEvent;
|
||||
import org.osmf.events.MediaErrorEvent;
|
||||
import org.osmf.events.MediaFactoryEvent;
|
||||
import org.osmf.events.PluginManagerEvent;
|
||||
import org.osmf.media.MediaElement;
|
||||
import org.osmf.media.MediaFactory;
|
||||
import org.osmf.media.MediaFactoryItem;
|
||||
import org.osmf.media.MediaResourceBase;
|
||||
import org.osmf.media.PluginInfoResource;
|
||||
import org.osmf.media.URLResource;
|
||||
import org.osmf.traits.LoadState;
|
||||
import org.osmf.traits.LoadTrait;
|
||||
import org.osmf.traits.MediaTraitType;
|
||||
import org.osmf.utils.OSMFStrings;
|
||||
import org.osmf.utils.Version;
|
||||
|
||||
[Event(name="pluginLoadError",type="org.osmf.events.PluginManagerEvent")]
|
||||
[Event(name="pluginLoad",type="org.osmf.events.PluginManagerEvent")]
|
||||
[ExcludeClass]
|
||||
public class PluginManager extends EventDispatcher
|
||||
{
|
||||
|
||||
private static const STATIC_PLUGIN_MEDIA_INFO_ID:String = "org.osmf.plugins.StaticPluginLoader";
|
||||
|
||||
private static const DYNAMIC_PLUGIN_MEDIA_INFO_ID:String = "org.osmf.plugins.DynamicPluginLoader";
|
||||
|
||||
private var _mediaFactory:MediaFactory;
|
||||
|
||||
private var _pluginFactory:MediaFactory;
|
||||
|
||||
private var _pluginMap:Dictionary;
|
||||
|
||||
private var _pluginList:Vector.<PluginEntry>;
|
||||
|
||||
private var notificationFunctions:Vector.<Function>;
|
||||
|
||||
private var createdElements:Dictionary;
|
||||
|
||||
private var minimumSupportedFrameworkVersion:String;
|
||||
|
||||
private var staticPluginLoader:StaticPluginLoader;
|
||||
|
||||
private var dynamicPluginLoader:DynamicPluginLoader;
|
||||
|
||||
public function PluginManager(mediaFactory:MediaFactory)
|
||||
{
|
||||
super();
|
||||
this._mediaFactory = mediaFactory;
|
||||
this._mediaFactory.addEventListener(MediaFactoryEvent.MEDIA_ELEMENT_CREATE,this.onMediaElementCreate);
|
||||
this.minimumSupportedFrameworkVersion = Version.lastAPICompatibleVersion;
|
||||
this.initPluginFactory();
|
||||
this._pluginMap = new Dictionary();
|
||||
this._pluginList = new Vector.<PluginEntry>();
|
||||
}
|
||||
|
||||
public function loadPlugin(resource:MediaResourceBase) : void
|
||||
{
|
||||
var identifier:Object = null;
|
||||
var pluginEntry:PluginEntry = null;
|
||||
var onLoadStateChange:Function = null;
|
||||
var onMediaError:Function = null;
|
||||
var pluginElement:MediaElement = null;
|
||||
var loadTrait:LoadTrait = null;
|
||||
onLoadStateChange = function(event:LoadEvent):void
|
||||
{
|
||||
var pluginLoadTrait:PluginLoadTrait = null;
|
||||
if(event.loadState == LoadState.READY)
|
||||
{
|
||||
pluginEntry.state = PluginLoadingState.LOADED;
|
||||
_pluginList.push(pluginEntry);
|
||||
pluginLoadTrait = pluginElement.getTrait(MediaTraitType.LOAD) as PluginLoadTrait;
|
||||
if(pluginLoadTrait.pluginInfo.mediaElementCreationNotificationFunction != null)
|
||||
{
|
||||
invokeMediaElementCreationNotificationForCreatedMediaElements(pluginLoadTrait.pluginInfo.mediaElementCreationNotificationFunction);
|
||||
if(notificationFunctions == null)
|
||||
{
|
||||
notificationFunctions = new Vector.<Function>();
|
||||
}
|
||||
notificationFunctions.push(pluginLoadTrait.pluginInfo.mediaElementCreationNotificationFunction);
|
||||
}
|
||||
dispatchEvent(new PluginManagerEvent(PluginManagerEvent.PLUGIN_LOAD,false,false,resource));
|
||||
}
|
||||
else if(event.loadState == LoadState.LOAD_ERROR)
|
||||
{
|
||||
delete _pluginMap[identifier];
|
||||
dispatchEvent(new PluginManagerEvent(PluginManagerEvent.PLUGIN_LOAD_ERROR,false,false,resource));
|
||||
}
|
||||
};
|
||||
onMediaError = function(event:MediaErrorEvent):void
|
||||
{
|
||||
dispatchEvent(event.clone());
|
||||
};
|
||||
if(resource == null)
|
||||
{
|
||||
throw new ArgumentError(OSMFStrings.getString(OSMFStrings.INVALID_PARAM));
|
||||
}
|
||||
identifier = this.getPluginIdentifier(resource);
|
||||
pluginEntry = this._pluginMap[identifier] as PluginEntry;
|
||||
if(pluginEntry != null)
|
||||
{
|
||||
dispatchEvent(new PluginManagerEvent(PluginManagerEvent.PLUGIN_LOAD,false,false,resource));
|
||||
}
|
||||
else
|
||||
{
|
||||
pluginElement = this._pluginFactory.createMediaElement(resource);
|
||||
if(pluginElement != null)
|
||||
{
|
||||
pluginEntry = new PluginEntry(pluginElement,PluginLoadingState.LOADING);
|
||||
this._pluginMap[identifier] = pluginEntry;
|
||||
loadTrait = pluginElement.getTrait(MediaTraitType.LOAD) as LoadTrait;
|
||||
if(loadTrait != null)
|
||||
{
|
||||
loadTrait.addEventListener(LoadEvent.LOAD_STATE_CHANGE,onLoadStateChange);
|
||||
loadTrait.addEventListener(MediaErrorEvent.MEDIA_ERROR,onMediaError);
|
||||
loadTrait.load();
|
||||
}
|
||||
else
|
||||
{
|
||||
dispatchEvent(new PluginManagerEvent(PluginManagerEvent.PLUGIN_LOAD_ERROR,false,false,resource));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dispatchEvent(new PluginManagerEvent(PluginManagerEvent.PLUGIN_LOAD_ERROR,false,false,resource));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function get mediaFactory() : MediaFactory
|
||||
{
|
||||
return this._mediaFactory;
|
||||
}
|
||||
|
||||
private function getPluginIdentifier(resource:MediaResourceBase) : Object
|
||||
{
|
||||
var identifier:Object = null;
|
||||
if(resource is URLResource)
|
||||
{
|
||||
identifier = (resource as URLResource).url;
|
||||
}
|
||||
else if(resource is PluginInfoResource)
|
||||
{
|
||||
identifier = (resource as PluginInfoResource).pluginInfo;
|
||||
}
|
||||
return identifier;
|
||||
}
|
||||
|
||||
private function initPluginFactory() : void
|
||||
{
|
||||
this._pluginFactory = new MediaFactory();
|
||||
this.staticPluginLoader = new StaticPluginLoader(this.mediaFactory,this.minimumSupportedFrameworkVersion);
|
||||
this.dynamicPluginLoader = new DynamicPluginLoader(this.mediaFactory,this.minimumSupportedFrameworkVersion);
|
||||
var staticPluginItem:MediaFactoryItem = new MediaFactoryItem(STATIC_PLUGIN_MEDIA_INFO_ID,this.staticPluginLoader.canHandleResource,this.createStaticPluginElement);
|
||||
this._pluginFactory.addItem(staticPluginItem);
|
||||
var dynamicPluginItem:MediaFactoryItem = new MediaFactoryItem(DYNAMIC_PLUGIN_MEDIA_INFO_ID,this.dynamicPluginLoader.canHandleResource,this.createDynamicPluginElement);
|
||||
this._pluginFactory.addItem(dynamicPluginItem);
|
||||
}
|
||||
|
||||
private function createStaticPluginElement() : MediaElement
|
||||
{
|
||||
return new PluginElement(this.staticPluginLoader);
|
||||
}
|
||||
|
||||
private function createDynamicPluginElement() : MediaElement
|
||||
{
|
||||
return new PluginElement(this.dynamicPluginLoader);
|
||||
}
|
||||
|
||||
private function onMediaElementCreate(event:MediaFactoryEvent) : void
|
||||
{
|
||||
this.invokeMediaElementCreationNotifications(event.mediaElement);
|
||||
if(this.createdElements == null)
|
||||
{
|
||||
this.createdElements = new Dictionary(true);
|
||||
}
|
||||
this.createdElements[event.mediaElement] = true;
|
||||
}
|
||||
|
||||
private function invokeMediaElementCreationNotifications(mediaElement:MediaElement) : void
|
||||
{
|
||||
var func:Function = null;
|
||||
for each(func in this.notificationFunctions)
|
||||
{
|
||||
this.invokeMediaElementCreationNotificationFunction(func,mediaElement);
|
||||
}
|
||||
}
|
||||
|
||||
private function invokeMediaElementCreationNotificationFunction(func:Function, mediaElement:MediaElement) : void
|
||||
{
|
||||
try
|
||||
{
|
||||
func.call(null,mediaElement);
|
||||
}
|
||||
catch(error:Error)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
private function invokeMediaElementCreationNotificationForCreatedMediaElements(func:Function) : void
|
||||
{
|
||||
var elem:Object = null;
|
||||
for(elem in this.createdElements)
|
||||
{
|
||||
this.invokeMediaElementCreationNotificationFunction(func,elem as MediaElement);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
package org.osmf.media.pluginClasses
|
||||
{
|
||||
import org.osmf.media.MediaFactory;
|
||||
import org.osmf.media.MediaResourceBase;
|
||||
import org.osmf.media.PluginInfo;
|
||||
import org.osmf.media.PluginInfoResource;
|
||||
import org.osmf.traits.LoadState;
|
||||
import org.osmf.traits.LoadTrait;
|
||||
|
||||
internal class StaticPluginLoader extends PluginLoader
|
||||
{
|
||||
|
||||
public function StaticPluginLoader(mediaFactory:MediaFactory, minimumSupportedFrameworkVersion:String)
|
||||
{
|
||||
super(mediaFactory,minimumSupportedFrameworkVersion);
|
||||
}
|
||||
|
||||
override public function canHandleResource(resource:MediaResourceBase) : Boolean
|
||||
{
|
||||
return resource is PluginInfoResource;
|
||||
}
|
||||
|
||||
override protected function executeLoad(loadTrait:LoadTrait) : void
|
||||
{
|
||||
updateLoadTrait(loadTrait,LoadState.LOADING);
|
||||
var classResource:PluginInfoResource = loadTrait.resource as PluginInfoResource;
|
||||
var pluginInfo:PluginInfo = classResource.pluginInfo;
|
||||
loadFromPluginInfo(loadTrait,pluginInfo);
|
||||
}
|
||||
|
||||
override protected function executeUnload(loadTrait:LoadTrait) : void
|
||||
{
|
||||
var pluginLoadTrait:PluginLoadTrait = loadTrait as PluginLoadTrait;
|
||||
var pluginInfo:PluginInfo = pluginLoadTrait.pluginInfo;
|
||||
updateLoadTrait(loadTrait,LoadState.UNLOADING);
|
||||
unloadFromPluginInfo(pluginInfo);
|
||||
updateLoadTrait(loadTrait,LoadState.UNINITIALIZED);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package org.osmf.media.pluginClasses
|
||||
{
|
||||
[ExcludeClass]
|
||||
public class VersionUtils
|
||||
{
|
||||
|
||||
public function VersionUtils()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public static function parseVersionString(version:String) : Object
|
||||
{
|
||||
var versionInfo:Array = version.split(".");
|
||||
var major:int = 0;
|
||||
var minor:int = 0;
|
||||
if(versionInfo.length >= 1)
|
||||
{
|
||||
major = parseInt(versionInfo[0]);
|
||||
}
|
||||
if(versionInfo.length >= 2)
|
||||
{
|
||||
minor = parseInt(versionInfo[1]);
|
||||
if(minor < 10)
|
||||
{
|
||||
minor *= 10;
|
||||
}
|
||||
}
|
||||
return {
|
||||
"major":major,
|
||||
"minor":minor
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user