VideoPlayer
| Kind of class: | class |
|---|---|
| Inherits from: | MovieClip |
| Classpath: | mx.video.VideoPlayer |
| File last modified: | Tuesday, 18 December 2007, 16:08:45 |
Event dispatched when NetConnection is closed,
whether by being timed out or by calling close() API.
Only dispatched with RTMP streams, never HTTP. Event Object has
properties state and playheadTime.
| Event | "close" |
|---|
Summary
- version : String
- shortVersion : String
- DISCONNECTED : String
- STOPPED : String
- PLAYING : String
- PAUSED : String
- BUFFERING : String
- LOADING : String
- CONNECTION_ERROR : String
- REWINDING : String
- SEEKING : String
- RESIZING : String
- EXEC_QUEUED_CMD : String
- BUFFER_EMPTY : String
- BUFFER_FULL : String
- BUFFER_FLUSH : String
- DEFAULT_INCMANAGER : String
- DEFAULT_UPDATE_TIME_INTERVAL : Number
- DEFAULT_UPDATE_PROGRESS_INTERVAL : Number
- DEFAULT_IDLE_TIMEOUT_INTERVAL : Number
- AUTO_RESIZE_INTERVAL : Number
- AUTO_RESIZE_PLAYHEAD_TIMEOUT
- AUTO_RESIZE_METADATA_DELAY_MAX : Number
- FINISH_AUTO_RESIZE_INTERVAL : Number
- RTMP_DO_STOP_AT_END_INTERVAL : Number
- RTMP_DO_SEEK_INTERVAL : Number
- HTTP_DO_SEEK_INTERVAL : Number
- HTTP_DO_SEEK_MAX_COUNT : Number
- CLOSE_NS_INTERVAL : Number
- HTTP_DELAYED_BUFFERING_INTERVAL : Number
- PLAY : Number
- LOAD : Number
- PAUSE : Number
- STOP : Number
- SEEK : Number
- _state : String
- _cachedState : String
- _bufferState : String
- _sawPlayStop : Boolean
- _cachedPlayheadTime : Number
- _metadata : Object
- _startingPlay : Boolean
- _invalidSeekTime : Boolean
- _invalidSeekRecovery : Boolean
- _readyDispatched : Boolean
- _autoResizeDone : Boolean
- _lastUpdateTime : Number
- _sawSeekNotify : Boolean
- _video : Video
- _ncMgr : INCManager
- ncMgrClassName : String
- _ns : NetStream
- _currentPos : Number
- _atEnd : Boolean
- _streamLength : Number
- _autoSize : Boolean
- _aspectRatio : Boolean
- _autoPlay : Boolean
- _autoRewind : Boolean
- _contentPath : String
- _bufferTime : Number
- _isLive : Boolean
- _volume : Number
- _sound : Sound
- __visible : Boolean
- _hiddenForResize : Boolean
- _hiddenForResizeMetadataDelay : Number
- _hiddenRewindPlayheadTime : Number
- _videoWidth : Number
- _videoHeight : Number
- _prevVideoWidth : Number
- _prevVideoHeight : Number
- _updateTimeIntervalID : Number
- _updateTimeInterval : Number
- _updateProgressIntervalID : Number
- _updateProgressInterval : Number
- _idleTimeoutIntervalID : Number
- _idleTimeoutInterval : Number
- _autoResizeIntervalID : Number
- _rtmpDoStopAtEndIntervalID : Number
- _rtmpDoSeekIntervalID : Number
- _httpDoSeekIntervalID : Number
- _httpDoSeekCount : Number
- _finishAutoResizeIntervalID : Number
- _delayedBufferingIntervalID : Number
- _delayedBufferingInterval : Number
- _cmdQueue : Array
- addEventListener : Function
- removeEventListener : Function
- dispatchEvent : Function
- dispatchQueue : Function
- x : Number
- y : Number
- scaleX : Number
- 100 is standard scale
- scaleY : Number
- 100 is standard scale
- width : Number
- height : Number
- videoWidth
- videoHeight
- visible : Boolean
- autoSize : Boolean
- autoRewind : Boolean
- playheadTime : Number
- url : String
- volume : Number
- transform : Object
- isRTMP : Boolean
- True if stream is RTMP download (streaming from Flash
- isLive : Boolean
- state : String
- Get state.
- stateResponsive : Boolean
- Read only.
- bytesLoaded : Number
- bytesTotal : Number
- totalTime : Number
- bufferTime : Number
- idleTimeout : Number
- playheadUpdateInterval : Number
- progressInterval : Number
- ncMgr : INCManager
- metadata
- setSize (w:Number, h:Number) : Void
- setScale (xs:Number, ys:Number)
- play (url:String, isLive:Boolean, totalTime:Number) : Void
- load (url:String, isLive:Boolean, totalTime:Number) : Void
- _load (url:String, isLive:Boolean, totalTime:Number) : Void
- pause : Void
- stop : Void
- seek (time:Number) : Void
- close : Void
- doUpdateTime : Void
- doUpdateProgress : Void
- rtmpOnStatus (info:Object) : Void
- httpOnStatus (info:Object) : Void
- ncConnected : Void
- ncReconnected : Void
- setState (s:String) : Void
- sets state, dispatches event, execs queued commands.
- setStateFromCachedState : Void
- Sets state to _cachedState if the _cachedState is PLAYING,
- createINCManager : Void
- creates our implementatino of the INCManager.
- rtmpDoStopAtEnd (force:Boolean) : Void
- rtmpDoSeek : Void
- httpDoStopAtEnd : Void
- httpDoSeek : Void
- closeNS (updateCurrentPos:Boolean) : Void
- doDelayedBuffering : Void
- _pause (doPause:Boolean) : Void
- Wrapper for NetStream.pause().
- _play : Void
- Wrapper for NetStream.play().
- _seek (time:Number) : Void
- Wrapper for NetStream.seek().
- isXnOK : Boolean
- Gets whether connected to a stream.
- startAutoResize
- doAutoResize : Void
- finishAutoResize : Void
- _createStream : Void
- _setUpStream : Void
- doIdleTimeout : Void
- flushQueuedCmds : Void
- Dumps all queued commands without executing them
- execQueuedCmds : Void
- Executes as many queued commands as possible, obviously
- queueCmd (type:Number, url:String, isLive:Boolean, time:Number) : Void
- onMetaData (info:Object) : Void
- handles NetStream.onMetaData callback
- onCuePoint (info:Object) : Void
- handles NetStream.onCuePoint callback
Constructor
Class properties
AUTO_RESIZE_INTERVAL
AUTO_RESIZE_METADATA_DELAY_MAX
AUTO_RESIZE_PLAYHEAD_TIMEOUT
BUFFER_EMPTY
BUFFER_FLUSH
BUFFER_FULL
BUFFERING
State constant. State entered immediately afterplay() or load() is called.
This is a responsive state.
CLOSE_NS_INTERVAL
CONNECTION_ERROR
State constant. Stream attempted to load was unable to load
for some reason. Could be no connection to server, stream not
found, etc.
This is a unresponsive state.
DEFAULT_IDLE_TIMEOUT_INTERVAL
DEFAULT_INCMANAGER
Set this property to the name of your custom class to
make all VideoPlayer objects created use that class as the
default INCManager implementation. The default value is
"mx.video.NCManager".
DEFAULT_UPDATE_PROGRESS_INTERVAL
DEFAULT_UPDATE_TIME_INTERVAL
DISCONNECTED
State constant. This is the state when the VideoPlayer is
constructed and when the stream is closed by a call toclose() or timed out on idle.
This is a responsive state.
- state
- stateResponsive
- connected
- idleTimeout
- close
EXEC_QUEUED_CMD
State constant. State during execution of queued command.
There will never get a "stateChange" event notification with
this state; it is internal only.
This is a unresponsive state.
FINISH_AUTO_RESIZE_INTERVAL
HTTP_DELAYED_BUFFERING_INTERVAL
HTTP_DO_SEEK_INTERVAL
HTTP_DO_SEEK_MAX_COUNT
LOAD
LOADING
State constant. State entered immediately afterplay() or load() is called.
This is a unresponsive state.
PAUSE
PAUSED
State constant. FLV is loaded, but play is paused.
This state is entered when pause() is
called or when load() is called.
This is a responsive state.
PLAY
PLAYING
State constant. FLV is loaded and is playing.
This state is entered when play()is called.
This is a responsive state.
RESIZING
State constant. State entered during autoresize.
This is a unresponsive state.
- autoSize
- maintainAspectRatio
- state
- stateResponsive
REWINDING
State constant. State entered during a autorewind triggered
by a stop. After rewind is complete, the state will beSTOPPED.
This is a unresponsive state.
RTMP_DO_SEEK_INTERVAL
RTMP_DO_STOP_AT_END_INTERVAL
SEEK
SEEKING
State constant. State entered after seek()is called.
This is a unresponsive state.
shortVersion
STOP
STOPPED
State constant. FLV is loaded and play is stopped. This state
is entered when stop() is called and when the
playhead reaches the end of the stream.
This is a responsive state.
version
Instance properties
__visible
_aspectRatio
_atEnd
_autoPlay
If true, then video plays immediately, if false waits forplay to be called. Set to true if stream is
loaded with call to play(), false if loaded
by call to load().
Even if _autoPlay is set to false, we will start
loading the video after initialize() is called.
In the case of FCS, this means creating the stream and loading
the first frame to display (and loading more ifautoSize or aspectRatio is true). In
the case of HTTP download, we will start downloading the stream
and show the first frame.
_autoResizeDone
_autoResizeIntervalID
_autoRewind
_autoSize
_bufferState
_bufferTime
_cachedPlayheadTime
_cachedState
_cmdQueue
_contentPath
_currentPos
_delayedBufferingInterval
_delayedBufferingIntervalID
_finishAutoResizeIntervalID
_httpDoSeekCount
_httpDoSeekIntervalID
_idleTimeoutInterval
_idleTimeoutIntervalID
_invalidSeekRecovery
_invalidSeekTime
_isLive
_lastUpdateTime
_metadata
_ncMgr
_ns
_prevVideoHeight
_prevVideoWidth
_readyDispatched
_rtmpDoSeekIntervalID
_rtmpDoStopAtEndIntervalID
_sawPlayStop
_sawSeekNotify
_sound
_startingPlay
_state
_streamLength
_updateProgressInterval
_updateProgressIntervalID
_updateTimeInterval
_updateTimeIntervalID
_video
_videoHeight
_videoWidth
_volume
addEventListener
autoRewind
Determines whether video aspect ratio is maintained. If
this is set from false to true and
autoSize</code isor by
false after an FLV has been loaded, an automatic resize will
start immediately.</p>
@see #autoSize
/ public function get maintainAspectRatio():Boolean { return _aspectRatio; } public function set maintainAspectRatio(flag:Boolean):Void { if (_aspectRatio != flag) { _aspectRatio = flag; if (_aspectRatio && !_autoSize) { startAutoResize(); } } } /**
<p>Determines whether the FLV is rewound to the first frame
when play stops, either by calling <code>stop()
reaching the end of the stream. Meaningless for live streams.
autoSize
Determines whether the instance is automatically resized to
the source dimensions. If this is set from false to true after
an FLV has been loaded, an automatic resize will start
immediately.
bufferTime
Sets number of seconds to buffer in memory before playing
back stream. For slow connections streaming over rtmp, it is
important to increase this from the default. Default is
0.1
bytesLoaded
property bytesLoaded, read only. Returns -1 when there
is no stream, when the stream is FCS or if the information
is not yet available. Return value only useful for HTTP
download.
bytesTotal
property bytesTotal, read only. Returns -1 when there
is no stream, when the stream is FCS or if the information
is not yet available. Return value only useful for HTTP
download.
dispatchEvent
dispatchQueue
height
Height of video. Not same as Video.height, that is videoHeight.
idleTimeout
Property idleTimeout, which is amount of time in
milliseconds before connection is idle (playing is paused
or stopped) before connection to the FCS server is
terminated. Has no effect to HTTP download of FLV.
If set when stream already idle, restarts idle timeout with
new value.
isLive
True if stream is live, read only. isLive only makes sense when
streaming from FVSS or FCS, value is ignored when doing http
download.
isRTMP
Communication Server), read only.
metadata
Read only. Object received by call to onMetaData callback.
null if onMetaData callback has not been called since the last
load or play call. Always null with FLVs with no onMetaData
packet.
ncMgr
Access to instance of the class implementingINCManager. Read only.
One use case for this is that a customINCManager implementation may require custom
initialization.
ncMgrClassName
playheadTime
The current playhead time in seconds. Setting does a seek
and has all the restrictions of a seek.
The event "playheadUpdate" is dispatched when the playhead
time changes, including every .25 seconds while the FLV is
playing.
- The playhead position, measured in seconds since the start. Will return a fractional value.
playheadUpdateInterval
Property playheadUpdateInterval, which is amount of time
in milliseconds between each "playheadUpdate" event.
If set when stream is playing, will restart interval.
progressInterval
Property progressInterval, which is amount of time
in milliseconds between each "progress" event.
If set when stream is playing, will restart interval.
removeEventListener
state
load,play(), stop(),pause() and seek(). stateResponsive
unresponsive, calls to APIs
play(),load(), stop(),pause() and seek() will queue therequests for later, when the state changes to a responsive
one.
totalTime
property totalTime. read only. 0 or null or undefined
means that property was not passed into play() orload() and was unable to detect automatically, or
have not yet.
- The total running time of the FLV in seconds
transform
Provides direct access to theSound.setTransform() andSound.getTransform() APIs. to expose more sound
control. Must set property for changes to take effect, get
property just to get a copy of the current settings to tweak.
url
url of currently loaded (or loading) stream. Will be url
last sent to play() or load(), nullif no stream is loaded.
videoHeight
Source height of loaded FLV file. Read only. Returns
undefined if no information available yet.
videoWidth
Source width of loaded FLV file. Read only. Returns
undefined if no information available yet.
visible
Use this instead of _visible because we
sometimes do internal visibility management when doing an
autoresize.
volume
Volume control in range from 0 to 100.
- The most recent volume setting
width
Width of video instance. Not same as Video.width, that is videoWidth.
x
y
Instance methods
_createStream
Creates NetStream and does some basic
initialization.
_load
_pause
NetStream.pause(). Never callNetStream.pause() directly, always call thismethod because it does some other housekeeping.
_play
NetStream.play(). Never callNetStream.play() directly, always call thismethod because it does some other housekeeping.
_seek
NetStream.seek(). Never callNetStream.seek() directly, always callthis method because it does some other housekeeping.
_setUpStream
Does initialization after first connecting to the server
and creating the stream. Will get the stream duration from
the INCManager if it has it for us.
Starts resize if necessary, otherwise starts playing if
necessary, otherwise loads first frame of video. In http case,
starts progressive download in any case.
close
Forces close of video stream and FCS connection. Triggers
"close" event. Typically calling this directly is not necessary
because the idle timeout functionality will take care of this.
- idleTimeout
closeNS
Wrapper for NetStream.close(). Never callNetStream.close() directly, always call this
method because it does some other housekeeping.
createINCManager
INCManager.We put this off until we need to do it to give time for the
user to customize the
DEFAULT_INCMANAGERstatic variable. doAutoResize
Does the actual work of resetting the width and height.
Called on an interval which is stopped when width and height
of the Video object are not zero. Finishing the
resize is done in another method which is either called on a
interval set up here for live streams or on a
NetStream.Play.Stop event in rtmpOnStatus after
stream is rewound if it is not a live stream. Still need to
get a http solution.
doDelayedBuffering
We do a brief timer before entering BUFFERING state to avoid
quick switches from BUFFERING to PLAYING and back.
doIdleTimeout
ONLY CALL THIS WITH RTMP STREAMING
Only used for rtmp connections. When we pause or stop,
setup an interval to call this after a delay (see propertyidleTimeout). We do this to spare the server from
having a bunch of extra xns hanging around, although this needs
to be balanced with the load that creating connections puts on
the server, and keep in mind that FCS can be configured to
terminate idle connections on its own, which is a better way to
manage the issue.
doUpdateProgress
Called at interval determined byprogressInterval to send "progress" events.
Object dispatch starts when _load is called, ends
when all bytes downloaded or a network error of some kind
occurs, dispatched every .25 seconds by default.
doUpdateTime
Called on interval determined byplayheadUpdateInterval to send "playheadUpdate"
events. Events only sent when playhead is moving, sent every
.25 seconds by default.
execQueuedCmds
stopping when state becomes unresponsive.
finishAutoResize
Makes video visible, turns on sound and starts
playing if live or autoplay.
flushQueuedCmds
httpDoSeek
ONLY CALL THIS WITH HTTP PROGRESSIVE DOWNLOAD
If we get an onStatus callback indicating a seek is over,
but the playheadTime has not updated yet, then we wait on a
timer before moving forward.
httpDoStopAtEnd
ONLY CALL THIS WITH HTTP PROGRESSIVE DOWNLOAD
Call this when playing stops by hitting the end.
httpOnStatus
NetStream.onStatus callback for http. Handles
autorewind.
isXnOK
play() with no args, stop(),pause() and seek() will throwexceptions.
load
Similar to play, but causes the FLV to be loaded without
playing. Autoresizing will occur if appropriate and the first
frame of FLV will be shown (except for maybe not in the live case).
After initial load and autoresize, state will be PAUSED.
Takes same arguments as play(), but unlike that
method it is never acceptable to call load() with
no url. If you do, an Error will be thrown.
If player is in an unresponsive state, queues the request.
Defaults to false.
undefined to automatically detect length from metadata, server
or xml. If
INCManager.streamLength is not 0 ornull or undefined when
ncConnected is called, thenthat value will trump this one in any case. Default is
undefined.
- connected
- play
ncConnected
Called by INCManager after when connection complete or
failed after call to INCManager.connectToURL.
If connection failed, set INCManager.nc = nullbefore calling.
ncReconnected
Called by INCManager after when reconnection complete or
failed after call to INCManager.reconnect. If
connection failed, set INCManager.nc = nullbefore calling.
pause
Pauses video playback. If video is paused or stopped, has
no effect. To start playback again, call play().
Takes no parameters
If player is in an unresponsive state, queues the request.
Throws an exception if called when no stream is
connected. Use "stateChange" event andconnected property to determine when it is
safe to call this method.
If state is already stopped, pause is does nothing and state
remains stopped.
- connected
- stateResponsive
- play
play
Causes the video to play. Can be called while the video is
paused, stopped, or while the video is already playing. Call this
method with no arguments to play an already loaded video or pass
in a url to load a new stream.
If player is in an unresponsive state, queues the request.
Throws an exception if called with no args and no stream
is connected. Use "stateChange" event andconnected property to determine when it is
safe to call this method.
new FLV. If you have already loaded an FLV and want to continue
playing it, pass in
null.Defaults to false.
undefined to automatically detect length from metadata, server
or xml. If
INCManager.streamLength is not 0 ornull or undefined when
ncConnected is called, thenthat value will trump this one in any case. Default is
undefined.
- connected
- stateResponsive
- load
queueCmd
rtmpDoSeek
ONLY CALL THIS WITH RTMP STREAMING
Wait until time goes back to zero to leave rewinding state.
rtmpDoStopAtEnd
ONLY CALL THIS WITH RTMP STREAMING
Has the logic for what to do when we decide we have come to
a stop by coming to the end of an rtmp stream. There are a few
different ways we decide this has happened, and we sometimes
even set an interval that calls this function repeatedly to
check if the time is still changing, which is why it has its
own special function.
rtmpOnStatus
NetStream.onStatus callback for rtmp. Handles
automatic resizing, autorewind and buffering messaging.
seek
Seeks to given second in video. If video is playing,
continues playing from that point. If video is paused, seek to
that point and remain paused. If video is stopped, seek to
that point and enters paused state. Has no effect with live
streams.
If time is less than 0 or NaN, throws exeption. If time
is past the end of the stream, or past the amount of file
downloaded so far, then will attempt seek and when fails
will recover.
If player is in an unresponsive state, queues the request.
Throws an exception if called when no stream is
connected. Use "stateChange" event andconnected property to determine when it is
safe to call this method.
setScale
set scaleX and scaleY simultaneously. Since setting either
one can trigger an autoresize, this can be better than invoking
set width and set height individually.
If autoSize is true then this has no effect, since the player
sets its own dimensions. If maintainAspectRatio is true and
autoSize is false, then changing scaleX or scaleY will trigger an
autoresize.
- scaleX
- scaleY
setSize
set width and height simultaneously. Since setting either
one can trigger an autoresize, this can be better than invoking
set width and set height individually.
If autoSize is true then this has no effect, since the player
sets its own dimensions. If maintainAspectRatio is true and
autoSize is false, then changing width or height will trigger
an autoresize.
- width
- height
setState
this AFTER you do your work, because the state might change again after
you call this if you set it to a responsive state becasue of the call
to exec queued commands. If you set this to a responsive state and
then do more state based logic, check _state to make sure it did not
change out from under you.
setStateFromCachedState
PAUSED or BUFFERING, otherwise sets state to STOPPED.
startAutoResize
stop
Stops video playback. If autoRewind is set totrue, rewinds to first frame. If video is already
stopped, has no effect. To start playback again, callplay(). Takes no parameters
If player is in an unresponsive state, queues the request.
Throws an exception if called when no stream is
connected. Use "stateChange" event andconnected property to determine when it is
safe to call this method.
- connected
- stateResponsive
- autoRewind
- play