I have a class which load and play a flv video file. My problem is, How can I get the flv`s duration in my main code? ..
This is my video class:
package src {
import flash.display.Sprite;
import flash.media.Video;
import flash.net.NetConnection;
import flash.net.NetStream;
import flash.events.Event;
import flash.events.MouseEvent;
public class vplayer extends Sprite{
public var vid:Video = new Video(1920,1080);
private var nc:NetConnection = new NetConnection();
public var ns:NetStream;
public var listener:Object = new Object();
public function vplayer():void{
addChild(vid);
nc.connect(null);
ns = new NetStream(nc);
vid.attachNetStream(ns);
listener.onMetaData = metaDataHandler;
ns.client = listener;
//customClient.onCuePoint = cuePointHandler;
}
public var time00:Number = 0;
public function playVideo00():void{
ns.play("image00/mov00.flv");
}
public function stopVideo00():void{
ns.close();
}
/*public function cuePointHandler(infoObject:Object):void {
trace("cuePoint");
}*/
public function metaDataHandler(infoObject:Object):void {
trace (" Time: " + infoObject["duration"]);
}
}
}
.. and in my main class I have:
Veed = new vplayer();
addChild(Veed);
Veed.playVideo00();
After running program I have ” Time: 6.76″ in output windows and it plays flv fine, which is correct but I want something like
var myTD:int = Veed.getDuration();
in my main class to get the duration. It seems easy but I cannot make it done yet!! Any help?
Add a private var at the top:
Update this like so:
Now create a getter for duration.
Now you can do a:
The meta data will be retrieved even milliseconds after it’s requested, meaning if you try fetch the duration immediately after fetching the meta data, it wouldn’t have loaded yet. Try this as an example: