mirror of
https://github.com/burrow-dev/burrow-server.git
synced 2026-11-21 09: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,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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user