Hello Kirupians.
Question for curiosity as it is currently working as I want it to, but I don’t understand how I need to assign the client object to both the netstream & the netconnection to get my desired results… I’m making a video player in AS3 (actually a video player as part of a much larger Flash application). I’m not a fan of AS3 as things that should work simply don’t.
Here’s my code from the package:
public function playVideo():void
{
var client:Object = new Object();
client.onBWDone = function(e){ trace(e); }
client.onMetaData = doMetaData;
client.onCuePoint = function(e){ trace(e); }
var myVideo:Video = new Video;
addChild(myVideo);
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
ns.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorEventHandler);
ns.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
myVideo.attachNetStream(ns);
nc.client = client;
ns.client = client;
ns.play("http://www.viewtry.com/ad_images/breathalyzer.mp4");
}
public function doMetaData(infoObject:Object):void
{
var key:String;
for(key in infoObject){
trace(key+": "+infoObject[key]);
}
}
public function netStatusHandler(evt:NetStatusEvent):void
{
trace(evt.info.code);
if(evt.info.code == "NetStream.Play.Stop"){
trace("your movie has stopped");
}
}
public function asyncErrorEventHandler(event:AsyncErrorEvent):void
{
//ignore - brillant. Get a couple errors without this here.
}
I struggled for a while to get the metadata from the video that I’m pulling in… I was told that I could just use the nc.client to go back to the client object and have the onMetaData handler trace that out. But I never got any metadata - HOWEVER, the netStatusHandler will never read “NetStream.Play.Stop” unless I have that nc.client line in there - which I need to know when it stops.
Only one thing told me nc.client, all others were ns.client. When I simply changed it, I could see all my metadata from the function doMetaData - but then the “NetStream.Play.Stop” would not fire. I would still get the .Play.Start, .Buffer.Full, and .Buffer.Flush (which seems useless).
Only when I would put the two lines together (which makes no programming sense to me whatsoever:
nc.client = client;
ns.client = client;
will both things work correctly as it is now.
What gives?