PageRenderTime 59ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/com/greensock/loading/VideoLoader.as

https://github.com/FrancisVarga/as3TweenLite
ActionScript | 600 lines | 284 code | 42 blank | 274 comment | 79 complexity | ccfcf1006d3fe8c1971639ac258d4889 MD5 | raw file
  1. /**
  2. * VERSION: 1.18
  3. * DATE: 2010-06-28
  4. * AS3
  5. * UPDATES AND DOCS AT: http://www.greensock.com/loadermax/
  6. **/
  7. package com.greensock.loading {
  8. import com.greensock.events.LoaderEvent;
  9. import com.greensock.loading.core.LoaderItem;
  10. import com.greensock.loading.display.ContentDisplay;
  11. import flash.display.Sprite;
  12. import flash.events.Event;
  13. import flash.events.NetStatusEvent;
  14. import flash.events.ProgressEvent;
  15. import flash.media.SoundTransform;
  16. import flash.media.Video;
  17. import flash.net.NetConnection;
  18. import flash.net.NetStream;
  19. import flash.utils.getTimer;
  20. [Event(name="httpStatus", type="com.greensock.events.LoaderEvent")]
  21. [Event(name="videoComplete", type="com.greensock.loading.VideoLoader")]
  22. [Event(name="videoBufferFull", type="com.greensock.loading.VideoLoader")]
  23. [Event(name="videoBufferEmpty", type="com.greensock.loading.VideoLoader")]
  24. [Event(name="videoPause", type="com.greensock.loading.VideoLoader")]
  25. [Event(name="videoPlay", type="com.greensock.loading.VideoLoader")]
  26. [Event(name="netStatus", type="flash.events.NetStatusEvent")]
  27. /**
  28. * Loads an FLV or MP4 video file using a NetStream and also provides convenient playback methods
  29. * and properties like <code>pauseVideo(), playVideo(), gotoVideoTime(), bufferProgress, playProgress, volume,
  30. * duration, metaData, </code> and <code>videoTime</code>. Just like ImageLoader and SWFLoader, VideoLoader's <code>content</code>
  31. * property refers to a <code>ContentDisplay</code> object (a Sprite) that gets created immediately so that you can
  32. * add it to the display list before the video has finished loading. You don't need to worry about creating
  33. * a NetConnection, a Video object, attaching the NetStream, or any of the typical hassles. VideoLoader can even
  34. * scale the video into the area you specify using scaleModes like <code>"stretch", "proportionalInside",
  35. * "proportionalOutside",</code> and more. It packs a surprising amount of functionality
  36. * into a very small amount of kb.<br /><br />
  37. *
  38. * <strong>OPTIONAL VARS PROPERTIES</strong><br />
  39. * The following special properties can be passed into the VideoLoader constructor via its <code>vars</code> parameter:<br />
  40. * <ul>
  41. * <li><strong> name : String</strong> - A name that is used to identify the VideoLoader instance. This name can be fed to the <code>LoaderMax.getLoader()</code> or <code>LoaderMax.getContent()</code> methods or traced at any time. Each loader's name should be unique. If you don't define one, a unique name will be created automatically, like "loader21".</li>
  42. * <li><strong> bufferTime : Number</strong> - The amount of time (in seconds) that should be buffered before the video can begin playing (set <code>autoPlay</code> to <code>false</code> to pause the video initially).</li>
  43. * <li><strong> autoPlay : Boolean</strong> - By default, the video will begin playing as soon as it has been adequately buffered, but to prevent it from playing initially, set <code>autoPlay</code> to <code>false</code>.</li>
  44. * <li><strong> smoothing : Boolean</strong> - When <code>smoothing</code> is <code>true</code> (the default), smoothing will be enabled for the video which typically leads to better scaling results.</li>
  45. * <li><strong> container : DisplayObjectContainer</strong> - A DisplayObjectContainer into which the <code>ContentDisplay</code> should be added immediately.</li>
  46. * <li><strong> width : Number</strong> - Sets the <code>ContentDisplay</code>'s <code>width</code> property (applied before rotation, scaleX, and scaleY).</li>
  47. * <li><strong> height : Number</strong> - Sets the <code>ContentDisplay</code>'s <code>height</code> property (applied before rotation, scaleX, and scaleY).</li>
  48. * <li><strong> centerRegistration : Boolean </strong> - if <code>true</code>, the registration point will be placed in the center of the <code>ContentDisplay</code> which can be useful if, for example, you want to animate its scale and have it grow/shrink from its center.</li>
  49. * <li><strong> scaleMode : String </strong> - When a <code>width</code> and <code>height</code> are defined, the <code>scaleMode</code> controls how the video will be scaled to fit the area. The following values are recognized (you may use the <code>com.greensock.layout.ScaleMode</code> constants if you prefer):
  50. * <ul>
  51. * <li><code>"stretch"</code> (the default) - The video will fill the width/height exactly.</li>
  52. * <li><code>"proportionalInside"</code> - The video will be scaled proportionally to fit inside the area defined by the width/height</li>
  53. * <li><code>"proportionalOutside"</code> - The video will be scaled proportionally to completely fill the area, allowing portions of it to exceed the bounds defined by the width/height.</li>
  54. * <li><code>"widthOnly"</code> - Only the width of the video will be adjusted to fit.</li>
  55. * <li><code>"heightOnly"</code> - Only the height of the video will be adjusted to fit.</li>
  56. * <li><code>"none"</code> - No scaling of the video will occur.</li>
  57. * </ul></li>
  58. * <li><strong> hAlign : String </strong> - When a <code>width</code> and <code>height</code> are defined, the <code>hAlign</code> determines how the video is horizontally aligned within that area. The following values are recognized (you may use the <code>com.greensock.layout.AlignMode</code> constants if you prefer):
  59. * <ul>
  60. * <li><code>"center"</code> (the default) - The video will be centered horizontally in the area</li>
  61. * <li><code>"left"</code> - The video will be aligned with the left side of the area</li>
  62. * <li><code>"right"</code> - The video will be aligned with the right side of the area</li>
  63. * </ul></li>
  64. * <li><strong> vAlign : String </strong> - When a <code>width</code> and <code>height</code> are defined, the <code>vAlign</code> determines how the video is vertically aligned within that area. The following values are recognized (you may use the <code>com.greensock.layout.AlignMode</code> constants if you prefer):
  65. * <ul>
  66. * <li><code>"center"</code> (the default) - The video will be centered vertically in the area</li>
  67. * <li><code>"top"</code> - The video will be aligned with the top of the area</li>
  68. * <li><code>"bottom"</code> - The video will be aligned with the bottom of the area</li>
  69. * </ul></li>
  70. * <li><strong> crop : Boolean</strong> - When a <code>width</code> and <code>height</code> are defined, setting <code>crop</code> to <code>true</code> will cause the video to be cropped within that area (by applying a <code>scrollRect</code> for maximum performance). This is typically useful when the <code>scaleMode</code> is <code>"proportionalOutside"</code> or <code>"none"</code> so that any parts of the video that exceed the dimensions defined by <code>width</code> and <code>height</code> are visually chopped off. Use the <code>hAlign</code> and <code>vAlign</code> special properties to control the vertical and horizontal alignment within the cropped area.</li>
  71. * <li><strong> x : Number</strong> - Sets the <code>ContentDisplay</code>'s <code>x</code> property (for positioning on the stage).</li>
  72. * <li><strong> y : Number</strong> - Sets the <code>ContentDisplay</code>'s <code>y</code> property (for positioning on the stage).</li>
  73. * <li><strong> scaleX : Number</strong> - Sets the <code>ContentDisplay</code>'s <code>scaleX</code> property.</li>
  74. * <li><strong> scaleY : Number</strong> - Sets the <code>ContentDisplay</code>'s <code>scaleY</code> property.</li>
  75. * <li><strong> rotation : Number</strong> - Sets the <code>ContentDisplay</code>'s <code>rotation</code> property.</li>
  76. * <li><strong> alpha : Number</strong> - Sets the <code>ContentDisplay</code>'s <code>alpha</code> property.</li>
  77. * <li><strong> visible : Boolean</strong> - Sets the <code>ContentDisplay</code>'s <code>visible</code> property.</li>
  78. * <li><strong> blendMode : String</strong> - Sets the <code>ContentDisplay</code>'s <code>blendMode</code> property.</li>
  79. * <li><strong> bgColor : uint </strong> - When a <code>width</code> and <code>height</code> are defined, a rectangle will be drawn inside the <code>ContentDisplay</code> immediately in order to ease the development process. It is transparent by default, but you may define a <code>bgColor</code> if you prefer.</li>
  80. * <li><strong> bgAlpha : Number </strong> - Controls the alpha of the rectangle that is drawn when a <code>width</code> and <code>height</code> are defined.</li>
  81. * <li><strong> volume : Number</strong> - A value between 0 and 1 indicating the volume at which the video should play (default is 1).</li>
  82. * <li><strong> repeat : int</strong> - Number of times that the video should repeat. To repeat indefinitely, use -1. Default is 0.</li>
  83. * <li><strong> checkPolicyFile : Boolean</strong> - If <code>true</code>, the VideoLoader will check for a crossdomain.xml file on the remote host (only useful when loading videos from other domains - see Adobe's docs for details about NetStream's <code>checkPolicyFile</code> property). </li>
  84. * <li><strong> estimatedDuration : Number</strong> - Estimated duration of the video in seconds. VideoLoader will only use this value until it receives the necessary metaData from the video in order to accurately determine the video's duration. You do not need to specify an <code>estimatedDuration</code>, but doing so can help make the playProgress and some other values more accurate (until the metaData has loaded). It can also make the <code>progress/bytesLoaded/bytesTotal</code> more accurate when a <code>estimatedDuration</code> is defined, particularly in <code>bufferMode</code>.</li>
  85. * <li><strong> deblocking : int</strong> - Indicates the type of filter applied to decoded video as part of post-processing. The default value is 0, which lets the video compressor apply a deblocking filter as needed. See Adobe's <code>flash.media.Video</code> class docs for details.</li>
  86. * <li><strong> bufferMode : Boolean </strong> - When <code>true</code>, the loader will report its progress only in terms of the video's buffer which can be very convenient if, for example, you want to display loading progress for the video's buffer or tuck it into a LoaderMax with other loaders and allow the LoaderMax to dispatch its <code>COMPLETE</code> event when the buffer is full instead of waiting for the whole file to download. When <code>bufferMode</code> is <code>true</code>, the VideoLoader will dispatch its <code>COMPLETE</code> event when the buffer is full as opposed to waiting for the entire video to load. You can toggle the <code>bufferMode</code> anytime. Please read the full <code>bufferMode</code> property ASDoc description below for details about how it affects things like <code>bytesTotal</code>.</li>
  87. * <li><strong> alternateURL : String</strong> - If you define an <code>alternateURL</code>, the loader will initially try to load from its original <code>url</code> and if it fails, it will automatically (and permanently) change the loader's <code>url</code> to the <code>alternateURL</code> and try again. Think of it as a fallback or backup <code>url</code>. It is perfectly acceptable to use the same <code>alternateURL</code> for multiple loaders (maybe a default image for various ImageLoaders for example).</li>
  88. * <li><strong> noCache : Boolean</strong> - If <code>noCache</code> is <code>true</code>, a "cacheBusterID" parameter will be appended to the url with a random set of numbers to prevent caching (don't worry, this info is ignored when you <code>getLoader()</code> or <code>getContent()</code> by url and when you're running locally)</li>
  89. * <li><strong> estimatedBytes : uint</strong> - Initially, the loader's <code>bytesTotal</code> is set to the <code>estimatedBytes</code> value (or <code>LoaderMax.defaultEstimatedBytes</code> if one isn't defined). Then, when the loader begins loading and it can accurately determine the bytesTotal, it will do so. Setting <code>estimatedBytes</code> is optional, but the more accurate the value, the more accurate your loaders' overall progress will be initially. If the loader will be inserted into a LoaderMax instance (for queue management), its <code>auditSize</code> feature can attempt to automatically determine the <code>bytesTotal</code> at runtime (there is a slight performance penalty for this, however - see LoaderMax's documentation for details).</li>
  90. * <li><strong> requireWithRoot : DisplayObject</strong> - LoaderMax supports <i>subloading</i>, where an object can be factored into a parent's loading progress. If you want LoaderMax to require this VideoLoader as part of its parent SWFLoader's progress, you must set the <code>requireWithRoot</code> property to your swf's <code>root</code>. For example, <code>var loader:VideoLoader = new VideoLoader("myScript.php", {name:"textData", requireWithRoot:this.root});</code></li>
  91. * <li><strong> autoDispose : Boolean</strong> - When <code>autoDispose</code> is <code>true</code>, the loader will be disposed immediately after it completes (it calls the <code>dispose()</code> method internally after dispatching its <code>COMPLETE</code> event). This will remove any listeners that were defined in the vars object (like onComplete, onProgress, onError, onInit). Once a loader is disposed, it can no longer be found with <code>LoaderMax.getLoader()</code> or <code>LoaderMax.getContent()</code> - it is essentially destroyed but its content is not unloaded (you must call <code>unload()</code> or <code>dispose(true)</code> to unload its content). The default <code>autoDispose</code> value is <code>false</code>.
  92. *
  93. * <br /><br />----EVENT HANDLER SHORTCUTS----</li>
  94. * <li><strong> onOpen : Function</strong> - A handler function for <code>LoaderEvent.OPEN</code> events which are dispatched when the loader begins loading. Make sure your onOpen function accepts a single parameter of type <code>LoaderEvent</code> (<code>com.greensock.events.LoaderEvent</code>).</li>
  95. * <li><strong> onInit : Function</strong> - A handler function for <code>Event.INIT</code> events which will be called when the video's metaData has been received and the video is placed into the <code>ContentDisplay</code>. Make sure your onInit function accepts a single parameter of type <code>Event</code> (flash.events.Event).</li>
  96. * <li><strong> onProgress : Function</strong> - A handler function for <code>LoaderEvent.PROGRESS</code> events which are dispatched whenever the <code>bytesLoaded</code> changes. Make sure your onProgress function accepts a single parameter of type <code>LoaderEvent</code> (<code>com.greensock.events.LoaderEvent</code>). You can use the LoaderEvent's <code>target.progress</code> to get the loader's progress value or use its <code>target.bytesLoaded</code> and <code>target.bytesTotal</code>.</li>
  97. * <li><strong> onComplete : Function</strong> - A handler function for <code>LoaderEvent.COMPLETE</code> events which are dispatched when the loader has finished loading successfully. Make sure your onComplete function accepts a single parameter of type <code>LoaderEvent</code> (<code>com.greensock.events.LoaderEvent</code>).</li>
  98. * <li><strong> onCancel : Function</strong> - A handler function for <code>LoaderEvent.CANCEL</code> events which are dispatched when loading is aborted due to either a failure or because another loader was prioritized or <code>cancel()</code> was manually called. Make sure your onCancel function accepts a single parameter of type <code>LoaderEvent</code> (<code>com.greensock.events.LoaderEvent</code>).</li>
  99. * <li><strong> onError : Function</strong> - A handler function for <code>LoaderEvent.ERROR</code> events which are dispatched whenever the loader experiences an error (typically an IO_ERROR). An error doesn't necessarily mean the loader failed, however - to listen for when a loader fails, use the <code>onFail</code> special property. Make sure your onError function accepts a single parameter of type <code>LoaderEvent</code> (<code>com.greensock.events.LoaderEvent</code>).</li>
  100. * <li><strong> onFail : Function</strong> - A handler function for <code>LoaderEvent.FAIL</code> events which are dispatched whenever the loader fails and its <code>status</code> changes to <code>LoaderStatus.FAILED</code>. Make sure your onFail function accepts a single parameter of type <code>LoaderEvent</code> (<code>com.greensock.events.LoaderEvent</code>).</li>
  101. * <li><strong> onIOError : Function</strong> - A handler function for <code>LoaderEvent.IO_ERROR</code> events which will also call the onError handler, so you can use that as more of a catch-all whereas <code>onIOError</code> is specifically for LoaderEvent.IO_ERROR events. Make sure your onIOError function accepts a single parameter of type <code>LoaderEvent</code> (<code>com.greensock.events.LoaderEvent</code>).</li>
  102. * </ul><br />
  103. *
  104. * @example Example AS3 code:<listing version="3.0">
  105. import com.greensock.loading.~~;
  106. import com.greensock.loading.display.~~;
  107. import com.greensock.~~;
  108. import com.greensock.events.LoaderEvent;
  109. //create a VideoLoader
  110. var loader:VideoLoader = new VideoLoader("assets/video.flv", {name:"myVideo", container:this, width:400, height:300, scaleMode:"proportionalInside", bgColor:0x000000, autoPlay:false, volume:0, requireWithRoot:this.root, estimatedBytes:75000});
  111. //start loading
  112. loader.load();
  113. //Or you could put the VideoLoader into a LoaderMax. Create one first...
  114. var queue:LoaderMax = new LoaderMax({name:"mainQueue", onProgress:progressHandler, onComplete:completeHandler, onError:errorHandler});
  115. //append the VideoLoader and several other loaders
  116. queue.append( loader );
  117. queue.append( new DataLoader("assets/data.txt", {name:"myText"}) );
  118. queue.append( new ImageLoader("assets/image1.png", {name:"myImage", estimatedBytes:3500}) );
  119. //start loading the LoaderMax queue
  120. queue.load();
  121. function progressHandler(event:LoaderEvent):void {
  122. trace("progress: " + event.target.progress);
  123. }
  124. function completeHandler(event:LoaderEvent):void {
  125. //play the video
  126. loader.playVideo();
  127. //tween the volume up to 1 over the course of 2 seconds.
  128. TweenLite.to(loader, 2, {volume:1});
  129. }
  130. function errorHandler(event:LoaderEvent):void {
  131. trace("error occured with " + event.target + ": " + event.text);
  132. }
  133. </listing>
  134. *
  135. * <b>Copyright 2010, GreenSock. All rights reserved.</b> This work is subject to the terms in <a href="http://www.greensock.com/terms_of_use.html">http://www.greensock.com/terms_of_use.html</a> or for corporate Club GreenSock members, the software agreement that was issued with the corporate membership.
  136. *
  137. * @author Jack Doyle, jack@greensock.com
  138. */
  139. public class VideoLoader extends LoaderItem {
  140. /** @private **/
  141. private static var _classActivated:Boolean = _activateClass("VideoLoader", VideoLoader, "flv,f4v,mp4,mov");
  142. /** Event type constant for when the video completes. **/
  143. public static const VIDEO_COMPLETE:String="videoComplete";
  144. /** Event type constant for when the video's buffer is full. **/
  145. public static const VIDEO_BUFFER_FULL:String="videoBufferFull";
  146. /** Event type constant for when the video's buffer is empty. **/
  147. public static const VIDEO_BUFFER_EMPTY:String="videoBufferEmpty";
  148. /** Event type constant for when the video is paused. **/
  149. public static const VIDEO_PAUSE:String="videoPause";
  150. /** Event type constant for when the video begins or resumes playing. **/
  151. public static const VIDEO_PLAY:String="videoPlay";
  152. /** Event type constant for when the video reaches a cue point in the playback of the NetStream. **/
  153. public static const VIDEO_CUE_POINT:String="videoCuePoint";
  154. /** @private **/
  155. protected var _ns:NetStream;
  156. /** @private **/
  157. protected var _nc:NetConnection;
  158. /** @private **/
  159. protected var _video:Video;
  160. /** @private **/
  161. protected var _sound:SoundTransform;
  162. /** @private **/
  163. protected var _videoPaused:Boolean;
  164. /** @private **/
  165. protected var _videoComplete:Boolean;
  166. /** @private **/
  167. protected var _forceTime:Number;
  168. /** @private **/
  169. protected var _duration:Number;
  170. /** @private **/
  171. protected var _pauseOnBufferFull:Boolean;
  172. /** @private **/
  173. protected var _volume:Number;
  174. /** @private **/
  175. protected var _sprite:Sprite;
  176. /** @private **/
  177. protected var _initted:Boolean;
  178. /** @private **/
  179. protected var _bufferMode:Boolean;
  180. /** @private **/
  181. protected var _repeatCount:uint;
  182. /** The metaData that was received from the video (contains information about its width, height, frame rate, etc.). See Adobe's docs for information about a NetStream's onMetaData callback. **/
  183. public var metaData:Object;
  184. /**
  185. * Constructor
  186. *
  187. * @param urlOrRequest The url (<code>String</code>) or <code>URLRequest</code> from which the loader should get its content.
  188. * @param vars An object containing optional configuration details. For example: <code>new VideoLoader("video/video.flv", {name:"myVideo", onComplete:completeHandler, onProgress:progressHandler})</code>.<br /><br />
  189. *
  190. * The following special properties can be passed into the constructor via the <code>vars</code> parameter:<br />
  191. * <ul>
  192. * <li><strong> name : String</strong> - A name that is used to identify the VideoLoader instance. This name can be fed to the <code>LoaderMax.getLoader()</code> or <code>LoaderMax.getContent()</code> methods or traced at any time. Each loader's name should be unique. If you don't define one, a unique name will be created automatically, like "loader21".</li>
  193. * <li><strong> bufferTime : Number</strong> - The amount of time (in seconds) that should be buffered before the video can begin playing (set <code>autoPlay</code> to <code>false</code> to pause the video initially).</li>
  194. * <li><strong> autoPlay : Boolean</strong> - By default, the video will begin playing as soon as it has been adequately buffered, but to prevent it from playing initially, set <code>autoPlay</code> to <code>false</code>.</li>
  195. * <li><strong> smoothing : Boolean</strong> - When <code>smoothing</code> is <code>true</code> (the default), smoothing will be enabled for the video which typically leads to better scaling results.</li>
  196. * <li><strong> container : DisplayObjectContainer</strong> - A DisplayObjectContainer into which the <code>ContentDisplay</code> should be added immediately.</li>
  197. * <li><strong> width : Number</strong> - Sets the <code>ContentDisplay</code>'s <code>width</code> property (applied before rotation, scaleX, and scaleY).</li>
  198. * <li><strong> height : Number</strong> - Sets the <code>ContentDisplay</code>'s <code>height</code> property (applied before rotation, scaleX, and scaleY).</li>
  199. * <li><strong> centerRegistration : Boolean </strong> - if <code>true</code>, the registration point will be placed in the center of the <code>ContentDisplay</code> which can be useful if, for example, you want to animate its scale and have it grow/shrink from its center.</li>
  200. * <li><strong> scaleMode : String </strong> - When a <code>width</code> and <code>height</code> are defined, the <code>scaleMode</code> controls how the video will be scaled to fit the area. The following values are recognized (you may use the <code>com.greensock.layout.ScaleMode</code> constants if you prefer):
  201. * <ul>
  202. * <li><code>"stretch"</code> (the default) - The video will fill the width/height exactly.</li>
  203. * <li><code>"proportionalInside"</code> - The video will be scaled proportionally to fit inside the area defined by the width/height</li>
  204. * <li><code>"proportionalOutside"</code> - The video will be scaled proportionally to completely fill the area, allowing portions of it to exceed the bounds defined by the width/height.</li>
  205. * <li><code>"widthOnly"</code> - Only the width of the video will be adjusted to fit.</li>
  206. * <li><code>"heightOnly"</code> - Only the height of the video will be adjusted to fit.</li>
  207. * <li><code>"none"</code> - No scaling of the video will occur.</li>
  208. * </ul></li>
  209. * <li><strong> hAlign : String </strong> - When a <code>width</code> and <code>height</code> are defined, the <code>hAlign</code> determines how the video is horizontally aligned within that area. The following values are recognized (you may use the <code>com.greensock.layout.AlignMode</code> constants if you prefer):
  210. * <ul>
  211. * <li><code>"center"</code> (the default) - The video will be centered horizontally in the area</li>
  212. * <li><code>"left"</code> - The video will be aligned with the left side of the area</li>
  213. * <li><code>"right"</code> - The video will be aligned with the right side of the area</li>
  214. * </ul></li>
  215. * <li><strong> vAlign : String </strong> - When a <code>width</code> and <code>height</code> are defined, the <code>vAlign</code> determines how the video is vertically aligned within that area. The following values are recognized (you may use the <code>com.greensock.layout.AlignMode</code> constants if you prefer):
  216. * <ul>
  217. * <li><code>"center"</code> (the default) - The video will be centered vertically in the area</li>
  218. * <li><code>"top"</code> - The video will be aligned with the top of the area</li>
  219. * <li><code>"bottom"</code> - The video will be aligned with the bottom of the area</li>
  220. * </ul></li>
  221. * <li><strong> crop : Boolean</strong> - When a <code>width</code> and <code>height</code> are defined, setting <code>crop</code> to <code>true</code> will cause the video to be cropped within that area (by applying a <code>scrollRect</code> for maximum performance). This is typically useful when the <code>scaleMode</code> is <code>"proportionalOutside"</code> or <code>"none"</code> so that any parts of the video that exceed the dimensions defined by <code>width</code> and <code>height</code> are visually chopped off. Use the <code>hAlign</code> and <code>vAlign</code> special properties to control the vertical and horizontal alignment within the cropped area.</li>
  222. * <li><strong> x : Number</strong> - Sets the <code>ContentDisplay</code>'s <code>x</code> property (for positioning on the stage).</li>
  223. * <li><strong> y : Number</strong> - Sets the <code>ContentDisplay</code>'s <code>y</code> property (for positioning on the stage).</li>
  224. * <li><strong> scaleX : Number</strong> - Sets the <code>ContentDisplay</code>'s <code>scaleX</code> property.</li>
  225. * <li><strong> scaleY : Number</strong> - Sets the <code>ContentDisplay</code>'s <code>scaleY</code> property.</li>
  226. * <li><strong> rotation : Number</strong> - Sets the <code>ContentDisplay</code>'s <code>rotation</code> property.</li>
  227. * <li><strong> alpha : Number</strong> - Sets the <code>ContentDisplay</code>'s <code>alpha</code> property.</li>
  228. * <li><strong> visible : Boolean</strong> - Sets the <code>ContentDisplay</code>'s <code>visible</code> property.</li>
  229. * <li><strong> blendMode : String</strong> - Sets the <code>ContentDisplay</code>'s <code>blendMode</code> property.</li>
  230. * <li><strong> bgColor : uint </strong> - When a <code>width</code> and <code>height</code> are defined, a rectangle will be drawn inside the <code>ContentDisplay</code> immediately in order to ease the development process. It is transparent by default, but you may define a <code>bgColor</code> if you prefer.</li>
  231. * <li><strong> bgAlpha : Number </strong> - Controls the alpha of the rectangle that is drawn when a <code>width</code> and <code>height</code> are defined.</li>
  232. * <li><strong> volume : Number</strong> - A value between 0 and 1 indicating the volume at which the video should play (default is 1).</li>
  233. * <li><strong> repeat : int</strong> - Number of times that the video should repeat. To repeat indefinitely, use -1. Default is 0.</li>
  234. * <li><strong> checkPolicyFile : Boolean</strong> - If <code>true</code>, the VideoLoader will check for a crossdomain.xml file on the remote host (only useful when loading videos from other domains - see Adobe's docs for details about NetStream's <code>checkPolicyFile</code> property). </li>
  235. * <li><strong> estimatedDuration : Number</strong> - Estimated duration of the video in seconds. VideoLoader will only use this value until it receives the necessary metaData from the video in order to accurately determine the video's duration. You do not need to specify an <code>estimatedDuration</code>, but doing so can help make the playProgress and some other values more accurate (until the metaData has loaded). It can also make the <code>progress/bytesLoaded/bytesTotal</code> more accurate when a <code>estimatedDuration</code> is defined, particularly in <code>bufferMode</code>.</li>
  236. * <li><strong> deblocking : int</strong> - Indicates the type of filter applied to decoded video as part of post-processing. The default value is 0, which lets the video compressor apply a deblocking filter as needed. See Adobe's <code>flash.media.Video</code> class docs for details.</li>
  237. * <li><strong> bufferMode : Boolean </strong> - When <code>true</code>, the loader will report its progress only in terms of the video's buffer which can be very convenient if, for example, you want to display loading progress for the video's buffer or tuck it into a LoaderMax with other loaders and allow the LoaderMax to dispatch its <code>COMPLETE</code> event when the buffer is full instead of waiting for the whole file to download. When <code>bufferMode</code> is <code>true</code>, the VideoLoader will dispatch its <code>COMPLETE</code> event when the buffer is full as opposed to waiting for the entire video to load. You can toggle the <code>bufferMode</code> anytime. Please read the full <code>bufferMode</code> property ASDoc description below for details about how it affects things like <code>bytesTotal</code>.</li>
  238. * <li><strong> alternateURL : String</strong> - If you define an <code>alternateURL</code>, the loader will initially try to load from its original <code>url</code> and if it fails, it will automatically (and permanently) change the loader's <code>url</code> to the <code>alternateURL</code> and try again. Think of it as a fallback or backup <code>url</code>. It is perfectly acceptable to use the same <code>alternateURL</code> for multiple loaders (maybe a default image for various ImageLoaders for example).</li>
  239. * <li><strong> noCache : Boolean</strong> - If <code>noCache</code> is <code>true</code>, a "cacheBusterID" parameter will be appended to the url with a random set of numbers to prevent caching (don't worry, this info is ignored when you <code>getLoader()</code> or <code>getContent()</code> by url and when you're running locally)</li>
  240. * <li><strong> estimatedBytes : uint</strong> - Initially, the loader's <code>bytesTotal</code> is set to the <code>estimatedBytes</code> value (or <code>LoaderMax.defaultEstimatedBytes</code> if one isn't defined). Then, when the loader begins loading and it can accurately determine the bytesTotal, it will do so. Setting <code>estimatedBytes</code> is optional, but the more accurate the value, the more accurate your loaders' overall progress will be initially. If the loader will be inserted into a LoaderMax instance (for queue management), its <code>auditSize</code> feature can attempt to automatically determine the <code>bytesTotal</code> at runtime (there is a slight performance penalty for this, however - see LoaderMax's documentation for details).</li>
  241. * <li><strong> requireWithRoot : DisplayObject</strong> - LoaderMax supports <i>subloading</i>, where an object can be factored into a parent's loading progress. If you want LoaderMax to require this VideoLoader as part of its parent SWFLoader's progress, you must set the <code>requireWithRoot</code> property to your swf's <code>root</code>. For example, <code>var loader:VideoLoader = new VideoLoader("myScript.php", {name:"textData", requireWithRoot:this.root});</code></li>
  242. * <li><strong> autoDispose : Boolean</strong> - When <code>autoDispose</code> is <code>true</code>, the loader will be disposed immediately after it completes (it calls the <code>dispose()</code> method internally after dispatching its <code>COMPLETE</code> event). This will remove any listeners that were defined in the vars object (like onComplete, onProgress, onError, onInit). Once a loader is disposed, it can no longer be found with <code>LoaderMax.getLoader()</code> or <code>LoaderMax.getContent()</code> - it is essentially destroyed but its content is not unloaded (you must call <code>unload()</code> or <code>dispose(true)</code> to unload its content). The default <code>autoDispose</code> value is <code>false</code>.
  243. *
  244. * <br /><br />----EVENT HANDLER SHORTCUTS----</li>
  245. * <li><strong> onOpen : Function</strong> - A handler function for <code>LoaderEvent.OPEN</code> events which are dispatched when the loader begins loading. Make sure your onOpen function accepts a single parameter of type <code>LoaderEvent</code> (<code>com.greensock.events.LoaderEvent</code>).</li>
  246. * <li><strong> onInit : Function</strong> - A handler function for <code>Event.INIT</code> events which will be called when the video's metaData has been received and the video is placed into the <code>ContentDisplay</code>. Make sure your onInit function accepts a single parameter of type <code>Event</code> (flash.events.Event).</li>
  247. * <li><strong> onProgress : Function</strong> - A handler function for <code>LoaderEvent.PROGRESS</code> events which are dispatched whenever the <code>bytesLoaded</code> changes. Make sure your onProgress function accepts a single parameter of type <code>LoaderEvent</code> (<code>com.greensock.events.LoaderEvent</code>). You can use the LoaderEvent's <code>target.progress</code> to get the loader's progress value or use its <code>target.bytesLoaded</code> and <code>target.bytesTotal</code>.</li>
  248. * <li><strong> onComplete : Function</strong> - A handler function for <code>LoaderEvent.COMPLETE</code> events which are dispatched when the loader has finished loading successfully. Make sure your onComplete function accepts a single parameter of type <code>LoaderEvent</code> (<code>com.greensock.events.LoaderEvent</code>).</li>
  249. * <li><strong> onCancel : Function</strong> - A handler function for <code>LoaderEvent.CANCEL</code> events which are dispatched when loading is aborted due to either a failure or because another loader was prioritized or <code>cancel()</code> was manually called. Make sure your onCancel function accepts a single parameter of type <code>LoaderEvent</code> (<code>com.greensock.events.LoaderEvent</code>).</li>
  250. * <li><strong> onError : Function</strong> - A handler function for <code>LoaderEvent.ERROR</code> events which are dispatched whenever the loader experiences an error (typically an IO_ERROR). An error doesn't necessarily mean the loader failed, however - to listen for when a loader fails, use the <code>onFail</code> special property. Make sure your onError function accepts a single parameter of type <code>LoaderEvent</code> (<code>com.greensock.events.LoaderEvent</code>).</li>
  251. * <li><strong> onFail : Function</strong> - A handler function for <code>LoaderEvent.FAIL</code> events which are dispatched whenever the loader fails and its <code>status</code> changes to <code>LoaderStatus.FAILED</code>. Make sure your onFail function accepts a single parameter of type <code>LoaderEvent</code> (<code>com.greensock.events.LoaderEvent</code>).</li>
  252. * <li><strong> onIOError : Function</strong> - A handler function for <code>LoaderEvent.IO_ERROR</code> events which will also call the onError handler, so you can use that as more of a catch-all whereas <code>onIOError</code> is specifically for LoaderEvent.IO_ERROR events. Make sure your onIOError function accepts a single parameter of type <code>LoaderEvent</code> (<code>com.greensock.events.LoaderEvent</code>).</li>
  253. * </ul>
  254. */
  255. public function VideoLoader(urlOrRequest:*, vars:Object=null) {
  256. super(urlOrRequest, vars);
  257. _type = "VideoLoader";
  258. _nc = new NetConnection();
  259. _nc.connect(null);
  260. _nc.addEventListener("asyncError", _failHandler, false, 0, true);
  261. _nc.addEventListener("securityError", _failHandler, false, 0, true);
  262. _ns = (this.vars.netStream is NetStream) ? this.vars.netStream : new NetStream(_nc);
  263. _ns.checkPolicyFile = Boolean(this.vars.checkPolicyFile == true);
  264. _ns.client = {onMetaData:_metaDataHandler, onCuePoint:_cuePointHandler};
  265. _ns.addEventListener(NetStatusEvent.NET_STATUS, _statusHandler, false, 0, true);
  266. _ns.addEventListener("ioError", _failHandler, false, 0, true);
  267. _ns.addEventListener("asyncError", _failHandler, false, 0, true);
  268. _video = _content = new Video(320, 160);
  269. _video.smoothing = Boolean(this.vars.smoothing != false);
  270. _video.deblocking = uint(this.vars.deblocking);
  271. _video.attachNetStream(_ns);
  272. _sound = _ns.soundTransform;
  273. _duration = ("estimatedDuration" in this.vars) ? Number(this.vars.estimatedDuration) : 200; //just set it to a high number so that the progress starts out low.
  274. _bufferMode = _preferEstimatedBytesInAudit = Boolean(this.vars.bufferMode == true);
  275. _ns.bufferTime = ("bufferTime" in this.vars) ? Number(this.vars.bufferTime) : 5;
  276. _videoPaused = _pauseOnBufferFull = Boolean(this.vars.autoPlay != true);
  277. this.volume = ("volume" in this.vars) ? Number(this.vars.volume) : 1;
  278. if (LoaderMax.contentDisplayClass is Class) {
  279. _sprite = new LoaderMax.contentDisplayClass(this);
  280. if (!_sprite.hasOwnProperty("rawContent")) {
  281. throw new Error("LoaderMax.contentDisplayClass must be set to a class with a 'rawContent' property, like com.greensock.loading.display.ContentDisplay");
  282. }
  283. } else {
  284. _sprite = new ContentDisplay(this);
  285. }
  286. }
  287. /** @private **/
  288. override protected function _load():void {
  289. _prepRequest();
  290. _repeatCount = 0;
  291. this.metaData = null;
  292. _pauseOnBufferFull = _videoPaused;
  293. if (_videoPaused) {
  294. _sound.volume = 0;
  295. _ns.soundTransform = _sound; //temporarily silence the audio because in some cases, the Flash Player will begin playing it for a brief second right before the buffer is full (we can't pause until then)
  296. } else {
  297. this.volume = _volume; //ensures the volume is back to normal in case it had been temporarily silenced while buffering
  298. }
  299. _sprite.addEventListener(Event.ENTER_FRAME, _enterFrameHandler);
  300. _videoComplete = _initted = false;
  301. _ns.play(_request.url);
  302. }
  303. /** @private scrubLevel: 0 = cancel, 1 = unload, 2 = dispose, 3 = flush **/
  304. override protected function _dump(scrubLevel:int=0, newStatus:int=0, suppressEvents:Boolean=false):void {
  305. _sprite.removeEventListener(Event.ENTER_FRAME, _enterFrameHandler);
  306. _sprite.removeEventListener(Event.ENTER_FRAME, _forceTimeHandler);
  307. _forceTime = NaN;
  308. _initted = false;
  309. this.metaData = null;
  310. if (scrubLevel != 2) {
  311. _ns.pause();
  312. try {
  313. _ns.close();
  314. } catch (error:Error) {
  315. }
  316. (_sprite as Object).rawContent = null;
  317. if (_video.parent != null) {
  318. _video.parent.removeChild(_video);
  319. }
  320. }
  321. if (scrubLevel >= 2) {
  322. if (scrubLevel == 3) {
  323. (_sprite as Object).dispose(false, false);
  324. }
  325. _nc.removeEventListener("asyncError", _failHandler);
  326. _nc.removeEventListener("securityError", _failHandler);
  327. _ns.removeEventListener(NetStatusEvent.NET_STATUS, _statusHandler);
  328. _ns.removeEventListener("ioError", _failHandler);
  329. _ns.removeEventListener("asyncError", _failHandler);
  330. (_sprite as Object).gcProtect = (scrubLevel == 3) ? null : _ns; //we need to reference the NetStream in the ContentDisplay before forcing garbage collection, otherwise gc kills the NetStream even if it's attached to the Video and is playing on the stage!
  331. _ns.client = {};
  332. _video = null;
  333. _ns = null;
  334. _nc = null;
  335. _sound = null;
  336. (_sprite as Object).loader = null;
  337. _sprite = null;
  338. }
  339. super._dump(scrubLevel, newStatus, suppressEvents);
  340. }
  341. /** @private Set inside ContentDisplay's or FlexContentDisplay's "loader" setter. **/
  342. public function setContentDisplay(contentDisplay:Sprite):void {
  343. _sprite = contentDisplay;
  344. }
  345. /** @private **/
  346. override protected function _calculateProgress():void {
  347. _cachedBytesLoaded = _ns.bytesLoaded;
  348. if (_cachedBytesLoaded > 1) {
  349. if (_bufferMode) {
  350. _cachedBytesTotal = _ns.bytesTotal * (_ns.bufferTime / _duration);
  351. if (_ns.bufferLength > 0) {
  352. _cachedBytesLoaded = (_ns.bufferLength / _ns.bufferTime) * _cachedBytesTotal;
  353. }
  354. if (_cachedBytesTotal <= _cachedBytesLoaded) {
  355. _cachedBytesTotal = (this.metaData == null) ? int(1.01 * _cachedBytesLoaded) + 1 : _cachedBytesLoaded;
  356. }
  357. } else {
  358. _cachedBytesTotal = _ns.bytesTotal;
  359. }
  360. _auditedSize = true;
  361. }
  362. _cacheIsDirty = false;
  363. }
  364. /**
  365. * Pauses playback of the video.
  366. *
  367. * @param event An optional event which simply makes it easier to use the method as a handler for mouse clicks or other events.
  368. *
  369. * @see #videoPaused
  370. * @see #gotoVideoTime()
  371. * @see #playVideo()
  372. * @see #videoTime
  373. * @see #playProgress
  374. **/
  375. public function pauseVideo(event:Event=null):void {
  376. this.videoPaused = true;
  377. }
  378. /**
  379. * Plays the video (if the buffer isn't full yet, playback will wait until the buffer is full).
  380. *
  381. * @param event An optional event which simply makes it easier to use the method as a handler for mouse clicks or other events.
  382. *
  383. * @see #videoPaused
  384. * @see #pauseVideo()
  385. * @see #gotoVideoTime()
  386. * @see #videoTime
  387. * @see #playProgress
  388. **/
  389. public function playVideo(event:Event=null):void {
  390. this.videoPaused = false;
  391. }
  392. /**
  393. * Attempts to jump to a certain time in the video. If the video hasn't downloaded enough to get to
  394. * the new time or if there is no keyframe at that time value, it will get as close as possible.
  395. * For example, to jump to exactly 3-seconds into the video and play from there:<br /><br /><code>
  396. *
  397. * loader.gotoVideoTime(3, true);<br /><br /></code>
  398. *
  399. * @param time The time (in seconds, offset from the very beginning) at which to place the virtual playhead on the video.
  400. * @param forcePlay If <code>true</code>, the video will resume playback immediately after seeking to the new position.
  401. * @see #pauseVideo()
  402. * @see #playVideo()
  403. * @see #videoTime
  404. * @see #playProgress
  405. **/
  406. public function gotoVideoTime(time:Number, forcePlay:Boolean=false):void {
  407. if (time > _duration) {
  408. time = _duration;
  409. }
  410. _ns.seek(time);
  411. _videoComplete = false;
  412. _forceTime = time;
  413. _sprite.addEventListener(Event.ENTER_FRAME, _forceTimeHandler, false, 0, true); //If for example, after a video has finished playing, we seek(0) the video and immediately check the playProgress, it returns 1 instead of 0 because it takes a short time to render the first frame and accurately reflect the _ns.time variable. So we use a single ENTER_FRAME to help us override the _ns.time value briefly.
  414. if (forcePlay) {
  415. playVideo();
  416. }
  417. }
  418. //---- EVENT HANDLERS ------------------------------------------------------------------------------------
  419. /** @private **/
  420. protected function _metaDataHandler(info:Object):void {
  421. this.metaData = info;
  422. _duration = info.duration;
  423. if (_ns.bufferTime > _duration) {
  424. _ns.bufferTime = _duration;
  425. }
  426. if ("width" in info) {
  427. _video.scaleX = info.width / 320;
  428. _video.scaleY = info.height / 160; //MUST use 160 as the base width and adjust the scale because of the way Flash reports width/height/scaleX/scaleY on Video objects (it can cause problems when using the scrollRect otherwise)
  429. }
  430. _initted = true;
  431. (_sprite as Object).rawContent = _video; //resizes it appropriately
  432. dispatchEvent(new LoaderEvent(LoaderEvent.INIT, this));
  433. }
  434. protected function _cuePointHandler(info:Object):void {
  435. dispatchEvent(new LoaderEvent(VIDEO_CUE_POINT, this));
  436. }
  437. /** @private **/
  438. protected function _statusHandler(event:NetStatusEvent):void {
  439. var code:String = event.info.code;
  440. if (_pauseOnBufferFull && (code == "NetStream.Play.Start" || this.bufferProgress == 1)) {
  441. _pauseOnBufferFull = false;
  442. this.volume = _volume; //Just resets the volume to where it should be because we temporarily made it silent during the buffer.
  443. gotoVideoTime(0, false);
  444. _ns.pause(); //don't just do this.videoPaused = true because sometimes Flash fires NetStream.Play.Start BEFORE the buffer is full, and we must check inside the videoPaused setter to see if if the buffer is full and wait to pause until it is.
  445. } else if (code == "NetStream.Play.Start") {
  446. dispatchEvent(new LoaderEvent(VIDEO_PLAY, this));
  447. }
  448. dispatchEvent(new LoaderEvent(NetStatusEvent.NET_STATUS, this, code));
  449. if (code == "NetStream.Play.Stop") {
  450. if (this.vars.repeat == -1 || uint(this.vars.repeat) > _repeatCount) {
  451. _repeatCount++;
  452. dispatchEvent(new LoaderEvent(VIDEO_COMPLETE, this));
  453. gotoVideoTime(0, true);
  454. } else {
  455. _videoComplete = true;
  456. this.videoPaused = true;
  457. dispatchEvent(new LoaderEvent(VIDEO_COMPLETE, this));
  458. }
  459. } else if (code == "NetStream.Buffer.Full") {
  460. dispatchEvent(new LoaderEvent(VIDEO_BUFFER_FULL, this));
  461. } else if (code == "NetStream.Buffer.Empty") {
  462. dispatchEvent(new LoaderEvent(VIDEO_BUFFER_EMPTY, this));
  463. } else if (code == "NetStream.Play.StreamNotFound" ||
  464. code == "NetConnection.Connect.Failed" ||
  465. code == "NetStream.Play.Failed" ||
  466. code == "NetStream.Play.FileStructureInvalid" ||
  467. code == "The MP4 doesn't contain any supported tracks") {
  468. _failHandler(new LoaderEvent(LoaderEvent.ERROR, this, code));
  469. }
  470. }
  471. /** @private **/
  472. protected function _enterFrameHandler(event:Event):void {
  473. var bl:uint = _cachedBytesLoaded;
  474. var bt:uint = _cachedBytesTotal;
  475. _calculateProgress();
  476. if (_cachedBytesLoaded == _cachedBytesTotal && _ns.bytesTotal > 5 && (this.metaData != null || getTimer() - _time > 5000)) { //make sure the metaData has been received because if the NetStream file is cached locally sometimes the bytesLoaded == bytesTotal BEFORE the metaData arrives. Or timeout after 5 seconds.
  477. _sprite.removeEventListener(Event.ENTER_FRAME, _enterFrameHandler);
  478. if (!_initted) {
  479. (_sprite as Object).rawContent = _video; //resizes it appropriately
  480. }
  481. _completeHandler(event);
  482. } else if (_dispatchProgress && (_cachedBytesLoaded / _cachedBytesTotal) != (bl / bt)) {
  483. dispatchEvent(new LoaderEvent(LoaderEvent.PROGRESS, this));
  484. }
  485. }
  486. /** @private **/
  487. override protected function _auditStreamHandler(event:Event):void {
  488. if (event is ProgressEvent && _bufferMode) {
  489. (event as ProgressEvent).bytesTotal *= (_ns.bufferTime / _duration);
  490. }
  491. super._auditStreamHandler(event);
  492. }
  493. /** @private **/
  494. protected function _forceTimeHandler(event:Event):void {
  495. _forceTime = NaN;
  496. event.target.removeEventListener(Event.ENTER_FRAME, _forceTimeHandler);
  497. }
  498. //---- GETTERS / SETTERS -------------------------------------------------------------------------
  499. /** A ContentDisplay (a Sprite) that contains a Video object to which the NetStream is attached. This ContentDisplay Sprite can be accessed immediately; you do not need to wait for the video to load. **/
  500. override public function get content():* {
  501. return _sprite;
  502. }
  503. /** The <code>Video</code> object to which the NetStream was attached (automatically created by VideoLoader internally) **/
  504. public function get rawContent():Video {
  505. return _content as Video;
  506. }
  507. /** The <code>NetStream</code> object used to load the video **/
  508. public function get netStream():NetStream {
  509. return _ns;
  510. }
  511. /** The playback status of the video: <code>true</code> if the video's playback is paused, <code>false</code> if it isn't. **/
  512. public function get videoPaused():Boolean {
  513. return _videoPaused;
  514. }
  515. public function set videoPaused(value:Boolean):void {
  516. var changed:Boolean = Boolean(value != _videoPaused);
  517. _videoPaused = value;
  518. if (_videoPaused) {
  519. //If we're trying to pause a NetStream that hasn't even been buffered yet, we run into problems where it won't load. So we need to set the _pauseOnBufferFull to true and then when it's buffered, it'll pause it at the beginning.
  520. if (this.bufferProgress < 1 && this.playProgress == 0) {
  521. _pauseOnBufferFull = true;
  522. _sound.volume = 0; //temporarily make it silent while buffering.
  523. _ns.soundTransform = _sound;
  524. } else {
  525. _pauseOnBufferFull = false;
  526. this.volume = _volume; //Just resets the volume to where it should be in case we temporarily made it silent during the buffer.
  527. _ns.pause();
  528. }
  529. if (changed) {
  530. dispatchEvent(new LoaderEvent(VIDEO_PAUSE, this));
  531. }
  532. } else {
  533. _pauseOnBufferFull = false;
  534. this.volume = _volume; //Just resets the volume to where it should be in case we temporarily made it silent during the buffer.
  535. _ns.resume();
  536. if (changed) {
  537. dispatchEvent(new LoaderEvent(VIDEO_PLAY, this));
  538. }
  539. }
  540. }
  541. /** A value between 0 and 1 describing the progress of the buffer (0 = not buffered at all, 0.5 = halfway buffered, and 1 = fully buffered). The buffer progress is in relation to the <code>bufferTime</code> which is 5 seconds by default or you can pass a custom value in through the <code>vars</code> parameter in the constructor like <code>{bufferTime:20}</code>. **/
  542. public function get bufferProgress():Number {
  543. if (uint(_ns.bytesTotal) < 5) {
  544. return 0;
  545. }
  546. var prog:Number = (_ns.bufferLength / _ns.bufferTime);
  547. return (prog > 1) ? 1 : prog;
  548. }
  549. /** A value between 0 and 1 describing the playback progress where 0 means the virtual playhead is at the very beginning of the video, 0.5 means it