|
-
I want looping flv's!!!
i have got as far as i can with the following code. I'm playing multiple flv's, (which are loaded from an xml file) with success. All i want to do is to keep them looping, i cant work this out as i'm an AS3 newbie!
PHP Code:
var nc:NetConnection;
var ns:NetStream;
var listener:Object;
//
//
var xml:XML = new XML();
var loader:URLLoader = new URLLoader();
loader.load(new URLRequest("tubePanelsVID.xml"));
loader.addEventListener(
Event.COMPLETE,
function(evt:Event):void {
xml = XML(evt.target.data);
populatePics ();
}
);
function populatePics ():void {
//This will be used to represent a menu item
var picItem:PicItem;
//Counter
var i:uint = 0;
//Loop through the links found in the XML file
for each (var link:XML in xml.links.link) {
picItem = new PicItem();
//picItem.id = i;
//trace(link.@panel);
//Insert position
picItem.x = 73 + i* 255;
picItem.y = 667 + i* -127;
picItem.filters = [shadows];
addChildAt(picItem,1);
loadVid(link.@panel, picItem.myVideo);
i++;
}
setChildIndex(goingUp,numChildren - 1);
}
function loadVid(s:String, mc:Object):void {
trace(s)
nc = new NetConnection();
nc.connect(null);
ns = new NetStream(nc);
mc.attachNetStream(ns);
listener = new Object();
listener.onMetaData = onMeta;
ns.client = listener;
ns.play(s);
}
function onMeta(data:Object):void {
var totalLength:Number = data.duration;
trace(totalLength);
}
I would love a few tips on this to help me along my AS3 journey!
cheers
rat
-
Here's a workaround...detecting the end of the video and calling play() takes a while so it usually produces a noticeable skip in the looping - to get around that, listen for the playhead updates and just seek back to the beginning when you get close to the end. The trouble is that if your swf drops a few frames at the wrong moment you could miss the update and hit the end anyway so it's still necessary to watch for restarts.
PHP Code:
_v.autoRewind = true;
_v.addEventListener(VideoEvent.PLAYHEAD_UPDATE, vidLoop);
_v.addEventListener(VideoEvent.AUTO_REWOUND, restart);
private function vidLoop(e:VideoEvent):void{
if(_v.totalTime - e.playheadTime < .05) _v.seek(0);
}
private function restart(e:VideoEvent):void{
_v.play();
}
-
i couldn't get the VideoEvent code to work with my example, now i have taken 2 steps forward but having to take a step back, purly as i do not know AS3.
i just want to reload the flv's on the switch statement at the bottom of my code, it seems simple but i havn't had any luck!!!
PHP Code:
import flash.display.Sprite; import flash.events.MouseEvent; import flash.filters.DropShadowFilter; import flash.display.*; import flash.events.*; import flash.net.URLRequest;
var shadows:DropShadowFilter = new DropShadowFilter(); shadows.distance = 3; shadows.angle = 45; shadows.alpha = 0.5; shadows.blurX= 5; shadows.blurY= 5;
var nc:NetConnection; var ns:NetStream;
var xml:XML = new XML(); var loader:URLLoader = new URLLoader(); loader.load(new URLRequest("tubePanelsVID.xml"));
loader.addEventListener( Event.COMPLETE, function(evt:Event):void { xml = XML(evt.target.data); populatePics ();
} );
function populatePics ():void { //This will be used to represent a menu item var picItem:PicItem; //Counter var i:uint = 0; //Loop through the links found in the XML file for each (var link:XML in xml.links.link) {
picItem = new PicItem(); //picItem.id = i; //Insert position picItem.x = 73 + i* 255; picItem.y = 667 + i* -127;
picItem.filters = [shadows];
addChildAt(picItem,1); loadVid(link.@panel, picItem.myVideo);
i++;
} setChildIndex(goingUp,numChildren - 1);
}
function loadVid(s:String, mc:Object):void { nc = new NetConnection(); nc.connect(null); ns = new NetStream(nc); mc.attachNetStream(ns); ns.addEventListener(NetStatusEvent.NET_STATUS, onStatusEvent);
ns.client = meta; ns.play(s);
}
var meta:Object = new Object(); meta.onMetaData = function(meta:Object) { trace(meta.duration); }
function onStatusEvent(event:NetStatusEvent):void { switch (event.info.code) { case "NetStream.Play.Start": trace("Start [" + ns.time.toFixed(2) + " seconds]"); break; case "NetStream.Play.Stop": trace("Stop [" + ns.time.toFixed(2) + " seconds]"); break; } }
-
still stuck, is it far from getting a result!
should i not be using the
PHP Code:
function onStatusEvent(event:NetStatusEvent)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|