NetStream


Object   |   +-NetStream public dynamic class NetStream extends Object

The NetStream class provides methods and properties for playing Flash Video (FLV) files from the local file system or an HTTP address. You use a NetStream object to stream video through a NetConnection object. Playing external FLV files provides several advantages over embedding video in a Flash document, such as better performance and memory management, and independent video and Flash frame rates. This class provides a number of methods and properties you can use to track the progress of the file as it loads and plays, and to give the user control over playback (stopping, pausing, and so on).

Availability: ActionScript 1.0; Flash Player 7

Property summary

Modifiers

Property

Description

 

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

constructor (Object.constructor property) ,__proto__ (Object.__proto__ property),prototype (Object.prototype property) ,__resolve (Object.__resolve property)


Event summary

Event

Description

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

Signature

Description

NetStream(connection:NetConnection)

Creates a stream that can be used for playing FLV files through the specified NetConnection object.


Method summary

Modifiers

Signature

Description

 

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 (Object.addProperty method), hasOwnProperty (Object.hasOwnProperty method), isPropertyEnumerable (Object.isPropertyEnumerable method), isPrototypeOf (Object.isPrototypeOf method), registerClass (Object.registerClass method),toString (Object.toString method), unwatch (Object.unwatch method),valueOf (Object.valueOf method), watch (Object.watch method)


bufferLength (NetStream.bufferLength property)

public bufferLength : Number [read-only]

The number of seconds of data currently in the buffer. You can use this property in conjunction with 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.

Availability: ActionScript 1.0; 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.

Example

The following example dynamically creates a text field that displays information about the number of seconds that are currently in the buffer. The text field also displays the buffer length that the video is set to, and percentage of buffer that is filled.

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.

See also

bufferTime (NetStream.bufferTime property), bytesLoaded (NetStream.bytesLoaded property)

bufferTime (NetStream.bufferTime property)

public bufferTime : Number [read-only]

The number of seconds assigned to the buffer by 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.

Availability: ActionScript 1.0; 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.

Example

The following example dynamically creates a text field that displays information about the number of seconds that are currently in the buffer. The text field also displays the buffer length that the video is set to, and percentage of buffer that is filled.

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.

See also

setBufferTime (NetStream.setBufferTime method), time (NetStream.time property), bufferLength (NetStream.bufferLength property)

bytesLoaded (NetStream.bytesLoaded property)

public bytesLoaded : Number [read-only]

The number of bytes of data that have been loaded into the player. You can use this method in conjunction with 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.

Availability: ActionScript 1.0; Flash Player 7

Example

The following example creates a progress bar using the Drawing API and the 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.

See also

bytesTotal (NetStream.bytesTotal property), bufferLength (NetStream.bufferLength property)

bytesTotal (NetStream.bytesTotal property)

public bytesTotal : Number [read-only]

The total size in bytes of the file being loaded into the player.

Availability: ActionScript 1.0; Flash Player 7

Example

The following example creates a progress bar using the Drawing API and the 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.

See also

bytesLoaded (NetStream.bytesLoaded property), bufferTime (NetStream.bufferTime property)

close (NetStream.close method)

public close() : Void

Stops playing all data on the stream, sets the 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.

Availability: ActionScript 1.0; 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.

Example

The following 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(); };

See also

pause (NetStream.pause method), play (NetStream.play method)

currentFps (NetStream.currentFps property)

public currentFps : Number [read-only]

The number of frames per second being displayed. If you are exporting FLV files to be played back on a number of systems, you can check this value during testing to help you determine how much compression to apply when exporting the file.

Availability: ActionScript 1.0; 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.

Example

The following example creates a text field that displays the current number of frames per second that video1.flv displays.

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.

NetStream constructor

public NetStream(connection:NetConnection)

Creates a stream that can be used for playing FLV files through the specified NetConnection object.

Availability: ActionScript 1.0; 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.

Parameters

connection:NetConnection - A NetConnection object.

Example

The following code first constructs a new 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.

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");

See also

NetConnection, attachVideo (Video.attachVideo method)

onCuePoint (NetStream.onCuePoint handler)

onCuePoint = function(infoObject:Object) {}

Invoked when an embedded cue point is reached while playing an FLV file. You can use this handler to trigger actions in your code when the video reaches a specific cue point. This lets you synchronize other actions in your application with video playback events.

There are two types of cue points that can be embedded in an FLV file.

  • A "navigation" cue point specifies a keyframe within the FLV file and the cue point's 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.

  • An "event" cue point is specified by time, whether or not that time corresponds to a specific keyframe. An event cue point usually represents a time in the video when something happens that could be used to trigger other application events.

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.

Availability: ActionScript 1.0; Flash Player 8

Parameters

infoObject:Object - An object containing the name, time, type, and parameters for the cue point.

Example

The code in this example starts by creating new NetConnection and NetStream objects. Then it defines the 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 also

onMetaData (NetStream.onMetaData handler)

onMetaData (NetStream.onMetaData handler)

onMetaData = function(infoObject:Object) {}

Invoked when the Flash Player receives descriptive information embedded in the FLV file being played.

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.

Availability: ActionScript 1.0; Flash Player 7

Parameters

infoObject:Object - An object containing one property for each metadata item.

Example

The code in this example starts by creating new NetConnection and NetStream objects. Then it defines the 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 also

time (NetStream.time property), play (NetStream.play method), NetConnection

onStatus (NetStream.onStatus handler)

onStatus = function(infoObject:Object) {}

Invoked every time a status change or error is posted for the NetStream object. If you want to respond to this event handler, you must create a function to process the information object.

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.

Availability: ActionScript 1.0; Flash Player 6

Parameters

infoObject:Object - A parameter defined according to the status message or error message.

Example

The following example displays data about the stream in the Output panel:

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(""); };

See also

setBufferTime (NetStream.setBufferTime method), onStatus (System.onStatus handler)

pause (NetStream.pause method)

public pause([flag:Boolean]) : Void

Pauses or resumes playback of a stream.

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.

Availability: ActionScript 1.0; 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.

Parameters

flag: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.

Example

The following examples illustrate some uses of this method:

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

See also

close (NetStream.close method), play (NetStream.play method)

play (NetStream.play method)

public play(name:Object, start:Number, len:Number, reset:Object) : Void

Begins playback of an external video (FLV) file. To view video data, you must call a 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:

  • NetStream.play() is not allowed if the calling SWF file is in the local-with-file-system sandbox and the resource is in a non-local sandbox.

  • Network sandbox access from the local-trusted or local-with-networking sandbox requires permission from the website via a cross-domain policy file.

For more information, see the following:

  • Chapter 17, "Understanding Security," in Learning ActionScript 2.0 in Flash

  • The Flash Player 8 Security white paper at http://www.macromedia.com/go/fp8_security

  • The Flash Player 8 Security-Related API white paper at http://www.macromedia.com/go/fp8_security_apis

Availability: ActionScript 1.0; 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.

Parameters

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 -

Example

The following example illustrates some ways to use the 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");

See also

attachAudio (MovieClip.attachAudio method), close (NetStream.close method), onStatus (NetStream.onStatus handler), pause (NetStream.pause method), attachVideo (Video.attachVideo method)

seek (NetStream.seek method)

public seek(offset:Number) : Void

Seeks the keyframe closest to the specified number of seconds from the beginning of the stream. The stream resumes playing when it reaches the specified location in the stream.

Availability: ActionScript 1.0; 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.

Parameters

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 numberOfSeconds.

  • To return to the beginning of the stream, pass 0 for numberOfSeconds.

  • To seek forward from the beginning of the stream, pass the number of seconds you want to advance. For example, to position the playhead at 15 seconds from the beginning, use my_ns .seek(15).

  • To seek relative to the current position, pass my_ns .time + n or my_ns .time - n to seek n seconds forward or backward, respectively, from the current position. For example, to rewind 20 seconds from the current position, use my_ns.seek(my_ns.time - 20).

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, my_ns.seek(15) for both video objects.

Example

The following example illustrates some ways to use the 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);

See also

, time (NetStream.time property)

setBufferTime (NetStream.setBufferTime method)

public setBufferTime(bufferTime:Number) : Void

Specifies how long to buffer messages before starting to display the stream. For example, if you want to make sure that the first 15 seconds of the stream play without interruption, set numberOfSeconds to 15; Flash begins playing the stream only after 15 seconds of data are buffered.

Availability: ActionScript 1.0; 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.

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).

Example

See the example for NetStream.bufferLength.

See also

bufferLength (NetStream.bufferLength property), bufferTime (NetStream.bufferTime property)

time (NetStream.time property)

public time : Number [read-only]

The position of the playhead, in seconds.

Availability: ActionScript 1.0; 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.

Example

The following example displays the current position of the playhead in a dynamically created text field called 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.

See also

bufferLength (NetStream.bufferLength property), bytesLoaded (NetStream.bytesLoaded property)



ActionScript 2.0 Language Reference for Macromedia Flash 8
ActionScript 2.0 Language Reference for Macromedia Flash 8
ISBN: 0321384040
EAN: 2147483647
Year: 2004
Pages: 113

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net