flash+red5播放实例

var my_nc:NetConnection = new NetConnection();
my_nc.connect("您要连接RED5应用程序");
var my_ns:NetStream = new NetStream(my_nc);
var videointerval;
myVideo.attachVideo(my_ns);
my_nc.onStatus = function(thisObj:Object) {
if (thisObj.code == "NetConnection.Call.Failed") {
trace("连接状态: "+info.code);
trace("NetConnection.call方法调用服务器端的方法或命令失败");
} else if (thisObj.code == "NetConnection.Connect.AppShutdown") {
trace("连接状态: "+info.code);
trace("服务器端应用程序已经关闭(由于资源耗用过大等原因)或者服务器已经关闭");
} else if (thisObj.code == "NetConnection.Connect.Closed") {
trace("连接状态: "+thisObj.code);
trace("错误:服务器未启动或URI输入错误.");
} else if (thisObj.code == "NetConnection.Connect.Failed") {
trace("连接状态: "+thisObj.code);
trace("连接失败");
} else if (thisObj.code == "NetConnection.Connect.InvalidApp") {
trace("连接状态: "+thisObj.code);
trace("指定的应用程序名称没有找到");
} else if (thisObj.code == "NetConnection.Connect.Rejected") {
trace("连接状态: "+thisObj.code);
trace("连接被拒绝");
} else if (thisObj.code == "NetConnection.Connect.Success") {
trace("连接状态: "+thisObj.code);
}
};
startplay.onRelease = function() {
 
my_ns.play("music/1-2.flv");
//  addChild(myVideo);  
videointerval = setInterval(flv_ntime, 100);
};
//startplay.addEventListener("click", playLastVideo);
//stopplay.addEventListener("click",stopplayVideo);
stopplay.onRelease=function()
{
if(_root.stopplay.label == "暂停播放")
{
  stopplay.label="继续播放";
}else if(_root.stopplay.label =="继续播放")
{
  stopplay.label="暂停播放"
}
// videointerval = setInterval(flv_ntime, 100,my_ns);
my_ns.pause();
}



//my_ns.onStatus = function(infoObject:Object) {
//trace("NetStream.onStatus called: ("+getTimer()+" ms)");
//for (var prop in infoObject) {
//trace("\t"+prop+":\t"+infoObject[prop]);
//}

//}
var flv_duration;
my_ns.onMetaData = function(infoObject:Object) {
//获得FLV文件中嵌入的描述性信息,这里获得获得总持续时间(单位:秒)
trace("df");
var flv_duration = infoObject.duration;
var flv_width = infoObject.width;
var flv_height = infoObject.height;

var min:Number = Math.floor(flv_duration/60);
var sec = Math.floor(flv_duration%60);
if (sec<10) {
   sec = "0"+sec;
}
ztime.text = min+":"+sec;
_global.zt=flv_duration;
trace(_global.zt);
};
//注意:这里可以和获得宽高写在一起。
//获取当前播放时间

function flv_ntime() {
var flv_thistime = my_ns.time;
var cmin:Number = Math.floor(flv_thistime/60);
var csec = Math.floor(flv_thistime%60);
cseed._x=300*(flv_thistime/zt)+69
if (csec<10) {
   csec = "0"+csec;
}
ntime.text = cmin+":"+csec;

if(ntime.text==ztime.text){
trace("停止");
//  pix_end.gotoAndPlay(2);
     clearInterval(videointerval)
   }
}
//RED5应用程序需自己配制
  开户REd5服务器可以运行

你可能感兴趣的:(应用服务器,Flash)