/**
* ...
*/
public class Player extends Sprite
{
private var video:Video;
private var ns:NetStream;
private var url:String;
public var loop:Boolean;
public var state:String = "stop";
public function Player(vw:int,vh:int)
{
var nc:NetConnection = new NetConnection();
nc.connect(null);
video = new Video(vw, vh);
addChild(video);
video.smoothing = true;
ns = new NetStream(nc);
ns.addEventListener(NetStatusEvent.NET_STATUS, onState);
var obj:Object = new Object();
ns.client = obj;
obj.onMetaData = videoInfo;
video.attachNetStream(ns);
addEventListener(Event.REMOVED_FROM_STAGE, kill);
}
public function setSize(w:int,h:int):void
{
video.width = w;
video.height = h;
}
public function play(url:String,loop:Boolean):void
{
video.clear();
ns.close();
this.url = url;
this.loop = loop;
ns.play(url);
state = "playing";
}
public function pause():void
{
ns.pause();
state = "pause";
}
public function resume():void
{
ns.resume();
state = "playing";
}
private function onState(e:NetStatusEvent):void
{
trace(e.info.code)
if (e.info.code == "NetStream.Play.Stop"){
if (loop){
ns.play(url);
}else{
ns.close();
state = "stop";
dispatchEvent(new Event(Event.COMPLETE));
}
}
}
private function kill(e:Event):void
{
video.clear();
ns.close();
}
private function videoInfo(info:Object):void
{
//time = info.duration;
}
}