views:

126

answers:

3

I have a website in ActionScript 3 that has lots of FLV animations that happen when you press buttons. Right now this is how I have it set up.

in AS3, im loading FLv's (which are animations I exported in FLV form from After Effects) with net stream. I have a timer set up for the same amount of length of time that the animations (FLV's) play and when the timer stops it calls a function that closes the stream, opens a new one and plays another video. The only problem I noticed using timers is that if the connection is slow and (animation)stops for a second, the timer keeps going, and calls the next flv too early.

Does anyone know a way to load a flv, or swf for that matter, at the end of play of the flv? so that the next FLV will always play at the end of the run time of the previous FLV, rather than using timers?

im thinking onComplete but I don't know how to implement that!?

A: 

Sequential playing is pretty easy to achieve with the OSMF framework, you should check it out. Google "osmf tutorials" and you should find a few tutorials online.

The framework is fairly recent, but it looks like it may become the de facto solution for media delivery in Flash as it's not limited to video but also audio & images.

As a developer you won't have to bother with the NetStream & NetConnection classes. Developing video solutions , as well as audio & images solutions should be streamlined and easier to handle. Only limitation is that it requires Flash 10

PatrickS
is there no way to do it with as3 by itself with no classes? I actually going to research osmf and that looks really cool but I only have a week till graduation and I need to complete this project for grad so I need something thats not going to take e=me a long time to research
tyepoe
i don't think osmf would take you a week to understand! maybe a couple of hours to go thru the tutorials and get the general idea. check this blog
PatrickS
sorry, i couldn't edit anymore... osmf wouldn't take you a week to understand!at the most a couple of hours to go thru the tutorials and get the general idea. check this http://www.rblank.com/,there's the code for a basic player, so u wouldn't have to start from scratch, he's got few video tutorials too. of course you can do it without osmf , one way could be to retrieve the video's duration and monitor the current position, as soon as the current position reaches the duration value you could start the next video, Ross's solution should work well too
PatrickS
A: 

Here's some code for checking when a FLV ends with NetStream. I just provide snippets as I assume you got the FLV up and running already.

//create a netstream and pass in your connection
var netStream:NetStream = new NetStream(conn);

//add callback function for PlayStatus -event
var client : Object = {};
client.onPlayStatus = onPlayStatus;
netStream.client = client;

//attach your NetStream to the connection as usual
//---

//function that gets called onPlayStatus
function onPlayStatus(info : Object) : void {
    trace("onPlayStatus:" +info.code + " " + info.duration);
    if (info.code == "NetStream.Play.Complete") {
        //play the next FLV and so on
    }
}

EDIT: With your example code it will look something like this.

var nc:NetConnection = new NetConnection(); 
nc.connect(null); 
var ns:NetStream = new NetStream(nc); 

var listener:Object = new Object(); 
listener.onMetaData = function(md:Object):void{}; 
listener.onPlayStatus = function(info : Object) : void {
    trace("onPlayStatus:" +info.code + " " + info.duration);
    if (info.code == "NetStream.Play.Complete") {
        //play the next FLV and so on
    }
};
ns.client = listener; 

vid1.attachNetStream(ns); 

const moviename1:String = "moviename2.flv"; 
const moviename1:String = "moviename3.flv"; 
var movietoplay:String = "moviename.flv"; 
ns.play(movietoplay);
Ross
i have flv running already, but im bad at figuring this out. I am attaching my connection to a video on the stage with an instance name, how would I put your code with what I have:... var nc:NetConnection = new NetConnection(); nc.connect(null); var ns:NetStream = new NetStream(nc); vid1.attachNetStream(ns); var listener:Object = new Object(); listener.onMetaData = function(md:Object):void{}; ns.client = listener; const moviename1:String = "moviename2.flv"; const moviename1:String = "moviename3.flv"; var movietoplay:String = "moviename.flv"; ns.play(movietoplay);
tyepoe
i've provided an example with your code in my post now
Ross
A: 

thanks a lot Ross and patrick, both of your solutions will work for me, I wish I would hae asked this question a lot sooner because this is an issue that I have been messing around with a lot for a long time....Thanks a lot both you guys!

mike