开发者

if I load a flv with netStream, how can I call a function when the flv stops playing

开发者 https://www.devze.com 2023-01-15 08:58 出处:网络
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.

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 a开发者_如何学Pythonnd (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!?


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


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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号