Properties | Events | Methods |
Object
Player version: | Flash Player 7 |
Property Summary | |
| bufferLength : Number [read-only]The number of seconds of data currently in the buffer. |
| bufferTime : Number [read-only]The number of seconds assigned to the buffer by NetStream.setBufferTime() . |
| bytesLoaded : Number [read-only]The number of bytes of data that have been loaded into the player. |
| bytesTotal : Number [read-only]The total size in bytes of the file being loaded into the player. |
| currentFps : Number [read-only]The number of frames per second being displayed. |
| time : Number [read-only]The position of the playhead, in seconds. |
Properties inherited from class Object |
__proto__, __resolve, constructor, prototype |
Event Summary | |
onCuePoint = function(infoObject:Object) {}
Invoked when an embedded cue point is reached while playing an FLV file. |
|
onMetaData = function(infoObject:Object) {}
Invoked when the Flash Player receives descriptive information embedded in the FLV file being played. |
|
onStatus = function(infoObject:Object) {}
Invoked every time a status change or error is posted for the NetStream object. |
Constructor Summary | |
NetStream(connection:NetConnection)
Creates a stream that can be used for playing FLV files through the specified NetConnection object. |
Method Summary | |
| close() : Void
Stops playing all data on the stream, sets the NetStream.time property to 0, and makes the stream available for another use. |
| pause([flag:Boolean]) : Void
Pauses or resumes playback of a stream. |
| play(name:Object, start:Number, len:Number, reset:Object) : Void
Begins playback of an external video (FLV) file. |
| seek(offset:Number) : Void
Seeks the keyframe closest to the specified number of seconds from the beginning of the stream. |
| setBufferTime(bufferTime:Number) : Void
Specifies how long to buffer messages before starting to display the stream. |
Methods inherited from class Object |
addProperty, hasOwnProperty, isPropertyEnumerable, isPrototypeOf, registerClass, toString, unwatch, valueOf, watch |
Property Detail |
public bufferLength : Number
[read-only]
Player version: | Flash Player 7 — Note: This property is also supported in Flash Player 6 when used with Flash Communication Server. For more information, see the Flash Communication Server documentation. |
NetStream.bufferTime
to estimate how close the buffer is to being full--for example, to display feedback to a user who is waiting for data to be loaded into the buffer.
Example
this.createTextField("buffer_txt", this.getNextHighestDepth(), 10, 10, 300, 22); buffer_txt.html = true; var connection_nc:NetConnection = new NetConnection(); connection_nc.connect(null); var stream_ns:NetStream = new NetStream(connection_nc); stream_ns.setBufferTime(3); my_video.attachVideo(stream_ns); stream_ns.play("video1.flv"); var buffer_interval:Number = setInterval(checkBufferTime, 100, stream_ns); function checkBufferTime(my_ns:NetStream):Void { var bufferPct:Number = Math.min(Math.round(my_ns.bufferLength/my_ns.bufferTime 100), 100); var output_str:String = "<textformat tabStops='[100,200]'>"; output_str += "Length: "+my_ns.bufferLength+"\t"+"Time: "+my_ns.bufferTime+"\t"+"Buffer:"+bufferPct+"%"; output_str += "</textformat>"; buffer_txt.htmlText = output_str; }
If your SWF file includes a version 2 component, use the version 2 components DepthManager class instead of the MovieClip.getNextHighestDepth()
method, which is used in this example.
NetStream.bufferTime, NetStream.bytesLoaded |
public bufferTime : Number
[read-only]
Player version: | Flash Player 7 — Note: This property is also supported in Flash Player 6 when used with Flash Communication Server. For more information, see the Flash Communication Server documentation. |
NetStream.setBufferTime()
. The default value is .1(one-tenth of a second). To determine the number of seconds currently in the buffer, use NetStream.bufferLength
.
Example
this.createTextField("buffer_txt", this.getNextHighestDepth(), 10, 10, 300, 22); buffer_txt.html = true; var connection_nc:NetConnection = new NetConnection(); connection_nc.connect(null); var stream_ns:NetStream = new NetStream(connection_nc); stream_ns.setBufferTime(3); my_video.attachVideo(stream_ns); stream_ns.play("video1.flv"); var buffer_interval:Number = setInterval(checkBufferTime, 100, stream_ns); function checkBufferTime(my_ns:NetStream):Void { var bufferPct:Number = Math.min(Math.round(my_ns.bufferLength/my_ns.bufferTime 100), 100); var output_str:String = "<textformat tabStops='[100,200]'>"; output_str += "Length: "+my_ns.bufferLength+"\t"+"Time: "+my_ns.bufferTime+"\t"+"Buffer:"+bufferPct+"%"; output_str += "</textformat>"; buffer_txt.htmlText = output_str; }
If your SWF file includes a version 2 component, use the version 2 components DepthManager class instead of the MovieClip.getNextHighestDepth()
method, which is used in this example.
NetStream.setBufferTime(), NetStream.time, NetStream.bufferLength |
public bytesLoaded : Number
[read-only]
Player version: | Flash Player 7 |
NetStream.bytesTotal
to estimate how close the buffer is to being full--for example, to display feedback to a user who is waiting for data to be loaded into the buffer.
Example
bytesLoaded
and bytesTotal
properties that displays the loading progress of video1.flv into the video object instance called my_video
. A text field called loaded_txt
is dynamically created to display information about the loading progress as well. var connection_nc:NetConnection = new NetConnection(); connection_nc.connect(null); var stream_ns:NetStream = new NetStream(connection_nc); my_video.attachVideo(stream_ns); stream_ns.play("video1.flv"); this.createTextField("loaded_txt", this.getNextHighestDepth(), 10, 10, 160, 22); this.createEmptyMovieClip("progressBar_mc", this.getNextHighestDepth()); progressBar_mc.createEmptyMovieClip("bar_mc", progressBar_mc.getNextHighestDepth()); with (progressBar_mc.bar_mc) { beginFill(0xFF0000); moveTo(0, 0); lineTo(100, 0); lineTo(100, 10); lineTo(0, 10); lineTo(0, 0); endFill(); _xscale = 0; } progressBar_mc.createEmptyMovieClip("stroke_mc", progressBar_mc.getNextHighestDepth()); with (progressBar_mc.stroke_mc) { lineStyle(0, 0x000000); moveTo(0, 0); lineTo(100, 0); lineTo(100, 10); lineTo(0, 10); lineTo(0, 0); } var loaded_interval:Number = setInterval(checkBytesLoaded, 500, stream_ns); function checkBytesLoaded(my_ns:NetStream) { var pctLoaded:Number = Math.round(my_ns.bytesLoaded/my_ns.bytesTotal 100); loaded_txt.text = Math.round(my_ns.bytesLoaded/1000)+" of "+Math.round(my_ns.bytesTotal/1000)+" KB loaded ("+pctLoaded+"%)"; progressBar_mc.bar_mc._xscale = pctLoaded; if (pctLoaded>=100) { clearInterval(loaded_interval); } }
If your SWF file includes a version 2 component, use the version 2 components DepthManager class instead of the MovieClip.getNextHighestDepth()
method, which is used in this example.
NetStream.bytesTotal, NetStream.bufferLength |
public bytesTotal : Number
[read-only]
Player version: | Flash Player 7 |
bytesLoaded
and bytesTotal
properties that displays the loading progress of video1.flv into the video object instance called my_video
. A text field called loaded_txt
is dynamically created to display information about the loading progress as well. var connection_nc:NetConnection = new NetConnection(); connection_nc.connect(null); var stream_ns:NetStream = new NetStream(connection_nc); my_video.attachVideo(stream_ns); stream_ns.play("video1.flv"); this.createTextField("loaded_txt", this.getNextHighestDepth(), 10, 10, 160, 22); this.createEmptyMovieClip("progressBar_mc", this.getNextHighestDepth()); progressBar_mc.createEmptyMovieClip("bar_mc", progressBar_mc.getNextHighestDepth()); with (progressBar_mc.bar_mc) { beginFill(0xFF0000); moveTo(0, 0); lineTo(100, 0); lineTo(100, 10); lineTo(0, 10); lineTo(0, 0); endFill(); _xscale = 0; } progressBar_mc.createEmptyMovieClip("stroke_mc", progressBar_mc.getNextHighestDepth()); with (progressBar_mc.stroke_mc) { lineStyle(0, 0x000000); moveTo(0, 0); lineTo(100, 0); lineTo(100, 10); lineTo(0, 10); lineTo(0, 0); } var loaded_interval:Number = setInterval(checkBytesLoaded, 500, stream_ns); function checkBytesLoaded(my_ns:NetStream) { var pctLoaded:Number = Math.round(my_ns.bytesLoaded/my_ns.bytesTotal 100); loaded_txt.text = Math.round(my_ns.bytesLoaded/1000)+" of "+Math.round(my_ns.bytesTotal/1000)+" KB loaded ("+pctLoaded+"%)"; progressBar_mc.bar_mc._xscale = pctLoaded; if (pctLoaded>=100) { clearInterval(loaded_interval); } }
If your SWF file includes a version 2 component, use the version 2 components DepthManager class instead of the MovieClip.getNextHighestDepth()
method, which is used in this example.
NetStream.bytesLoaded, NetStream.bufferTime |
public currentFps : Number
[read-only]
Player version: | Flash Player 7 — Note: This property is also supported in Flash Player 6 when used with Flash Communication Server. For more information, see the Flash Communication Server documentation. |
var connection_nc:NetConnection = new NetConnection(); connection_nc.connect(null); var stream_ns:NetStream = new NetStream(connection_nc); my_video.attachVideo(stream_ns); stream_ns.play("video1.flv"); this.createTextField("fps_txt", this.getNextHighestDepth(), 10, 10, 50, 22); fps_txt.autoSize = true; var fps_interval:Number = setInterval(displayFPS, 500, stream_ns); function displayFPS(my_ns:NetStream) { fps_txt.text = "currentFps (frames per second): "+Math.floor(my_ns.currentFps); }
If your SWF file includes a version 2 component, use the version 2 components DepthManager class instead of the MovieClip.getNextHighestDepth()
method, which is used in this example.
public time : Number
[read-only]
Player version: | Flash Player 7 — Note: This property is also supported in Flash Player 6 when used with Flash Communication Server. For more information, see the Flash Communication Server documentation. |
time_txt
. Select New Video from the Library options menu to create a video object instance, and give it an instance name my_video
. Create a new video object called my_video. Add the following ActionScript to your FLA or AS file: var connection_nc:NetConnection = new NetConnection(); connection_nc.connect(null); var stream_ns:NetStream = new NetStream(connection_nc); my_video.attachVideo(stream_ns); stream_ns.play("video1.flv"); // stream_ns.onStatus = function(infoObject:Object) { statusCode_txt.text = infoObject.code; }; this.createTextField("time_txt", this.getNextHighestDepth(), 10, 10, 100, 22); time_txt.text = "LOADING"; var time_interval:Number = setInterval(checkTime, 500, stream_ns); function checkTime(my_ns:NetStream) { var ns_seconds:Number = my_ns.time; var minutes:Number = Math.floor(ns_seconds/60); var seconds = Math.floor(ns_seconds%60); if (seconds<10) { seconds = "0"+seconds; } time_txt.text = minutes+":"+seconds; }
If your SWF file includes a version 2 component, use the version 2 components DepthManager class instead of the MovieClip.getNextHighestDepth()
method, which is used in this example.
NetStream.bufferLength, NetStream.bytesLoaded |
Event Detail |
public onCuePoint = function(infoObject:Object) {}
Player version: | Flash Player 8 |
There are two types of cue points that can be embedded in an FLV file.
time
property corresponds to that exact keyframe. Navigation cue points are often used as bookmarks or entry points to let users navigate through the video file. The onCuePoint()
event handler receives an object with these properties:
Property | Description |
---|---|
name | The name given to the cue point when it was embedded in the FLV file. |
time | The time in seconds at which the cue point occurred in the video file during playback. |
type | The type of cue point that was reached, either "navigation" or "event". |
parameters | A associative array of name/value pair strings specified for this cue point. Any valid string can be used for the parameter name or value. |
You can define cue points in an FLV file when you first encode the file, or when you import a video clip in the Flash Authoring tool by using the Video Import wizard.
The onMetaData()
event handler also retrieves information about the cue points in a video file. However the onMetaData()
event handler gets information about all of the cue points before the video begins playing. The onCuePoint()
event handler receives information about a single cue point at the time specified for that cue point during playback.
Generally if you want your code to respond to a specific cue point at the time it occurs you should use the onCuePoint()
event handler to trigger some action in your code.
You can use the list of cue points provided to the onMetaData()
event handler to let your user start playing the video at predefined points along the video stream. Pass the value of the cue point's time
property to the NetStream.seek()
method to play the video from that cue point.
infoObject:Object — An object containing the name , time , type , and parameters for the cue point. |
onCuePoint()
handler for the NetStream object. The handler cycles through each named property in the infoObject
object and prints the property's name and value. When it finds the property named parameters
it cycles through each parameter name in the list and prints the parameter name and value. var nc:NetConnection = new NetConnection(); nc.connect(null); var ns:NetStream = new NetStream(nc); ns.onCuePoint = function(infoObject:Object) { trace("onCuePoint:"); for (var propName:String in infoObject) { if (propName != "parameters") { trace(propName + " = " + infoObject[propName]); } else { trace("parameters ="); if (infoObject.parameters != undefined) { for (var paramName:String in infoObject.parameters) { trace(" " + paramName + ": " + infoObject.parameters[paramName]); } } else { trace("undefined"); } } } trace("---------"); } ns.play("http://www.helpexamples.com/flash/video/cuepoints.flv");
This causes the following information to be displayed:
onCuePoint: parameters = lights: beginning type = navigation time = 0.418 name = point1 --------- onCuePoint: parameters = lights: middle type = navigation time = 7.748 name = point2 --------- onCuePoint: parameters = lights: end type = navigation time = 16.02 name = point3 ---------
The parameter name "lights" is an arbitrary name used by the author of the example video. You can give cue point parameters any name you want.
See alsoNetStream.onMetaData |
public onMetaData = function(infoObject:Object) {}
Player version: | Flash Player 7 |
The Flash Video Exporter utility (version 1.1 or greater) embeds a video's duration, creation date, data rates, and other information into the video file itself. Different video encoders embed different sets of metadata.
This handler is triggered after a call to the NetStream.play()
method, but before the video playhead has advanced.
In many cases the duration value embedded in FLV metadata approximates the actual duration but is not exact. In other words it will not always match the value of the NetStream.time
property when the playhead is at the end of the video stream.
infoObject:Object — An object containing one property for each metadata item. |
onMetaData()
handler for the NetStream object. The handler cycles through each named property in the infoObject
object and prints the property's name and value. var nc:NetConnection = new NetConnection(); nc.connect(null); var ns:NetStream = new NetStream(nc); ns.onMetaData = function(infoObject:Object) { for (var propName:String in infoObject) { trace(propName + " = " + infoObject[propName]); } }; ns.play("http://www.helpexamples.com/flash/video/water.flv");
This causes the following information to be displayed:
canSeekToEnd = true videocodecid = 4 framerate = 15 videodatarate = 400 height = 215 width = 320 duration = 7.347
The list of properties will vary depending on the software that was used to encode the FLV file.
See alsoNetStream.time, NetStream.play(), NetConnection |
public onStatus = function(infoObject:Object) {}
Player version: | Flash Player 6 |
The information object has a code property containing a string that describes the result of the onStatus handler, and a level property containing a string that is either status or error.
In addition to this onStatus handler, Flash also provides a "super" function called System.onStatus
. If onStatus is invoked for a particular object and there is no function assigned to respond to it, Flash processes a function assigned to System.onStatus
if it exists.
The following events notify you when certain NetStream activities occur.
Code property | Level property | Meaning |
---|---|---|
NetStream.Buffer.Empty | status | Data is not being received quickly enough to fill the buffer. Data flow will be interrupted until the buffer refills, at which time a NetStream.Buffer.Full message will be sent and the stream will begin playing again. |
NetStream.Buffer.Full | status | The buffer is full and the stream will begin playing. |
NetStream.Buffer.Flush | status | Data has finished streaming, and the remaining buffer will be emptied. |
NetStream.Play.Start | status | Playback has started. |
NetStream.Play.Stop | status | Playback has stopped. |
NetStream.Play.StreamNotFound | error | The FLV passed to the play() method can't be found. |
NetStream.Seek.InvalidTime | error | For video downloaded with progressive download, the user has tried to seek or play past the end of the video data that has downloaded thus far, or past the end of the video once the entire file has downloaded. The message.details property contains a time code that indicates the last valid position to which the user can seek. |
NetStream.Seek.Notify | status | The seek operation is complete. |
If you consistently see errors regarding buffer, you should try changing the buffer using the NetStream.setBufferTime()
method.
infoObject:Object — A parameter defined according to the status message or error message. |
var connection_nc:NetConnection = new NetConnection(); connection_nc.connect(null); var stream_ns:NetStream = new NetStream(connection_nc); my_video.attachVideo(stream_ns); stream_ns.play("video1.flv"); stream_ns.onStatus = function(infoObject:Object) { trace("NetStream.onStatus called: ("+getTimer()+" ms)"); for (var prop in infoObject) { trace("\t"+prop+":\t"+infoObject[prop]); } trace(""); };
NetStream.setBufferTime(), System.onStatus |
Constructor Detail |
public NetStream(connection:NetConnection)
Player version: | Flash Player 7 — Note: This class is also supported in Flash Player 6 when used with Flash Communication Server. For more information, see the Flash Communication Server documentation. |
connection:NetConnection — A NetConnection object. |
connection_nc
, and uses it to construct a new NetStream object called stream_ns
. Select New Video from the Library options menu to create a video object instance, and give it an instance name my_video
. Create a new video object called my_video. Then add the following ActionScript to your FLA or AS file: var connection_nc:NetConnection = new NetConnection(); connection_nc.connect(null); var stream_ns:NetStream = new NetStream(connection_nc); my_video.attachVideo(stream_ns); stream_ns.play("video1.flv");
NetConnection class, Video.attachVideo() |
Method Detail |
public close() : Void
Player version: | Flash Player 7 — Note: This method is also supported in Flash Player 6 when used with Flash Communication Server. For more information, see the Flash Communication Server documentation. |
NetStream.time
property to 0, and makes the stream available for another use. This command also deletes the local copy of an FLV file that was downloaded using HTTP. Although Flash Player will delete the local copy of the FLV file that it creates, a copy of the video may persist in the browser's cache directory. If complete prevention of caching or local storage of the FLV file is required, use Flash Communication Server MX.
Example
onDisconnect()
function closes a connection and deletes the temporary copy of video1.flv that was stored on the local disk when you click the button called close_btn
: var connection_nc:NetConnection = new NetConnection(); connection_nc.connect(null); var stream_ns:NetStream = new NetStream(connection_nc); my_video.attachVideo(stream_ns); stream_ns.play("video1.flv"); close_btn.onRelease = function(){ stream_ns.close(); };
NetStream.pause(), NetStream.play() |
public pause([flag:Boolean]) : Void
Player version: | Flash Player 7 — Note: This method is also supported in Flash Player 6 when used with Flash Communication Server. For more information, see the Flash Communication Server documentation. |
The first time you call this method (without sending a parameter), it pauses play; the next time, it resumes play. You might want to attach this method to a button that the user presses to pause or resume playback.
Parametersflag:Boolean [optional] — A Boolean value specifying whether to pause play (true ) or resume play (false ). If you omit this parameter, NetStream.pause() acts as a toggle: the first time it is called on a specified stream, it pauses play, and the next time it is called, it resumes play. |
my_ns.pause(); // pauses play first time issued my_ns.pause(); // resumes play my_ns.pause(false); // no effect, play continues my_ns.pause(); // pauses play
NetStream.close(), NetStream.play() |
public play(name:Object, start:Number, len:Number, reset:Object) : Void
Player version: | Flash Player 7 — Note: This method is also supported in Flash Player 6 when used with Flash Communication Server. For more information, see the Flash Communication Server documentation. |
Video.attachVideo()
method; audio being streamed with the video, or an FLV file that contains only audio, is played automatically. If you want to control the audio associated with an FLV file, you can use MovieClip.attachAudio()
to route the audio to a movie clip; you can then create a Sound object to control some aspects of the audio. For more information, see MovieClip.attachAudio()
.
If the FLV file can't be found, the NetStream.onStatus
event handler is invoked. If you want to stop a stream that is currently playing, use NetStream.close()
.
You can play local FLV files that are stored in the same directory as the SWF file or in a subdirectory; you can't navigate to a higher-level directory. For example, if the SWF file is located in a directory named /training, and you want to play a video stored in the /training/videos directory, you would use the following syntax:
my_ns.play("videos/videoName.flv");
To play a video stored in the /training directory, you would use the following syntax:
my_ns.play("videoName.flv");
When using this method, consider the Flash Player security model.
For Flash Player 8:
For more information, see the following:
name:Object — The name of an FLV file to play, in quotation marks. Both http:// and file:// formats are supported; the file:// location is always relative to the location of the SWF file. |
|
start:Number |
|
len:Number |
|
reset:Object |
NetStream.play()
command. You can play a file that is on a user's computer. The joe_user directory is a subdirectory of the directory where the SWF is stored. And, you can play a file on a server: // Play a file that is on the user's computer. my_ns.play("file://joe_user/flash/videos/lectureJune26.flv"); // Play a file on a server. my_ns.play("http://someServer.someDomain.com/flash/video/orientation.flv");
MovieClip.attachAudio(), NetStream.close(), NetStream.onStatus, NetStream.pause(), Video.attachVideo() |
public seek(offset:Number) : Void
Player version: | Flash Player 7 — Note: This method is also supported in Flash Player 6 when used with Flash Communication Server. For more information, see the Flash Communication Server documentation. |
offset:Number — The approximate time value, in seconds, to move to in an FLV file. The playhead moves to the keyframe of the video that's closest to offset .
The precise location to which a video seeks will differ depending on the frames per second setting at which it was exported. Therefore, if the same video is exported at 6 fps and 30 fps, it will seek to two different locations if you use, for example, |
NetStream.seek()
command. You can return to the beginning of the stream, move to a location 30 seconds from the beginning of the stream, and move backwards three minutes from the current location: // Return to the beginning of the stream my_ns.seek(0); // Move to a location 30 seconds from the beginning of the stream my_ns.seek(30); // Move backwards three minutes from current location my_ns.seek(my_ns.time - 180);
Netstream.play(), NetStream.time |
public setBufferTime(bufferTime:Number) : Void
Player version: | Flash Player 7 — Note: This method is also supported in Flash Player 6 when used with Flash Communication Server. For more information, see the Flash Communication Server documentation. |
bufferTime
to 15; Flash begins playing the stream only after 15 seconds of data are buffered.
Parameters
bufferTime:Number — The number of seconds of data to be buffered before Flash begins displaying data. The default value is 0.1 (one-tenth of a second). |
NetStream.bufferLength
.
See also
NetStream.bufferLength, NetStream.bufferTime |
Properties | Events | Methods |