标题: [AS3]as3写的FLV播放器源代码完整实例 [打印本页] 作者: jekeyhui99 时间: 2016-8-19 17:02 标题: [AS3]as3写的FLV播放器源代码完整实例 一个简单的FLV播放器,应用了NetConnection类,NetStream类以及Video类,在创建视频之前在NetStream类对象上注册了onMetaData事件和NET_STATUS事件
import flash.media.*;
import flash.net.URLStream;
import flash.net.NetConnection;
var movieTotalTime:Number=0;//CuPlayer.com提示:总时间
var proTime:Number=0;//已经播放的时间
var dx=drag.x;
var lx=line.x;
var dw=drag.width;
var lw=line.width;
var tempProgress;
var now=true;
btn.buttonMode=true;
line.line_b.scaleX=0;//CuPlayer.com提示:进度条控制
var videoconnection:NetConnection=new NetConnection();//创建一个NetConnection对象.
videoconnection.connect(null);
var videostream:NetStream=new NetStream(videoconnection);//建立一个NetStream对象,连接到NetConnection里面去.
line.addEventListener(MouseEvent.MOUSE_DOWN,dragdown);
line.addEventListener(MouseEvent.MOUSE_UP,dragup);
function dragdown(e:MouseEvent) {
drag.x=mouseX;
proTime=(drag.x-dx)/line.width*movieTotalTime;//当前播放的时间
videostream.seek(proTime);
}
function dragup(e:MouseEvent) {
removeEventListener(MouseEvent.MOUSE_DOWN,dragdown);
}
addEventListener(Event.ENTER_FRAME,dragmove);
function dragmove(e:Event) {
if (movieTotalTime!=0) {
tempProgress=Math.ceil(videostream.time/movieTotalTime*100)/100;
}
line.line_b.scaleX=tempProgress;
drag.x=Math.round(tempProgress*line.width)+dx-dw;
var ld_minutes=Math.ceil(videostream.time);
var n_minutes=Math.floor(ld_minutes/60);
var p_minutes=Math.floor(ld_minutes%60);
//CuPlayer.com提示:秒数转化为时间显示
if (p_minutes<10) {
if (n_minutes<1) {
proTitle.text="00"+":"+"0"+String(ld_minutes);
} else {
proTitle.text="0"+String(n_minutes)+":"+"0"+String(p_minutes);
}
} else {
proTitle.text="0"+String(n_minutes)+":"+String(p_minutes);
}
var str:String;
var my_minutes=Math.floor(movieTotalTime/60);//得到分钟的正整数
var my_seconds=Math.floor(movieTotalTime%60);//得到秒钟的正整数
if (my_seconds<10) {
str="0"+String(my_seconds);
} else {
str=String(my_seconds);
}
troTitle.text=String(100+my_minutes).substr(1,2)+":"+str;
}
function bt_down(e:MouseEvent):void {
now!=now;
if (now) {
videostream.pause();
btn_mc.visible=true;
btn.gotoAndStop(2);
now=false;
} else {
btn_mc.visible=false;
videostream.resume();
btn.gotoAndStop(1);
now=true;
}
if (tempProgress>=1) {
drag.x=dx;
btn_mc.visible=false;
videostream.seek(0);
videostream.resume();
function fullScreen(e:MouseEvent):void {
if (stage.displayState==StageDisplayState.NORMAL) {
stage.displayState=StageDisplayState.FULL_SCREEN;
} else if (stage.displayState ==StageDisplayState.FULL_SCREEN) {
stage.displayState=StageDisplayState.NORMAL;
}
}
//CuPlayer.com提示:声音控制
var sound:SoundTransform =new SoundTransform();
var volumes:Number=sound.volume;
videostream.soundTransform=sound;
btn_sy.gotoAndStop(7);
for (var j:uint=1; j<=7; j++) {
var s_btn:MovieClip=btn_sy.an.getChildAt(j-1) as MovieClip;
s_btn.addEventListener(MouseEvent.MOUSE_DOWN,set_volume);
}
function set_volume(e:MouseEvent):void {
var _mc=e.currentTarget;
var k:Number=btn_sy.an.getChildIndex(_mc);
btn_sy.gotoAndStop(k+1);
sound.volume=(k+1)/7;
videostream.soundTransform=sound;
}