Brought up to date with the private repository (feea4c7)

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

No files matched your search

@@ -0,0 +1,119 @@
package org.osmf.traits
{
import org.osmf.events.AudioEvent;
[Event(name="panChange",type="org.osmf.events.AudioEvent")]
[Event(name="mutedChange",type="org.osmf.events.AudioEvent")]
[Event(name="volumeChange",type="org.osmf.events.AudioEvent")]
public class AudioTrait extends MediaTraitBase
{
private var _volume:Number = 1;
private var _muted:Boolean = false;
private var _pan:Number = 0;
public function AudioTrait()
{
super(MediaTraitType.AUDIO);
}
public function get volume() : Number
{
return this._volume;
}
final public function set volume(value:Number) : void
{
if(isNaN(value))
{
value = 0;
}
else if(value > 1)
{
value = 1;
}
else if(value < 0)
{
value = 0;
}
if(value != this._volume)
{
this.volumeChangeStart(value);
this._volume = value;
this.volumeChangeEnd();
}
}
public function get muted() : Boolean
{
return this._muted;
}
final public function set muted(value:Boolean) : void
{
if(value != this._muted)
{
this.mutedChangeStart(value);
this._muted = value;
this.mutedChangeEnd();
}
}
public function get pan() : Number
{
return this._pan;
}
final public function set pan(value:Number) : void
{
if(isNaN(value))
{
value = 0;
}
else if(value > 1)
{
value = 1;
}
else if(value < -1)
{
value = -1;
}
if(value != this._pan)
{
this.panChangeStart(value);
this._pan = value;
this.panChangeEnd();
}
}
protected function volumeChangeStart(newVolume:Number) : void
{
}
protected function volumeChangeEnd() : void
{
dispatchEvent(new AudioEvent(AudioEvent.VOLUME_CHANGE,false,false,false,this._volume));
}
protected function mutedChangeStart(newMuted:Boolean) : void
{
}
protected function mutedChangeEnd() : void
{
dispatchEvent(new AudioEvent(AudioEvent.MUTED_CHANGE,false,false,this._muted));
}
protected function panChangeStart(newPan:Number) : void
{
}
protected function panChangeEnd() : void
{
dispatchEvent(new AudioEvent(AudioEvent.PAN_CHANGE,false,false,false,NaN,this._pan));
}
}
}
@@ -0,0 +1,98 @@
package org.osmf.traits
{
import org.osmf.events.BufferEvent;
[Event(name="bufferTimeChange",type="org.osmf.events.BufferEvent")]
[Event(name="bufferingChange",type="org.osmf.events.BufferEvent")]
public class BufferTrait extends MediaTraitBase
{
private var _buffering:Boolean = false;
private var _bufferLength:Number = 0;
private var _bufferTime:Number = 0;
public function BufferTrait()
{
super(MediaTraitType.BUFFER);
}
public function get buffering() : Boolean
{
return this._buffering;
}
public function get bufferLength() : Number
{
return this._bufferLength;
}
public function get bufferTime() : Number
{
return this._bufferTime;
}
public function set bufferTime(value:Number) : void
{
if(isNaN(value) || value < 0)
{
value = 0;
}
if(value != this._bufferTime)
{
this.bufferTimeChangeStart(value);
this._bufferTime = value;
this.bufferTimeChangeEnd();
}
}
final protected function setBufferLength(value:Number) : void
{
if(value != this._bufferLength)
{
this.bufferLengthChangeStart(value);
this._bufferLength = value;
this.bufferLengthChangeEnd();
}
}
final protected function setBuffering(value:Boolean) : void
{
if(value != this._buffering)
{
this.bufferingChangeStart(value);
this._buffering = value;
this.bufferingChangeEnd();
}
}
protected function bufferingChangeStart(newBuffering:Boolean) : void
{
}
protected function bufferingChangeEnd() : void
{
dispatchEvent(new BufferEvent(BufferEvent.BUFFERING_CHANGE,false,false,this._buffering));
}
protected function bufferLengthChangeStart(newSize:Number) : void
{
}
protected function bufferLengthChangeEnd() : void
{
dispatchEvent(new BufferEvent(BufferEvent.BUFFER_LENGTH_CHANGE,false,false,false,NaN,this._bufferLength));
}
protected function bufferTimeChangeStart(newTime:Number) : void
{
}
protected function bufferTimeChangeEnd() : void
{
dispatchEvent(new BufferEvent(BufferEvent.BUFFER_TIME_CHANGE,false,false,false,this._bufferTime));
}
}
}
@@ -0,0 +1,24 @@
package org.osmf.traits
{
public final class DRMState
{
public static const UNINITIALIZED:String = "uninitialized";
public static const AUTHENTICATION_NEEDED:String = "authenticationNeeded";
public static const AUTHENTICATING:String = "authenticating";
public static const AUTHENTICATION_COMPLETE:String = "authenticationComplete";
public static const AUTHENTICATION_ERROR:String = "authenticationError";
public static const DRM_SYSTEM_UPDATING:String = "drmSystemUpdating";
public function DRMState()
{
super();
}
}
}
@@ -0,0 +1,69 @@
package org.osmf.traits
{
[Event(name="drmStateChange",type="org.osmf.events.DRMEvent")]
public class DRMTrait extends MediaTraitBase
{
private var _drmState:String = "uninitialized";
private var _period:Number = 0;
private var _endDate:Date;
private var _startDate:Date;
public function DRMTrait()
{
super(MediaTraitType.DRM);
}
public function authenticate(username:String = null, password:String = null) : void
{
}
public function authenticateWithToken(token:Object) : void
{
}
public function get drmState() : String
{
return this._drmState;
}
public function get startDate() : Date
{
return this._startDate;
}
public function get endDate() : Date
{
return this._endDate;
}
public function get period() : Number
{
return this._period;
}
final protected function setPeriod(value:Number) : void
{
this._period = value;
}
final protected function setStartDate(value:Date) : void
{
this._startDate = value;
}
final protected function setEndDate(value:Date) : void
{
this._endDate = value;
}
final protected function setDrmState(value:String) : void
{
this._drmState = value;
}
}
}
@@ -0,0 +1,42 @@
package org.osmf.traits
{
import org.osmf.events.DVREvent;
[Event(name="isRecordingChange",type="org.osmf.events.DVREvent")]
public class DVRTrait extends MediaTraitBase
{
private var _isRecording:Boolean;
public function DVRTrait(isRecording:Boolean = false)
{
this._isRecording = isRecording;
super(MediaTraitType.DVR);
}
final public function get isRecording() : Boolean
{
return this._isRecording;
}
final protected function setIsRecording(value:Boolean) : void
{
if(value != this._isRecording)
{
this.isRecordingChangeStart(value);
this._isRecording = value;
this.isRecordingChangeEnd();
}
}
protected function isRecordingChangeStart(value:Boolean) : void
{
}
protected function isRecordingChangeEnd() : void
{
dispatchEvent(new DVREvent(DVREvent.IS_RECORDING_CHANGE));
}
}
}
@@ -0,0 +1,86 @@
package org.osmf.traits
{
import flash.display.DisplayObject;
import org.osmf.events.DisplayObjectEvent;
[Event(name="mediaSizeChange",type="org.osmf.events.DisplayObjectEvent")]
[Event(name="displayObjectChange",type="org.osmf.events.DisplayObjectEvent")]
public class DisplayObjectTrait extends MediaTraitBase
{
private var _displayObject:DisplayObject;
private var _mediaWidth:Number = 0;
private var _mediaHeight:Number = 0;
public function DisplayObjectTrait(displayObject:DisplayObject, mediaWidth:Number = 0, mediaHeight:Number = 0)
{
super(MediaTraitType.DISPLAY_OBJECT);
this._displayObject = displayObject;
this._mediaWidth = mediaWidth;
this._mediaHeight = mediaHeight;
}
public function get displayObject() : DisplayObject
{
return this._displayObject;
}
public function get mediaWidth() : Number
{
return this._mediaWidth;
}
public function get mediaHeight() : Number
{
return this._mediaHeight;
}
final protected function setDisplayObject(value:DisplayObject) : void
{
var oldDisplayObject:DisplayObject = null;
if(this._displayObject != value)
{
this.displayObjectChangeStart(value);
oldDisplayObject = this._displayObject;
this._displayObject = value;
this.displayObjectChangeEnd(oldDisplayObject);
}
}
final protected function setMediaSize(mediaWidth:Number, mediaHeight:Number) : void
{
var oldMediaWidth:Number = NaN;
var oldMediaHeight:Number = NaN;
if(mediaWidth != this._mediaWidth || mediaHeight != this._mediaHeight)
{
this.mediaSizeChangeStart(mediaWidth,mediaHeight);
oldMediaWidth = this._mediaWidth;
oldMediaHeight = this._mediaHeight;
this._mediaWidth = mediaWidth;
this._mediaHeight = mediaHeight;
this.mediaSizeChangeEnd(oldMediaWidth,oldMediaHeight);
}
}
protected function displayObjectChangeStart(newView:DisplayObject) : void
{
}
protected function displayObjectChangeEnd(oldDisplayObject:DisplayObject) : void
{
dispatchEvent(new DisplayObjectEvent(DisplayObjectEvent.DISPLAY_OBJECT_CHANGE,false,false,oldDisplayObject,this._displayObject));
}
protected function mediaSizeChangeStart(newMediaWidth:Number, newMediaHeight:Number) : void
{
}
protected function mediaSizeChangeEnd(oldMediaWidth:Number, oldMediaHeight:Number) : void
{
dispatchEvent(new DisplayObjectEvent(DisplayObjectEvent.MEDIA_SIZE_CHANGE,false,false,null,null,oldMediaWidth,oldMediaHeight,this._mediaWidth,this._mediaHeight));
}
}
}
@@ -0,0 +1,166 @@
package org.osmf.traits
{
import flash.errors.IllegalOperationError;
import org.osmf.events.DynamicStreamEvent;
import org.osmf.utils.OSMFStrings;
[Event(name="autoSwitchChange",type="org.osmf.events.DynamicStreamEvent")]
[Event(name="numDynamicStreamsChange",type="org.osmf.events.DynamicStreamEvent")]
[Event(name="switchingChange",type="org.osmf.events.DynamicStreamEvent")]
public class DynamicStreamTrait extends MediaTraitBase
{
private var _autoSwitch:Boolean;
private var _currentIndex:int = 0;
private var _maxAllowedIndex:int = 0;
private var _numDynamicStreams:int;
private var _switching:Boolean;
public function DynamicStreamTrait(autoSwitch:Boolean = true, currentIndex:int = 0, numDynamicStreams:int = 1)
{
super(MediaTraitType.DYNAMIC_STREAM);
this._autoSwitch = autoSwitch;
this._currentIndex = currentIndex;
this._numDynamicStreams = numDynamicStreams;
this._maxAllowedIndex = numDynamicStreams - 1;
this._switching = false;
}
public function get autoSwitch() : Boolean
{
return this._autoSwitch;
}
final public function set autoSwitch(value:Boolean) : void
{
if(this.autoSwitch != value)
{
this.autoSwitchChangeStart(value);
this._autoSwitch = value;
this.autoSwitchChangeEnd();
}
}
public function get numDynamicStreams() : int
{
return this._numDynamicStreams;
}
public function get currentIndex() : int
{
return this._currentIndex;
}
public function get maxAllowedIndex() : int
{
return this._maxAllowedIndex;
}
final public function set maxAllowedIndex(value:int) : void
{
if(value < 0 || value > this._numDynamicStreams - 1)
{
throw new RangeError(OSMFStrings.getString(OSMFStrings.STREAMSWITCH_INVALID_INDEX));
}
if(this.maxAllowedIndex != value)
{
this.maxAllowedIndexChangeStart(value);
this._maxAllowedIndex = value;
this.maxAllowedIndexChangeEnd();
}
}
public function getBitrateForIndex(index:int) : Number
{
if(index > this._numDynamicStreams - 1 || index < 0)
{
throw new RangeError(OSMFStrings.getString(OSMFStrings.STREAMSWITCH_INVALID_INDEX));
}
return 0;
}
public function get switching() : Boolean
{
return this._switching;
}
public function switchTo(index:int) : void
{
if(this.autoSwitch)
{
throw new IllegalOperationError(OSMFStrings.getString(OSMFStrings.STREAMSWITCH_STREAM_NOT_IN_MANUAL_MODE));
}
if(index != this.currentIndex)
{
if(index < 0 || index > this.maxAllowedIndex)
{
throw new RangeError(OSMFStrings.getString(OSMFStrings.STREAMSWITCH_INVALID_INDEX));
}
this.setSwitching(true,index);
}
}
final protected function setNumDynamicStreams(value:int) : void
{
if(value != this._numDynamicStreams)
{
this._numDynamicStreams = value;
if(this.maxAllowedIndex >= this._numDynamicStreams)
{
this.maxAllowedIndex = Math.max(0,this._numDynamicStreams - 1);
}
dispatchEvent(new DynamicStreamEvent(DynamicStreamEvent.NUM_DYNAMIC_STREAMS_CHANGE));
}
}
final protected function setCurrentIndex(value:int) : void
{
this._currentIndex = value;
}
final protected function setSwitching(newSwitching:Boolean, index:int) : void
{
if(newSwitching != this._switching)
{
this.switchingChangeStart(newSwitching,index);
this._switching = newSwitching;
if(newSwitching == false)
{
this.setCurrentIndex(index);
}
this.switchingChangeEnd(index);
}
}
protected function autoSwitchChangeStart(value:Boolean) : void
{
}
protected function autoSwitchChangeEnd() : void
{
dispatchEvent(new DynamicStreamEvent(DynamicStreamEvent.AUTO_SWITCH_CHANGE,false,false,false,this._autoSwitch));
}
protected function switchingChangeStart(newSwitching:Boolean, index:int) : void
{
}
protected function switchingChangeEnd(index:int) : void
{
dispatchEvent(new DynamicStreamEvent(DynamicStreamEvent.SWITCHING_CHANGE,false,false,this.switching));
}
protected function maxAllowedIndexChangeStart(newIndex:int) : void
{
}
protected function maxAllowedIndexChangeEnd() : void
{
}
}
}
@@ -0,0 +1,22 @@
package org.osmf.traits
{
public final class LoadState
{
public static const UNINITIALIZED:String = "uninitialized";
public static const LOADING:String = "loading";
public static const UNLOADING:String = "unloading";
public static const READY:String = "ready";
public static const LOAD_ERROR:String = "loadError";
public function LoadState()
{
super();
}
}
}
@@ -0,0 +1,165 @@
package org.osmf.traits
{
import flash.errors.IllegalOperationError;
import org.osmf.events.LoadEvent;
import org.osmf.events.LoaderEvent;
import org.osmf.media.MediaResourceBase;
import org.osmf.utils.OSMFStrings;
[Event(name="bytesTotalChange",type="org.osmf.events.LoadEvent")]
[Event(name="loadStateChange",type="org.osmf.events.LoadEvent")]
public class LoadTrait extends MediaTraitBase
{
private var loader:LoaderBase;
private var _resource:MediaResourceBase;
private var _loadState:String;
private var _bytesLoaded:Number;
private var _bytesTotal:Number;
public function LoadTrait(loader:LoaderBase, resource:MediaResourceBase)
{
super(MediaTraitType.LOAD);
this.loader = loader;
this._resource = resource;
this._loadState = LoadState.UNINITIALIZED;
if(loader != null)
{
loader.addEventListener(LoaderEvent.LOAD_STATE_CHANGE,this.onLoadStateChange,false,int.MAX_VALUE,true);
}
}
public function get resource() : MediaResourceBase
{
return this._resource;
}
public function get loadState() : String
{
return this._loadState;
}
public function load() : void
{
if(Boolean(this.loader))
{
if(this._loadState == LoadState.READY)
{
throw new IllegalOperationError(OSMFStrings.getString(OSMFStrings.ALREADY_READY));
}
if(this._loadState == LoadState.LOADING)
{
throw new IllegalOperationError(OSMFStrings.getString(OSMFStrings.ALREADY_LOADING));
}
this.loader.load(this);
return;
}
throw new IllegalOperationError(OSMFStrings.getString(OSMFStrings.MUST_SET_LOADER));
}
public function unload() : void
{
if(Boolean(this.loader))
{
if(this._loadState == LoadState.UNLOADING)
{
throw new IllegalOperationError(OSMFStrings.getString(OSMFStrings.ALREADY_UNLOADING));
}
if(this._loadState == LoadState.UNINITIALIZED)
{
throw new IllegalOperationError(OSMFStrings.getString(OSMFStrings.ALREADY_UNLOADED));
}
this.loader.unload(this);
return;
}
throw new IllegalOperationError(OSMFStrings.getString(OSMFStrings.MUST_SET_LOADER));
}
public function get bytesLoaded() : Number
{
return this._bytesLoaded;
}
public function get bytesTotal() : Number
{
return this._bytesTotal;
}
final protected function setLoadState(newState:String) : void
{
if(this._loadState != newState)
{
this.loadStateChangeStart(newState);
this._loadState = newState;
this.loadStateChangeEnd();
}
}
final protected function setBytesLoaded(value:Number) : void
{
if(isNaN(value) || value > this.bytesTotal || value < 0)
{
throw new ArgumentError(OSMFStrings.getString(OSMFStrings.INVALID_PARAM));
}
if(value != this._bytesLoaded)
{
this.bytesLoadedChangeStart(value);
this._bytesLoaded = value;
this.bytesLoadedChangeEnd();
}
}
final protected function setBytesTotal(value:Number) : void
{
if(value < this._bytesLoaded || value < 0)
{
throw new ArgumentError(OSMFStrings.getString(OSMFStrings.INVALID_PARAM));
}
if(value != this._bytesTotal)
{
this.bytesTotalChangeStart(value);
this._bytesTotal = value;
this.bytesTotalChangeEnd();
}
}
protected function bytesLoadedChangeStart(newValue:Number) : void
{
}
protected function bytesLoadedChangeEnd() : void
{
}
protected function bytesTotalChangeStart(newValue:Number) : void
{
}
protected function bytesTotalChangeEnd() : void
{
dispatchEvent(new LoadEvent(LoadEvent.BYTES_TOTAL_CHANGE,false,false,null,this._bytesTotal));
}
protected function loadStateChangeStart(newState:String) : void
{
}
protected function loadStateChangeEnd() : void
{
dispatchEvent(new LoadEvent(LoadEvent.LOAD_STATE_CHANGE,false,false,this._loadState));
}
private function onLoadStateChange(event:LoaderEvent) : void
{
if(event.loadTrait == this)
{
this.setLoadState(event.newState);
}
}
}
}
@@ -0,0 +1,94 @@
package org.osmf.traits
{
import flash.errors.IllegalOperationError;
import flash.events.EventDispatcher;
import org.osmf.events.LoaderEvent;
import org.osmf.media.MediaResourceBase;
import org.osmf.utils.OSMFStrings;
[Event(name="loadStateChange",type="org.osmf.events.LoaderEvent")]
public class LoaderBase extends EventDispatcher
{
public function LoaderBase()
{
super();
}
public function canHandleResource(resource:MediaResourceBase) : Boolean
{
return false;
}
final public function load(loadTrait:LoadTrait) : void
{
this.validateLoad(loadTrait);
this.executeLoad(loadTrait);
}
final public function unload(loadTrait:LoadTrait) : void
{
this.validateUnload(loadTrait);
this.executeUnload(loadTrait);
}
protected function executeLoad(loadTrait:LoadTrait) : void
{
}
protected function executeUnload(loadTrait:LoadTrait) : void
{
}
final protected function updateLoadTrait(loadTrait:LoadTrait, newState:String) : void
{
var oldState:String = null;
if(newState != loadTrait.loadState)
{
oldState = loadTrait.loadState;
dispatchEvent(new LoaderEvent(LoaderEvent.LOAD_STATE_CHANGE,false,false,this,loadTrait,oldState,newState));
}
}
private function validateLoad(loadTrait:LoadTrait) : void
{
if(loadTrait == null)
{
throw new IllegalOperationError(OSMFStrings.getString(OSMFStrings.NULL_PARAM));
}
if(loadTrait.loadState == LoadState.READY)
{
throw new IllegalOperationError(OSMFStrings.getString(OSMFStrings.ALREADY_READY));
}
if(loadTrait.loadState == LoadState.LOADING)
{
throw new IllegalOperationError(OSMFStrings.getString(OSMFStrings.ALREADY_LOADING));
}
if(this.canHandleResource(loadTrait.resource) == false)
{
throw new IllegalOperationError(OSMFStrings.getString(OSMFStrings.LOADER_CANT_HANDLE_RESOURCE));
}
}
private function validateUnload(loadTrait:LoadTrait) : void
{
if(loadTrait == null)
{
throw new IllegalOperationError(OSMFStrings.getString(OSMFStrings.NULL_PARAM));
}
if(loadTrait.loadState == LoadState.UNLOADING)
{
throw new IllegalOperationError(OSMFStrings.getString(OSMFStrings.ALREADY_UNLOADING));
}
if(loadTrait.loadState == LoadState.UNINITIALIZED)
{
throw new IllegalOperationError(OSMFStrings.getString(OSMFStrings.ALREADY_UNLOADED));
}
if(this.canHandleResource(loadTrait.resource) == false)
{
throw new IllegalOperationError(OSMFStrings.getString(OSMFStrings.LOADER_CANT_HANDLE_RESOURCE));
}
}
}
}
@@ -0,0 +1,26 @@
package org.osmf.traits
{
import flash.events.EventDispatcher;
public class MediaTraitBase extends EventDispatcher
{
private var _traitType:String;
public function MediaTraitBase(traitType:String)
{
super();
this._traitType = traitType;
}
public function get traitType() : String
{
return this._traitType;
}
public function dispose() : void
{
}
}
}
@@ -0,0 +1,34 @@
package org.osmf.traits
{
public final class MediaTraitType
{
public static const AUDIO:String = "audio";
public static const BUFFER:String = "buffer";
public static const DRM:String = "drm";
public static const DYNAMIC_STREAM:String = "dynamicStream";
public static const LOAD:String = "load";
public static const PLAY:String = "play";
public static const SEEK:String = "seek";
public static const TIME:String = "time";
public static const DISPLAY_OBJECT:String = "displayObject";
public static const DVR:String = "dvr";
public static const ALL_TYPES:Vector.<String> = Vector.<String>([AUDIO,BUFFER,DRM,DYNAMIC_STREAM,LOAD,PLAY,SEEK,TIME,DISPLAY_OBJECT,DVR]);
public function MediaTraitType()
{
super();
}
}
}
@@ -0,0 +1,18 @@
package org.osmf.traits
{
public final class PlayState
{
public static const PLAYING:String = "playing";
public static const PAUSED:String = "paused";
public static const STOPPED:String = "stopped";
public function PlayState()
{
super();
}
}
}
@@ -0,0 +1,82 @@
package org.osmf.traits
{
import flash.errors.IllegalOperationError;
import org.osmf.events.PlayEvent;
import org.osmf.utils.OSMFStrings;
[Event(name="playStateChange",type="org.osmf.events.PlayEvent")]
[Event(name="canPauseChange",type="org.osmf.events.PlayEvent")]
public class PlayTrait extends MediaTraitBase
{
private var _playState:String;
private var _canPause:Boolean;
public function PlayTrait()
{
super(MediaTraitType.PLAY);
this._canPause = true;
this._playState = PlayState.STOPPED;
}
final public function play() : void
{
this.attemptPlayStateChange(PlayState.PLAYING);
}
public function get canPause() : Boolean
{
return this._canPause;
}
final public function pause() : void
{
if(this.canPause)
{
this.attemptPlayStateChange(PlayState.PAUSED);
return;
}
throw new IllegalOperationError(OSMFStrings.getString(OSMFStrings.PAUSE_NOT_SUPPORTED));
}
final public function stop() : void
{
this.attemptPlayStateChange(PlayState.STOPPED);
}
public function get playState() : String
{
return this._playState;
}
final protected function setCanPause(value:Boolean) : void
{
if(value != this._canPause)
{
this._canPause = value;
dispatchEvent(new PlayEvent(PlayEvent.CAN_PAUSE_CHANGE));
}
}
protected function playStateChangeStart(newPlayState:String) : void
{
}
protected function playStateChangeEnd() : void
{
dispatchEvent(new PlayEvent(PlayEvent.PLAY_STATE_CHANGE,false,false,this.playState));
}
private function attemptPlayStateChange(newPlayState:String) : void
{
if(this._playState != newPlayState)
{
this.playStateChangeStart(newPlayState);
this._playState = newPlayState;
this.playStateChangeEnd();
}
}
}
}
@@ -0,0 +1,64 @@
package org.osmf.traits
{
import org.osmf.events.SeekEvent;
[Event(name="seekingChange",type="org.osmf.events.SeekEvent")]
public class SeekTrait extends MediaTraitBase
{
private var _timeTrait:TimeTrait;
private var _seeking:Boolean;
public function SeekTrait(timeTrait:TimeTrait)
{
super(MediaTraitType.SEEK);
this._timeTrait = timeTrait;
}
final public function get seeking() : Boolean
{
return this._seeking;
}
final public function seek(time:Number) : void
{
if(this.canSeekTo(time))
{
this.setSeeking(true,time);
}
}
public function canSeekTo(time:Number) : Boolean
{
return Boolean(this._timeTrait) ? isNaN(time) == false && time >= 0 && (time <= this._timeTrait.duration || time <= this._timeTrait.currentTime) : false;
}
final protected function get timeTrait() : TimeTrait
{
return this._timeTrait;
}
final protected function set timeTrait(value:TimeTrait) : void
{
this._timeTrait = value;
}
final protected function setSeeking(value:Boolean, time:Number) : void
{
this.seekingChangeStart(value,time);
this._seeking = value;
this.seekingChangeEnd(time);
}
protected function seekingChangeStart(newSeeking:Boolean, time:Number) : void
{
}
protected function seekingChangeEnd(time:Number) : void
{
dispatchEvent(new SeekEvent(SeekEvent.SEEKING_CHANGE,false,false,this.seeking,time));
}
}
}
@@ -0,0 +1,96 @@
package org.osmf.traits
{
import org.osmf.events.TimeEvent;
[Event(name="complete",type="org.osmf.events.TimeEvent")]
[Event(name="durationChange",type="org.osmf.events.TimeEvent")]
public class TimeTrait extends MediaTraitBase
{
private var _duration:Number;
private var _currentTime:Number;
public function TimeTrait(duration:Number = NaN)
{
super(MediaTraitType.TIME);
this._duration = duration;
}
public function get duration() : Number
{
return this._duration;
}
public function get currentTime() : Number
{
return this._currentTime;
}
protected function durationChangeStart(newDuration:Number) : void
{
}
protected function durationChangeEnd(oldDuration:Number) : void
{
dispatchEvent(new TimeEvent(TimeEvent.DURATION_CHANGE,false,false,this._duration));
}
protected function currentTimeChangeStart(newCurrentTime:Number) : void
{
}
protected function currentTimeChangeEnd(oldCurrentTime:Number) : void
{
}
protected function signalComplete() : void
{
dispatchEvent(new TimeEvent(TimeEvent.COMPLETE));
}
final protected function setCurrentTime(value:Number) : void
{
var oldCurrentTime:Number = NaN;
if(!isNaN(value))
{
if(!isNaN(this._duration))
{
value = Math.min(value,this._duration);
}
else
{
value = 0;
}
}
if(this._currentTime != value && !(isNaN(this._currentTime) && isNaN(value)))
{
this.currentTimeChangeStart(value);
oldCurrentTime = this._currentTime;
this._currentTime = value;
this.currentTimeChangeEnd(oldCurrentTime);
if(this.currentTime == this.duration && this.currentTime > 0)
{
this.signalComplete();
}
}
}
final protected function setDuration(value:Number) : void
{
var oldDuration:Number = NaN;
if(this._duration != value)
{
this.durationChangeStart(value);
oldDuration = this._duration;
this._duration = value;
this.durationChangeEnd(oldDuration);
if(!isNaN(this._currentTime) && !isNaN(this._duration) && this._currentTime > this._duration)
{
this.setCurrentTime(this.duration);
}
}
}
}
}
@@ -0,0 +1,204 @@
package org.osmf.traits
{
import flash.events.Event;
import flash.events.EventDispatcher;
import flash.utils.Dictionary;
import org.osmf.events.AudioEvent;
import org.osmf.events.BufferEvent;
import org.osmf.events.DRMEvent;
import org.osmf.events.DVREvent;
import org.osmf.events.DisplayObjectEvent;
import org.osmf.events.DynamicStreamEvent;
import org.osmf.events.LoadEvent;
import org.osmf.events.MediaElementEvent;
import org.osmf.events.PlayEvent;
import org.osmf.events.SeekEvent;
import org.osmf.events.TimeEvent;
import org.osmf.media.MediaElement;
[Event(name="isRecordingChange",type="org.osmf.events.DVREvent")]
[Event(name="drmStateChange",type="org.osmf.events.DRMEvent")]
[Event(name="loadStateChange",type="org.osmf.events.LoadEvent")]
[Event(name="bytesTotalChange",type="org.osmf.events.LoadEvent")]
[Event(name="bufferTimeChange",type="org.osmf.events.BufferEvent")]
[Event(name="bufferingChange",type="org.osmf.events.BufferEvent")]
[Event(name="autoSwitchChange",type="org.osmf.events.DynamicStreamEvent")]
[Event(name="numDynamicStreamsChange",type="org.osmf.events.DynamicStreamEvent")]
[Event(name="switchingChange",type="org.osmf.events.DynamicStreamEvent")]
[Event(name="seekingChange",type="org.osmf.events.SeekEvent")]
[Event(name="mediaSizeChange",type="org.osmf.events.DisplayObjectEvent")]
[Event(name="displayObjectChange",type="org.osmf.events.DisplayObjectEvent")]
[Event(name="canPauseChange",type="org.osmf.events.PlayEvent")]
[Event(name="playStateChange",type="org.osmf.events.PlayEvent")]
[Event(name="panChange",type="org.osmf.events.AudioEvent")]
[Event(name="mutedChange",type="org.osmf.events.AudioEvent")]
[Event(name="volumeChange",type="org.osmf.events.AudioEvent")]
[Event(name="complete",type="org.osmf.events.TimeEvent")]
[Event(name="durationChange",type="org.osmf.events.TimeEvent")]
public class TraitEventDispatcher extends EventDispatcher
{
private static var eventMaps:Dictionary;
private var _mediaElement:MediaElement;
public function TraitEventDispatcher()
{
super();
if(eventMaps == null)
{
eventMaps = new Dictionary();
eventMaps[TimeEvent.DURATION_CHANGE] = MediaTraitType.TIME;
eventMaps[TimeEvent.COMPLETE] = MediaTraitType.TIME;
eventMaps[PlayEvent.PLAY_STATE_CHANGE] = MediaTraitType.PLAY;
eventMaps[PlayEvent.CAN_PAUSE_CHANGE] = MediaTraitType.PLAY;
eventMaps[AudioEvent.VOLUME_CHANGE] = MediaTraitType.AUDIO;
eventMaps[AudioEvent.MUTED_CHANGE] = MediaTraitType.AUDIO;
eventMaps[AudioEvent.PAN_CHANGE] = MediaTraitType.AUDIO;
eventMaps[SeekEvent.SEEKING_CHANGE] = MediaTraitType.SEEK;
eventMaps[DynamicStreamEvent.SWITCHING_CHANGE] = MediaTraitType.DYNAMIC_STREAM;
eventMaps[DynamicStreamEvent.AUTO_SWITCH_CHANGE] = MediaTraitType.DYNAMIC_STREAM;
eventMaps[DynamicStreamEvent.NUM_DYNAMIC_STREAMS_CHANGE] = MediaTraitType.DYNAMIC_STREAM;
eventMaps[DisplayObjectEvent.DISPLAY_OBJECT_CHANGE] = MediaTraitType.DISPLAY_OBJECT;
eventMaps[DisplayObjectEvent.MEDIA_SIZE_CHANGE] = MediaTraitType.DISPLAY_OBJECT;
eventMaps[LoadEvent.LOAD_STATE_CHANGE] = MediaTraitType.LOAD;
eventMaps[LoadEvent.BYTES_LOADED_CHANGE] = MediaTraitType.LOAD;
eventMaps[LoadEvent.BYTES_TOTAL_CHANGE] = MediaTraitType.LOAD;
eventMaps[BufferEvent.BUFFERING_CHANGE] = MediaTraitType.BUFFER;
eventMaps[BufferEvent.BUFFER_TIME_CHANGE] = MediaTraitType.BUFFER;
eventMaps[BufferEvent.BUFFER_LENGTH_CHANGE] = MediaTraitType.BUFFER;
eventMaps[DRMEvent.DRM_STATE_CHANGE] = MediaTraitType.DRM;
eventMaps[DVREvent.IS_RECORDING_CHANGE] = MediaTraitType.DVR;
}
}
public function get media() : MediaElement
{
return this._mediaElement;
}
public function set media(value:MediaElement) : void
{
var traitType:String = null;
if(value != this._mediaElement)
{
if(this._mediaElement != null)
{
this._mediaElement.removeEventListener(MediaElementEvent.TRAIT_ADD,this.onTraitAdd);
this._mediaElement.removeEventListener(MediaElementEvent.TRAIT_REMOVE,this.onTraitRemove);
for each(traitType in this._mediaElement.traitTypes)
{
this.onTraitChanged(traitType,false);
}
}
this._mediaElement = value;
if(this._mediaElement != null)
{
this._mediaElement.addEventListener(MediaElementEvent.TRAIT_ADD,this.onTraitAdd);
this._mediaElement.addEventListener(MediaElementEvent.TRAIT_REMOVE,this.onTraitRemove);
for each(traitType in this._mediaElement.traitTypes)
{
this.onTraitChanged(traitType,true);
}
}
}
}
override public function addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false) : void
{
var hadEventListener:Boolean = hasEventListener(type);
super.addEventListener(type,listener,useCapture,priority,useWeakReference);
if(Boolean(this._mediaElement) && Boolean(!hadEventListener) && eventMaps[type] != undefined)
{
this.changeListeners(true,eventMaps[type],type);
}
}
override public function removeEventListener(type:String, listener:Function, useCapture:Boolean = false) : void
{
super.removeEventListener(type,listener,useCapture);
if(Boolean(this._mediaElement) && Boolean(!hasEventListener(type)) && eventMaps[type] != undefined)
{
this.changeListeners(false,eventMaps[type],type);
}
}
private function onTraitAdd(event:MediaElementEvent) : void
{
this.onTraitChanged(event.traitType,true);
}
private function onTraitRemove(event:MediaElementEvent) : void
{
this.onTraitChanged(event.traitType,false);
}
private function onTraitChanged(traitType:String, add:Boolean) : void
{
switch(traitType)
{
case MediaTraitType.TIME:
this.changeListeners(add,traitType,TimeEvent.DURATION_CHANGE);
this.changeListeners(add,traitType,TimeEvent.COMPLETE);
break;
case MediaTraitType.PLAY:
this.changeListeners(add,traitType,PlayEvent.PLAY_STATE_CHANGE);
this.changeListeners(add,traitType,PlayEvent.CAN_PAUSE_CHANGE);
break;
case MediaTraitType.AUDIO:
this.changeListeners(add,traitType,AudioEvent.VOLUME_CHANGE);
this.changeListeners(add,traitType,AudioEvent.MUTED_CHANGE);
this.changeListeners(add,traitType,AudioEvent.PAN_CHANGE);
break;
case MediaTraitType.SEEK:
this.changeListeners(add,traitType,SeekEvent.SEEKING_CHANGE);
break;
case MediaTraitType.DYNAMIC_STREAM:
this.changeListeners(add,traitType,DynamicStreamEvent.SWITCHING_CHANGE);
this.changeListeners(add,traitType,DynamicStreamEvent.AUTO_SWITCH_CHANGE);
this.changeListeners(add,traitType,DynamicStreamEvent.NUM_DYNAMIC_STREAMS_CHANGE);
break;
case MediaTraitType.DISPLAY_OBJECT:
this.changeListeners(add,traitType,DisplayObjectEvent.DISPLAY_OBJECT_CHANGE);
this.changeListeners(add,traitType,DisplayObjectEvent.MEDIA_SIZE_CHANGE);
break;
case MediaTraitType.LOAD:
this.changeListeners(add,traitType,LoadEvent.LOAD_STATE_CHANGE);
this.changeListeners(add,traitType,LoadEvent.BYTES_TOTAL_CHANGE);
this.changeListeners(add,traitType,LoadEvent.BYTES_LOADED_CHANGE);
break;
case MediaTraitType.BUFFER:
this.changeListeners(add,traitType,BufferEvent.BUFFERING_CHANGE);
this.changeListeners(add,traitType,BufferEvent.BUFFER_TIME_CHANGE);
this.changeListeners(add,traitType,BufferEvent.BUFFER_LENGTH_CHANGE);
break;
case MediaTraitType.DRM:
this.changeListeners(add,traitType,DRMEvent.DRM_STATE_CHANGE);
break;
case MediaTraitType.DVR:
this.changeListeners(add,traitType,DVREvent.IS_RECORDING_CHANGE);
}
}
private function changeListeners(add:Boolean, traitType:String, event:String) : void
{
if(this._mediaElement.getTrait(traitType) != null)
{
if(add && hasEventListener(event))
{
this._mediaElement.getTrait(traitType).addEventListener(event,this.redispatchEvent);
}
else
{
this._mediaElement.getTrait(traitType).removeEventListener(event,this.redispatchEvent);
}
}
}
private function redispatchEvent(event:Event) : void
{
dispatchEvent(event.clone());
}
}
}