Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2007-03-27
3
Medium Priority
?
185 Views
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!
Jeff
0
Comment
Question by:buktotruth
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 5

Expert Comment

by:victmo
ID: 18801656
Hello,

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){
      trace(status_obj.code);
};



Here's an example of a script i used to display a 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("video_file.flv");

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

stream_ns.onStatus = function(status_obj:Object){
      switch(status_obj.code){

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

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

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

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

            default:
                  //Usually playing... buff._visible = false
                  break;                  
      }
};

stop();



Hope it helps,

Vic
0
 

Author Comment

by:buktotruth
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){
      trace(status_obj.code);
}"

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

Accepted Solution

by:
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

Cheers,

Vic
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is a very simple example to help those of you who are still migrating from AS2 to AS3 understand the redesigned event model in AS3. In AS2.0, event functions (that is, the function to be performed when an event is fired) were stored as a pro…
The last time I worked with Flash and Socket connections was in AS1. A recent project required flash connecting to a Socket, and sending receiving information - we figured it would be easy enough - we all know about the socket policy documents and c…
The goal of the tutorial is to teach the user how to set there setting in Adobe Flash Media Live Encoder and YouTube for optimal video and audio quality.
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.

715 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