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,40 @@
|
||||
package org.osmf.metadata
|
||||
{
|
||||
public class CuePoint extends TimelineMarker
|
||||
{
|
||||
|
||||
public static const EMBEDDED_CUEPOINTS_NAMESPACE:String = "http://www.osmf.org/timeline/embeddedCuePoints/1.0";
|
||||
|
||||
public static const DYNAMIC_CUEPOINTS_NAMESPACE:String = "http://www.osmf.org/timeline/dynamicCuePoints/1.0";
|
||||
|
||||
private var _name:String;
|
||||
|
||||
private var _type:String;
|
||||
|
||||
private var _parameters:Object;
|
||||
|
||||
public function CuePoint(type:String, time:Number, name:String, parameters:Object, duration:Number = NaN)
|
||||
{
|
||||
super(time,duration);
|
||||
this._type = type;
|
||||
this._name = name;
|
||||
this._parameters = parameters;
|
||||
}
|
||||
|
||||
public function get type() : String
|
||||
{
|
||||
return this._type;
|
||||
}
|
||||
|
||||
public function get name() : String
|
||||
{
|
||||
return this._name;
|
||||
}
|
||||
|
||||
public function get parameters() : Object
|
||||
{
|
||||
return this._parameters;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
package org.osmf.metadata
|
||||
{
|
||||
import flash.events.Event;
|
||||
import flash.events.EventDispatcher;
|
||||
import flash.utils.Dictionary;
|
||||
import org.osmf.events.MetadataEvent;
|
||||
import org.osmf.utils.OSMFStrings;
|
||||
|
||||
[Event(name="valueChange",type="org.osmf.events.MetadataEvent")]
|
||||
[Event(name="valueRemove",type="org.osmf.events.MetadataEvent")]
|
||||
[Event(name="valueAdd",type="org.osmf.events.MetadataEvent")]
|
||||
public class Metadata extends EventDispatcher
|
||||
{
|
||||
|
||||
private var data:Dictionary;
|
||||
|
||||
public function Metadata()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public function getValue(key:String) : *
|
||||
{
|
||||
if(key == null)
|
||||
{
|
||||
throw new ArgumentError(OSMFStrings.getString(OSMFStrings.NULL_PARAM));
|
||||
}
|
||||
return this.data != null ? this.data[key] : null;
|
||||
}
|
||||
|
||||
public function addValue(key:String, value:Object) : void
|
||||
{
|
||||
var event:Event = null;
|
||||
if(key == null)
|
||||
{
|
||||
throw new ArgumentError(OSMFStrings.getString(OSMFStrings.NULL_PARAM));
|
||||
}
|
||||
if(this.data == null)
|
||||
{
|
||||
this.data = new Dictionary();
|
||||
}
|
||||
var oldValue:* = this.data[key];
|
||||
this.data[key] = value;
|
||||
if(oldValue != value)
|
||||
{
|
||||
event = oldValue === undefined ? new MetadataEvent(MetadataEvent.VALUE_ADD,false,false,key,value) : new MetadataEvent(MetadataEvent.VALUE_CHANGE,false,false,key,value,oldValue);
|
||||
dispatchEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
public function removeValue(key:String) : *
|
||||
{
|
||||
if(key == null)
|
||||
{
|
||||
throw new ArgumentError(OSMFStrings.getString(OSMFStrings.NULL_PARAM));
|
||||
}
|
||||
var value:* = this.data[key];
|
||||
if(value !== undefined)
|
||||
{
|
||||
delete this.data[key];
|
||||
dispatchEvent(new MetadataEvent(MetadataEvent.VALUE_REMOVE,false,false,key,value));
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
public function get keys() : Vector.<String>
|
||||
{
|
||||
var key:Object = null;
|
||||
var allKeys:Vector.<String> = new Vector.<String>();
|
||||
if(this.data != null)
|
||||
{
|
||||
for(key in this.data)
|
||||
{
|
||||
allKeys.push(key);
|
||||
}
|
||||
}
|
||||
return allKeys;
|
||||
}
|
||||
|
||||
public function get synthesizer() : MetadataSynthesizer
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
package org.osmf.metadata
|
||||
{
|
||||
[ExcludeClass]
|
||||
public final class MetadataNamespaces
|
||||
{
|
||||
|
||||
public static const MEDIA_ELEMENT_METADATA:String = "http://www.osmf.org/mediaElement/1.0";
|
||||
|
||||
public static const DERIVED_RESOURCE_METADATA:String = "http://www.osmf.org/derivedResource/1.0";
|
||||
|
||||
public static const FMS_SERVER_VERSION_METADATA:String = "http://www.osmf.org/fmsServerVersion/1.0";
|
||||
|
||||
public static const ELEMENT_ID:String = "http://www.osmf.org/layout/elementId/1.0";
|
||||
|
||||
public static const LAYOUT_RENDERER_TYPE:String = "http://www.osmf.org/layout/renderer_type/1.0";
|
||||
|
||||
public static const ABSOLUTE_LAYOUT_PARAMETERS:String = "http://www.osmf.org/layout/absolute/1.0";
|
||||
|
||||
public static const RELATIVE_LAYOUT_PARAMETERS:String = "http://www.osmf.org/layout/relative/1.0";
|
||||
|
||||
public static const ANCHOR_LAYOUT_PARAMETERS:String = "http://www.osmf.org/layout/anchor/1.0";
|
||||
|
||||
public static const PADDING_LAYOUT_PARAMETERS:String = "http://www.osmf.org/layout/padding/1.0";
|
||||
|
||||
public static const LAYOUT_ATTRIBUTES:String = "http://www.osmf.org/layout/attributes/1.0";
|
||||
|
||||
public static const BOX_LAYOUT_ATTRIBUTES:String = "http://www.osmf.org/layout/attributes/box/1.0";
|
||||
|
||||
public static const DRM_METADATA:String = "http://www.osmf.org/drm/1.0";
|
||||
|
||||
public static const MULTICAST_INFO:String = "http://www.osmf.org/multicast/info/1.0";
|
||||
|
||||
public static const MULTICAST_NET_LOADER:String = "http://www.osmf.org/multicast/netloader/1.0";
|
||||
|
||||
public static const DVR_METADATA:String = "http://www.osmf.org/dvr/1.0";
|
||||
|
||||
public static const DRM_ADDITIONAL_HEADER_KEY:String = "DRMAdditionalHeader";
|
||||
|
||||
public static const HTTP_STREAMING_METADATA:String = "http://www.osmf.org/httpstreaming/1.0";
|
||||
|
||||
public static const HTTP_STREAMING_BOOTSTRAP_KEY:String = "bootstrap";
|
||||
|
||||
public static const HTTP_STREAMING_STREAM_METADATA_KEY:String = "streamMetadata";
|
||||
|
||||
public static const HTTP_STREAMING_XMP_METADATA_KEY:String = "xmpMetadata";
|
||||
|
||||
public static const HTTP_STREAMING_SERVER_BASE_URLS_KEY:String = "serverBaseUrls";
|
||||
|
||||
public static const HTTP_STREAMING_DVR_BEGIN_OFFSET_KEY:String = "beginOffset";
|
||||
|
||||
public static const HTTP_STREAMING_DVR_END_OFFSET_KEY:String = "endOffset";
|
||||
|
||||
public static const HTTP_STREAMING_DVR_OFFLINE_KEY:String = "dvrOffline";
|
||||
|
||||
public static const HTTP_STREAMING_DVR_ID_KEY:String = "dvrId";
|
||||
|
||||
public function MetadataNamespaces()
|
||||
{
|
||||
super();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package org.osmf.metadata
|
||||
{
|
||||
import org.osmf.elements.compositeClasses.CompositionMode;
|
||||
|
||||
[ExcludeClass]
|
||||
public class MetadataSynthesizer
|
||||
{
|
||||
|
||||
public function MetadataSynthesizer()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public function synthesize(namespaceURL:String, targetParentMetadata:Metadata, metadatas:Vector.<Metadata>, mode:String, serialElementActiveChildMetadata:Metadata) : Metadata
|
||||
{
|
||||
var result:Metadata = null;
|
||||
if(mode == CompositionMode.SERIAL && Boolean(serialElementActiveChildMetadata))
|
||||
{
|
||||
result = serialElementActiveChildMetadata.getValue(namespaceURL) as Metadata;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = metadatas.length >= 1 ? metadatas[0] : null;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,172 @@
|
||||
package org.osmf.metadata
|
||||
{
|
||||
import flash.errors.IllegalOperationError;
|
||||
import org.osmf.events.MetadataEvent;
|
||||
import org.osmf.utils.OSMFStrings;
|
||||
|
||||
[ExcludeClass]
|
||||
public class MetadataWatcher
|
||||
{
|
||||
|
||||
private var parentMetadata:Metadata;
|
||||
|
||||
private var namespaceURL:String;
|
||||
|
||||
private var key:String;
|
||||
|
||||
private var callback:Function;
|
||||
|
||||
private var currentMetadata:Metadata;
|
||||
|
||||
private var watching:Boolean;
|
||||
|
||||
public function MetadataWatcher(parentMetadata:Metadata, namespaceURL:String, key:String, callback:Function)
|
||||
{
|
||||
super();
|
||||
if(parentMetadata == null || namespaceURL == null || callback == null)
|
||||
{
|
||||
throw new IllegalOperationError(OSMFStrings.getString(OSMFStrings.NULL_PARAM));
|
||||
}
|
||||
this.parentMetadata = parentMetadata;
|
||||
this.namespaceURL = namespaceURL;
|
||||
this.key = key;
|
||||
this.callback = callback;
|
||||
}
|
||||
|
||||
public function watch(dispatchInitialChangeEvent:Boolean = true) : void
|
||||
{
|
||||
if(this.watching == false)
|
||||
{
|
||||
this.watching = true;
|
||||
this.parentMetadata.addEventListener(MetadataEvent.VALUE_ADD,this.onMetadataAdd,false,0,true);
|
||||
this.processWatchedMetadataChange(this.parentMetadata.getValue(this.namespaceURL) as Metadata);
|
||||
if(dispatchInitialChangeEvent == true)
|
||||
{
|
||||
if(this.key != null)
|
||||
{
|
||||
this.callback(Boolean(this.currentMetadata) ? this.currentMetadata.getValue(this.key) : undefined);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.callback(Boolean(this.currentMetadata) ? this.currentMetadata : undefined);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function unwatch() : void
|
||||
{
|
||||
if(this.watching == true)
|
||||
{
|
||||
this.processWatchedMetadataChange(null,false);
|
||||
this.parentMetadata.removeEventListener(MetadataEvent.VALUE_ADD,this.onMetadataAdd);
|
||||
this.watching = false;
|
||||
}
|
||||
}
|
||||
|
||||
private function processWatchedMetadataChange(metadata:Metadata, dispatchChange:Boolean = true) : void
|
||||
{
|
||||
var oldMetadata:Metadata = null;
|
||||
if(this.currentMetadata != metadata)
|
||||
{
|
||||
oldMetadata = this.currentMetadata;
|
||||
if(Boolean(this.currentMetadata))
|
||||
{
|
||||
this.currentMetadata.removeEventListener(MetadataEvent.VALUE_CHANGE,this.onValueChange);
|
||||
this.currentMetadata.removeEventListener(MetadataEvent.VALUE_ADD,this.onValueAdd);
|
||||
this.currentMetadata.removeEventListener(MetadataEvent.VALUE_REMOVE,this.onValueRemove);
|
||||
this.parentMetadata.removeEventListener(MetadataEvent.VALUE_REMOVE,this.onMetadataRemove);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.parentMetadata.removeEventListener(MetadataEvent.VALUE_ADD,this.onMetadataAdd);
|
||||
}
|
||||
this.currentMetadata = metadata;
|
||||
if(Boolean(metadata))
|
||||
{
|
||||
metadata.addEventListener(MetadataEvent.VALUE_CHANGE,this.onValueChange,false,0,true);
|
||||
metadata.addEventListener(MetadataEvent.VALUE_ADD,this.onValueAdd,false,0,true);
|
||||
metadata.addEventListener(MetadataEvent.VALUE_REMOVE,this.onValueRemove,false,0,true);
|
||||
this.parentMetadata.addEventListener(MetadataEvent.VALUE_REMOVE,this.onMetadataRemove);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.parentMetadata.addEventListener(MetadataEvent.VALUE_ADD,this.onMetadataAdd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function onMetadataAdd(event:MetadataEvent) : void
|
||||
{
|
||||
var metadata:Metadata = event.value as Metadata;
|
||||
if(Boolean(metadata) && event.key == this.namespaceURL)
|
||||
{
|
||||
this.processWatchedMetadataChange(metadata);
|
||||
if(this.key == null)
|
||||
{
|
||||
this.callback(metadata);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.callback(metadata.getValue(this.key));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function onMetadataRemove(event:MetadataEvent) : void
|
||||
{
|
||||
var metadata:Metadata = event.value as Metadata;
|
||||
if(Boolean(metadata) && event.key == this.namespaceURL)
|
||||
{
|
||||
this.processWatchedMetadataChange(null);
|
||||
this.callback(undefined);
|
||||
}
|
||||
}
|
||||
|
||||
private function onValueChange(event:MetadataEvent) : void
|
||||
{
|
||||
if(Boolean(this.key))
|
||||
{
|
||||
if(this.key == event.key)
|
||||
{
|
||||
this.callback(event.value);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.callback(event.target as Metadata);
|
||||
}
|
||||
}
|
||||
|
||||
private function onValueAdd(event:MetadataEvent) : void
|
||||
{
|
||||
if(Boolean(this.key))
|
||||
{
|
||||
if(this.key == event.key)
|
||||
{
|
||||
this.callback(event.value);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.callback(event.target as Metadata);
|
||||
}
|
||||
}
|
||||
|
||||
private function onValueRemove(event:MetadataEvent) : void
|
||||
{
|
||||
if(Boolean(this.key))
|
||||
{
|
||||
if(this.key == event.key)
|
||||
{
|
||||
this.callback(undefined);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.callback(event.target as Metadata);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package org.osmf.metadata
|
||||
{
|
||||
[ExcludeClass]
|
||||
public class NonSynthesizingMetadata extends Metadata
|
||||
{
|
||||
|
||||
private var _synthesizer:MetadataSynthesizer = new NullMetadataSynthesizer();
|
||||
|
||||
public function NonSynthesizingMetadata()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
override public function get synthesizer() : MetadataSynthesizer
|
||||
{
|
||||
return this._synthesizer;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package org.osmf.metadata
|
||||
{
|
||||
[ExcludeClass]
|
||||
public class NullMetadataSynthesizer extends MetadataSynthesizer
|
||||
{
|
||||
|
||||
public function NullMetadataSynthesizer()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
override public function synthesize(namespaceURL:String, targetParentMetadata:Metadata, metadatas:Vector.<Metadata>, mode:String, activeParentMetadata:Metadata) : Metadata
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package org.osmf.metadata
|
||||
{
|
||||
public class TimelineMarker
|
||||
{
|
||||
|
||||
private var _time:Number;
|
||||
|
||||
private var _duration:Number;
|
||||
|
||||
public function TimelineMarker(time:Number, duration:Number = NaN)
|
||||
{
|
||||
super();
|
||||
this._time = time;
|
||||
this._duration = duration;
|
||||
}
|
||||
|
||||
public function get time() : Number
|
||||
{
|
||||
return this._time;
|
||||
}
|
||||
|
||||
public function get duration() : Number
|
||||
{
|
||||
return this._duration;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,448 @@
|
||||
package org.osmf.metadata
|
||||
{
|
||||
import flash.events.TimerEvent;
|
||||
import flash.utils.Dictionary;
|
||||
import flash.utils.Timer;
|
||||
import org.osmf.events.MediaElementEvent;
|
||||
import org.osmf.events.MetadataEvent;
|
||||
import org.osmf.events.PlayEvent;
|
||||
import org.osmf.events.SeekEvent;
|
||||
import org.osmf.events.TimelineMetadataEvent;
|
||||
import org.osmf.media.MediaElement;
|
||||
import org.osmf.traits.MediaTraitType;
|
||||
import org.osmf.traits.PlayState;
|
||||
import org.osmf.traits.PlayTrait;
|
||||
import org.osmf.traits.SeekTrait;
|
||||
import org.osmf.traits.TimeTrait;
|
||||
import org.osmf.utils.OSMFStrings;
|
||||
|
||||
[Event(name="markerDurationReached",type="org.osmf.events.TimelineMetadataEvent")]
|
||||
[Event(name="markerTimeReached",type="org.osmf.events.TimelineMetadataEvent")]
|
||||
[Event(name="markerRemove",type="org.osmf.metadata.TimelineMetadataEvent")]
|
||||
[Event(name="markerAdd",type="org.osmf.metadata.TimelineMetadataEvent")]
|
||||
public class TimelineMetadata extends Metadata
|
||||
{
|
||||
|
||||
private static const CHECK_INTERVAL:Number = 100;
|
||||
|
||||
private static const TOLERANCE:Number = 0.25;
|
||||
|
||||
private var temporalKeyCollection:Vector.<Number>;
|
||||
|
||||
private var temporalValueCollection:Vector.<TimelineMarker>;
|
||||
|
||||
private var media:MediaElement;
|
||||
|
||||
private var timeTrait:TimeTrait;
|
||||
|
||||
private var seekTrait:SeekTrait;
|
||||
|
||||
private var playTrait:PlayTrait;
|
||||
|
||||
private var lastFiredTemporalMetadataIndex:int;
|
||||
|
||||
private var intervalTimer:Timer;
|
||||
|
||||
private var restartTimer:Boolean;
|
||||
|
||||
private var _enabled:Boolean;
|
||||
|
||||
private var durationTimers:Dictionary;
|
||||
|
||||
public function TimelineMetadata(media:MediaElement)
|
||||
{
|
||||
super();
|
||||
if(media == null)
|
||||
{
|
||||
throw new ArgumentError(OSMFStrings.getString(OSMFStrings.NULL_PARAM));
|
||||
}
|
||||
this.media = media;
|
||||
this._enabled = true;
|
||||
this.intervalTimer = new Timer(CHECK_INTERVAL);
|
||||
this.intervalTimer.addEventListener(TimerEvent.TIMER,this.onIntervalTimer);
|
||||
this.timeTrait = media.getTrait(MediaTraitType.TIME) as TimeTrait;
|
||||
this.seekTrait = media.getTrait(MediaTraitType.SEEK) as SeekTrait;
|
||||
this.setupTraitEventListener(MediaTraitType.SEEK);
|
||||
this.playTrait = media.getTrait(MediaTraitType.PLAY) as PlayTrait;
|
||||
this.setupTraitEventListener(MediaTraitType.PLAY);
|
||||
media.addEventListener(MediaElementEvent.TRAIT_ADD,this.onTraitAdd);
|
||||
media.addEventListener(MediaElementEvent.TRAIT_REMOVE,this.onTraitRemove);
|
||||
}
|
||||
|
||||
public function get numMarkers() : int
|
||||
{
|
||||
return Boolean(this.temporalValueCollection) ? int(this.temporalValueCollection.length) : 0;
|
||||
}
|
||||
|
||||
public function getMarkerAt(index:int) : TimelineMarker
|
||||
{
|
||||
if(index >= 0 && this.temporalValueCollection != null && index < this.temporalValueCollection.length)
|
||||
{
|
||||
return this.temporalValueCollection[index];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function addMarker(marker:TimelineMarker) : void
|
||||
{
|
||||
if(marker == null)
|
||||
{
|
||||
throw new ArgumentError(OSMFStrings.getString(OSMFStrings.INVALID_PARAM));
|
||||
}
|
||||
this.addValue("" + marker.time,marker);
|
||||
}
|
||||
|
||||
public function removeMarker(marker:TimelineMarker) : TimelineMarker
|
||||
{
|
||||
if(marker == null)
|
||||
{
|
||||
throw new ArgumentError(OSMFStrings.getString(OSMFStrings.INVALID_PARAM));
|
||||
}
|
||||
return this.removeValue("" + marker.time);
|
||||
}
|
||||
|
||||
override public function addValue(key:String, value:Object) : void
|
||||
{
|
||||
var index:int = 0;
|
||||
var time:Number = new Number(key);
|
||||
var marker:TimelineMarker = value as TimelineMarker;
|
||||
if(key == null || isNaN(time) || time < 0 || marker == null)
|
||||
{
|
||||
throw new ArgumentError(OSMFStrings.getString(OSMFStrings.INVALID_PARAM));
|
||||
}
|
||||
if(this.temporalValueCollection == null)
|
||||
{
|
||||
this.temporalKeyCollection = new Vector.<Number>();
|
||||
this.temporalKeyCollection.push(time);
|
||||
this.temporalValueCollection = new Vector.<TimelineMarker>();
|
||||
this.temporalValueCollection.push(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
index = this.findTemporalMetadata(0,this.temporalValueCollection.length - 1,time);
|
||||
if(index < 0)
|
||||
{
|
||||
index *= -1;
|
||||
this.temporalKeyCollection.splice(index,0,time);
|
||||
this.temporalValueCollection.splice(index,0,marker);
|
||||
}
|
||||
else if(index == 0 && time != this.temporalKeyCollection[0])
|
||||
{
|
||||
this.temporalKeyCollection.splice(index,0,time);
|
||||
this.temporalValueCollection.splice(index,0,marker);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.temporalKeyCollection[index] = time;
|
||||
this.temporalValueCollection[index] = marker;
|
||||
}
|
||||
}
|
||||
this.enabled = true;
|
||||
dispatchEvent(new MetadataEvent(MetadataEvent.VALUE_ADD,false,false,key,marker));
|
||||
dispatchEvent(new TimelineMetadataEvent(TimelineMetadataEvent.MARKER_ADD,false,false,marker));
|
||||
}
|
||||
|
||||
override public function removeValue(key:String) : *
|
||||
{
|
||||
if(key == null)
|
||||
{
|
||||
throw new ArgumentError(OSMFStrings.getString(OSMFStrings.NULL_PARAM));
|
||||
}
|
||||
var time:Number = new Number(key);
|
||||
var result:* = null;
|
||||
var index:int = Boolean(this.temporalValueCollection) ? this.findTemporalMetadata(0,this.temporalValueCollection.length - 1,time) : -1;
|
||||
if(index >= 0)
|
||||
{
|
||||
this.temporalKeyCollection.splice(index,1);
|
||||
result = this.temporalValueCollection.splice(index,1)[0];
|
||||
if(this.temporalValueCollection.length == 0)
|
||||
{
|
||||
this.reset(false);
|
||||
this.temporalValueCollection = null;
|
||||
this.temporalKeyCollection = null;
|
||||
}
|
||||
dispatchEvent(new MetadataEvent(MetadataEvent.VALUE_REMOVE,false,false,key,result));
|
||||
dispatchEvent(new TimelineMetadataEvent(TimelineMetadataEvent.MARKER_REMOVE,false,false,result as TimelineMarker));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
override public function getValue(key:String) : *
|
||||
{
|
||||
var i:int = 0;
|
||||
var keyTime:Number = NaN;
|
||||
if(key == null)
|
||||
{
|
||||
throw new ArgumentError(OSMFStrings.getString(OSMFStrings.NULL_PARAM));
|
||||
}
|
||||
var time:Number = new Number(key);
|
||||
if(!isNaN(time))
|
||||
{
|
||||
for(i = 0; i < this.temporalKeyCollection.length; i++)
|
||||
{
|
||||
keyTime = this.temporalKeyCollection[i];
|
||||
if(keyTime == time)
|
||||
{
|
||||
return this.temporalValueCollection[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function get enabled() : Boolean
|
||||
{
|
||||
return this._enabled;
|
||||
}
|
||||
|
||||
public function set enabled(value:Boolean) : void
|
||||
{
|
||||
this._enabled = value;
|
||||
this.reset(value);
|
||||
}
|
||||
|
||||
private function startTimer(start:Boolean = true) : void
|
||||
{
|
||||
if(!start)
|
||||
{
|
||||
this.intervalTimer.stop();
|
||||
}
|
||||
else if(this.timeTrait != null && this.temporalValueCollection != null && this.temporalValueCollection.length > 0 && this.restartTimer && this.enabled && !this.intervalTimer.running)
|
||||
{
|
||||
if(this.playTrait != null && this.playTrait.playState == PlayState.PLAYING)
|
||||
{
|
||||
this.intervalTimer.start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function reset(startTimer:Boolean) : void
|
||||
{
|
||||
this.lastFiredTemporalMetadataIndex = -1;
|
||||
this.restartTimer = true;
|
||||
this.intervalTimer.reset();
|
||||
this.intervalTimer.delay = CHECK_INTERVAL;
|
||||
if(startTimer)
|
||||
{
|
||||
this.startTimer();
|
||||
}
|
||||
}
|
||||
|
||||
private function checkForTemporalMetadata() : void
|
||||
{
|
||||
var now:Number = this.timeTrait.currentTime;
|
||||
var index:int = this.findTemporalMetadata(this.lastFiredTemporalMetadataIndex + 1,this.temporalValueCollection.length - 1,now);
|
||||
if(index <= 0)
|
||||
{
|
||||
index *= -1;
|
||||
index = index > 0 ? int(index - 1) : 0;
|
||||
}
|
||||
if(!this.checkTemporalMetadata(index,now) && index + 1 < this.temporalValueCollection.length)
|
||||
{
|
||||
this.checkTemporalMetadata(index + 1,now);
|
||||
}
|
||||
}
|
||||
|
||||
private function setupTraitEventListener(traitType:String, add:Boolean = true) : void
|
||||
{
|
||||
var event:PlayEvent = null;
|
||||
if(add)
|
||||
{
|
||||
if(traitType == MediaTraitType.SEEK && this.seekTrait != null)
|
||||
{
|
||||
this.seekTrait.addEventListener(SeekEvent.SEEKING_CHANGE,this.onSeekingChange);
|
||||
}
|
||||
else if(traitType == MediaTraitType.PLAY && this.playTrait != null)
|
||||
{
|
||||
this.playTrait.addEventListener(PlayEvent.PLAY_STATE_CHANGE,this.onPlayStateChange);
|
||||
if(this.playTrait.playState == PlayState.PLAYING)
|
||||
{
|
||||
event = new PlayEvent(PlayEvent.PLAY_STATE_CHANGE,false,false,PlayState.PLAYING);
|
||||
this.onPlayStateChange(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(traitType == MediaTraitType.SEEK && this.seekTrait != null)
|
||||
{
|
||||
this.seekTrait.removeEventListener(SeekEvent.SEEKING_CHANGE,this.onSeekingChange);
|
||||
}
|
||||
else if(traitType == MediaTraitType.PLAY && this.playTrait != null)
|
||||
{
|
||||
this.playTrait.removeEventListener(PlayEvent.PLAY_STATE_CHANGE,this.onPlayStateChange);
|
||||
}
|
||||
}
|
||||
|
||||
private function onSeekingChange(event:SeekEvent) : void
|
||||
{
|
||||
if(event.seeking)
|
||||
{
|
||||
this.reset(true);
|
||||
}
|
||||
}
|
||||
|
||||
private function onPlayStateChange(event:PlayEvent) : void
|
||||
{
|
||||
var timer:Timer = null;
|
||||
if(event.playState == PlayState.PLAYING)
|
||||
{
|
||||
if(this.durationTimers != null)
|
||||
{
|
||||
for each(timer in this.durationTimers)
|
||||
{
|
||||
timer.start();
|
||||
}
|
||||
}
|
||||
this.startTimer();
|
||||
}
|
||||
else
|
||||
{
|
||||
if(this.durationTimers != null)
|
||||
{
|
||||
for each(timer in this.durationTimers)
|
||||
{
|
||||
timer.stop();
|
||||
}
|
||||
}
|
||||
this.startTimer(false);
|
||||
}
|
||||
}
|
||||
|
||||
private function findTemporalMetadata(firstIndex:int, lastIndex:int, time:Number) : int
|
||||
{
|
||||
var mid:int = 0;
|
||||
if(firstIndex <= lastIndex)
|
||||
{
|
||||
mid = (firstIndex + lastIndex) / 2;
|
||||
if(time == this.temporalKeyCollection[mid])
|
||||
{
|
||||
return mid;
|
||||
}
|
||||
if(time < this.temporalKeyCollection[mid])
|
||||
{
|
||||
return this.findTemporalMetadata(firstIndex,mid - 1,time);
|
||||
}
|
||||
return this.findTemporalMetadata(mid + 1,lastIndex,time);
|
||||
}
|
||||
return -firstIndex;
|
||||
}
|
||||
|
||||
private function dispatchTemporalEvents(index:int) : void
|
||||
{
|
||||
var marker:TimelineMarker = null;
|
||||
var timer:Timer = null;
|
||||
var endTime:Number = NaN;
|
||||
var onDurationTimer:Function = null;
|
||||
marker = this.temporalValueCollection[index];
|
||||
dispatchEvent(new TimelineMetadataEvent(TimelineMetadataEvent.MARKER_TIME_REACHED,false,false,marker));
|
||||
if(marker.duration > 0)
|
||||
{
|
||||
onDurationTimer = function(event:TimerEvent):void
|
||||
{
|
||||
if(Boolean(timeTrait) && timeTrait.currentTime >= endTime)
|
||||
{
|
||||
timer.removeEventListener(TimerEvent.TIMER,onDurationTimer);
|
||||
delete durationTimers[marker];
|
||||
dispatchEvent(new TimelineMetadataEvent(TimelineMetadataEvent.MARKER_DURATION_REACHED,false,false,marker));
|
||||
}
|
||||
};
|
||||
timer = new Timer(CHECK_INTERVAL);
|
||||
endTime = marker.time + marker.duration;
|
||||
if(this.durationTimers == null)
|
||||
{
|
||||
this.durationTimers = new Dictionary();
|
||||
}
|
||||
this.durationTimers[marker] = timer;
|
||||
timer.addEventListener(TimerEvent.TIMER,onDurationTimer);
|
||||
timer.start();
|
||||
}
|
||||
}
|
||||
|
||||
private function checkTemporalMetadata(index:int, now:Number) : Boolean
|
||||
{
|
||||
var thisTime:Number = NaN;
|
||||
var nextTime:Number = NaN;
|
||||
var newDelay:Number = NaN;
|
||||
if(!this.temporalValueCollection || !this.temporalValueCollection.length)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var result:Boolean = false;
|
||||
if(this.temporalValueCollection[index].time >= now - TOLERANCE && this.temporalValueCollection[index].time <= now + TOLERANCE && index != this.lastFiredTemporalMetadataIndex)
|
||||
{
|
||||
this.lastFiredTemporalMetadataIndex = index;
|
||||
this.dispatchTemporalEvents(index);
|
||||
thisTime = this.temporalKeyCollection[index];
|
||||
nextTime = this.calcNextTime(index);
|
||||
newDelay = (nextTime - thisTime) * 1000 / 4;
|
||||
newDelay = newDelay > CHECK_INTERVAL ? newDelay : CHECK_INTERVAL;
|
||||
if(thisTime == nextTime)
|
||||
{
|
||||
this.startTimer(false);
|
||||
this.restartTimer = false;
|
||||
}
|
||||
else if(newDelay != this.intervalTimer.delay)
|
||||
{
|
||||
this.intervalTimer.reset();
|
||||
this.intervalTimer.delay = newDelay;
|
||||
this.startTimer();
|
||||
}
|
||||
result = true;
|
||||
}
|
||||
else if(this.intervalTimer.delay != CHECK_INTERVAL && now + this.intervalTimer.delay / 1000 > this.calcNextTime(index))
|
||||
{
|
||||
this.intervalTimer.reset();
|
||||
this.intervalTimer.delay = CHECK_INTERVAL;
|
||||
this.startTimer();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private function calcNextTime(index:int) : Number
|
||||
{
|
||||
return this.temporalValueCollection[index + 1 < this.temporalKeyCollection.length ? index + 1 : this.temporalKeyCollection.length - 1].time;
|
||||
}
|
||||
|
||||
private function onIntervalTimer(event:TimerEvent) : void
|
||||
{
|
||||
this.checkForTemporalMetadata();
|
||||
}
|
||||
|
||||
private function onTraitAdd(event:MediaElementEvent) : void
|
||||
{
|
||||
switch(event.traitType)
|
||||
{
|
||||
case MediaTraitType.TIME:
|
||||
this.timeTrait = this.media.getTrait(MediaTraitType.TIME) as TimeTrait;
|
||||
this.startTimer();
|
||||
break;
|
||||
case MediaTraitType.SEEK:
|
||||
this.seekTrait = this.media.getTrait(MediaTraitType.SEEK) as SeekTrait;
|
||||
break;
|
||||
case MediaTraitType.PLAY:
|
||||
this.playTrait = this.media.getTrait(MediaTraitType.PLAY) as PlayTrait;
|
||||
}
|
||||
this.setupTraitEventListener(event.traitType);
|
||||
}
|
||||
|
||||
private function onTraitRemove(event:MediaElementEvent) : void
|
||||
{
|
||||
this.setupTraitEventListener(event.traitType,false);
|
||||
switch(event.traitType)
|
||||
{
|
||||
case MediaTraitType.TIME:
|
||||
this.timeTrait = null;
|
||||
if(this.media.hasOwnProperty("numChildren") == false)
|
||||
{
|
||||
this.startTimer(false);
|
||||
}
|
||||
break;
|
||||
case MediaTraitType.SEEK:
|
||||
this.seekTrait = null;
|
||||
break;
|
||||
case MediaTraitType.PLAY:
|
||||
this.playTrait = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user