Call functions run when External Video events are triggered (Start, Buffer, End)

Posted on 2007-03-27
Medium Priority
Last Modified: 2010-04-03
I need to have several functions run when Video events are triggered.

Specifically, I have a flash program that plays an external FLV file that is set to stream (as opposed to embedding it within the flash movie).  I need to run a function as soon as the video starts playing (AFTER IT FINISHES BUFFERING) and also as soon as the video ends playing.  I would also like to know if and when the video ever goes back to buffering (i can hopefully avoid this by setting the "buffertime" parameter to something large like 30 seconds).

To reiterate I need 3 things:

1. Call a function when buffering of an externally streamed video ends and video playback begins.
2. Some way to know if and when buffering begins again.
3. Call a function as soon as the video playback ends.

Thanks a lot for your help!
Question by:buktotruth
  • 2

Expert Comment

ID: 18801656

You need to use the NetStream.onStatus method to get this information, try printing the netstream status to see how it beahves:

stream_ns.onStatus = function(status_obj:Object){

Here's an example of a script i used to display a video:

var connection_nc:NetConnection = new NetConnection();
var stream_ns:NetStream = new NetStream(connection_nc);


stream_ns.onMetaData = function(meta_obj:Object){
      my_video.duration = meta_obj.duration;

stream_ns.onStatus = function(status_obj:Object){

            case "NetStream.Play.Start":
                  //ToDo - Videa has been found and loaded but buffer is no ready loading._visible=false;

            case "NetStream.Buffer.Full":
                  //ToDo - Buffer is full, start playing...

            case "NetStream.Buffer.Flush":
                  if(Math.abs(my_video.duration-stream_ns.time)<1){ //half second tolerance...
                        //ToDo - END OF VIDEO

            case "NetStream.Buffer.Empty":
                  //ToDo - BUFFERING... buff._visible = true

                  //Usually playing... buff._visible = false


Hope it helps,


Author Comment

ID: 18802730
A couple of questions about this.

1)  I'm pretty sure i'm using AS2.0 (Flash Pro 8).  Will this still work?

2) Where do i put that initial line of code?

"stream_ns.onStatus = function(status_obj:Object){

3) within that last bit of code, is stream_ns the name of the FLV Playback instance?

Accepted Solution

victmo earned 780 total points
ID: 18826991
Hi buktotruth,

Sorry for taking this long to answer, i had to go out of town and i didnt have time to check on you question.

The code i gave you works fine on Actionscript 2.0 (Flash 8) but you need to have a Video instance (my_video) on the stage, not a FLVPlayback component.

I´ll try to upload an example for you to check later



Featured Post

Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

There are times in your Flash CS4 application when you want more than a simple pointer or a hand, and it's hard to find an ideal walk-through to tell you what to do.  I spent a few days recently learning my way around making custom cursors in Flash,…
This article describes a solution to a problem of subloading one movie into another when they have different SWF versions. Sometime back, I was working on an ActionScript project while I came across an interesting fact which I would like to share…
In this tutorial viewers will learn how to create a basic shape tween animation in Flash including shape hints for smooth animation Open a new document in Flash: Draw a shape: Select another frame (how long you want the tween to be): Right click and…
The goal of the tutorial is to teach the user how to live broadcast using Flash Media Live Encoder and connecting it to YouTube to broadcast. Log into your Youtube account, choose live stream settings, start live stream from Flash Media Live Enc…

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question