FORUMS: list search recent posts

(AS3) Looping 3 different videos with NetStream

COW Forums : Adobe Flash

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Amy Lee Walton
(AS3) Looping 3 different videos with NetStream
on Jan 11, 2009 at 5:13:11 am

Hi there.

I'm trying to once an flv is done, start playing another flv. Simple, it would seem... I can't get it to work at all. I was able, using this code to start over another video but to actually once the current video is stopped, tell the netstream to play another flv... it just doesn't do it.

I tried to open a new netstream and close the other with no change.

Please help me!

Thanks,
Amy Lee

CODE-------

//load the rain FLV
var video:Video = new Video();
addChild(video);

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

var ns:NetStream = new NetStream(nc);
ns.client = {onMetaData:ns_onMetaData, NetStatusEvent:ns_onPlayStatus};
var ns2:NetStream = new NetStream(nc);
ns2.client = {onMetaData:ns2_onMetaData, NetStatusEvent:ns2_onPlayStatus};

video.attachNetStream(ns);
ns.play("videos/walgreens.flv");

function ns_onMetaData(item:Object):void {
video.width = item.width;// Resize video instance.
video.height = item.height;
video.x = (stage.stageWidth - video.width) / 2;// Center video instance on Stage.
video.y = (stage.stageHeight - video.height) / 2;
}

//loop the video
function ns_onPlayStatus(event:NetStatusEvent):void {
if (event.info.code == "NetStream.Play.Stop") {
ns.close();
ns2.play("videos/scooter.flv");
video.attachNetStream(ns2);
trace("now what?")
}
}

function ns2_onMetaData(item:Object):void {
video.width = item.width;
video.height = item.height;
video.x = (stage.stageWidth - video.width) / 2;
video.y = (stage.stageHeight - video.height) / 2;
}

//loop the video
function ns2_onPlayStatus(event:NetStatusEvent):void {
if (event.info.code == "NetStream.Play.Stop") {
ns2.seek(0);
//video.attachNetStream(ns2);
//ns2.play("videos/scooter.flv");
}
}

ns.addEventListener(NetStatusEvent.NET_STATUS, ns_onPlayStatus);
ns2.addEventListener(NetStatusEvent.NET_STATUS, ns2_onPlayStatus);


Return to posts index

Pieter Helsen
Re: (AS3) Looping 3 different videos with NetStream
on Jan 11, 2009 at 3:27:57 pm

This should do the trick. No need to use two netstreams. :)

import flash.net.NetConnection;
import flash.net.NetStream;
import flash.media.Video;

var count:Number = 0;
var video:Video = new Video();
addChild(video);

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

var ns:NetStream = new NetStream(nc);
ns.client = {onMetaData:ns_onMetaData, NetStatusEvent:ns_onPlayStatus};
ns.addEventListener(NetStatusEvent.NET_STATUS, ns_onPlayStatus);

video.attachNetStream(ns);
ns.play("videos/walgreens.flv");

function ns_onMetaData(item:Object):void {
video.width = item.width;// Resize video instance.
video.height = item.height;
video.x = (stage.stageWidth - video.width) / 2;// Center video instance on Stage.
video.y = (stage.stageHeight - video.height) / 2;
}

//loop the video
function ns_onPlayStatus(event:NetStatusEvent):void {
trace(event.info.code);
if (event.info.code == "NetStream.Play.Stop") {
if(count == 0){
ns.play("videos/scooter.flv");
count++;
trace("now what?");
} else {
ns.seek(0);
}
}
}

stop();



Kind regards,
Pieter

General notice: from now on, I would like to ask everyone to put [AS2] or [AS3] (corresponding to the version of actionscript you are using on your project) in front of their post titles when the question is actionscript related! Please help us help you faster. Thank you.


Return to posts index

Amy Lee Walton
Re: (AS3) Looping 3 different videos with NetStream
on Jan 11, 2009 at 8:37:35 pm

Thank you for your response!

It still doesn't work... The event code does come up as NetStream.Play.Stop, then the "now what?" trace outputs too. But instead of switching over to the new video (which is actually scoot.flv vs. scooter.flv) the first video stops on the last frame and I get the error "NetStream.Play.StreamNotFound".

This has been the problem!

I did add a ns.close(); right above the ns.play("videos/scoot.flv"); to flush out the previous one and it does say the "now what?" and no NetStream.Play.Stop but I'm still getting the same result AKA it's not loading this ns.play("videos/scoot.flv");

Any more tips??



Return to posts index


Pieter Helsen
Re: (AS3) Looping 3 different videos with NetStream
on Jan 11, 2009 at 10:20:57 pm

Well, streamnotfound basically means that the file can't be found. Try playing the scoot.flv file first...

I've actually tested the code myself just now and it works here, so you shouldn't have any problems.

Kind regards,
Pieter

General notice: from now on, I would like to ask everyone to put [AS2] or [AS3] (corresponding to the version of actionscript you are using on your project) in front of their post titles when the question is actionscript related! Please help us help you faster. Thank you.


Return to posts index

Amy Lee Walton
Re: (AS3) Looping 3 different videos with NetStream
on Jan 12, 2009 at 1:03:29 am

I changed the name of the flv file to scooter and it works now... must have been something I over looked! Thank you for your help! Now I can move onto audio!

-Amy Lee



Return to posts index

Amy Lee Walton
Re: (AS3) Looping 3 different videos with NetStream
on Jan 12, 2009 at 2:30:33 am

okay, not exactly working they way i wanted... since i have 3 items to look thru... i'll think i'll try array



Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2017 CreativeCOW.net All Rights Reserved
[TOP]