as3.0 视频播放器
1.时间进度条控制
/**
* 时间条的控制
* */
protected function onMOUSE_DOWN(event:MouseEvent):void
{
_downX=mouseX;
this.removeEventListener(Event.ENTER_FRAME,onENTER_FRAME);
stage.addEventListener(MouseEvent.MOUSE_MOVE,onMOUSE_MOVE);
stage.addEventListener(MouseEvent.MOUSE_UP,onUp);
}
protected function onMOUSE_MOVE(event:MouseEvent):void
{
_res.point.x+=mouseX-_downX;
_downX=mouseX;
if(_res.point.x<_startX)
{
_res.point.x=_startX;
}
if(_res.point.x>_startX+_res.totalBar.width-_res.point.width-5)
{
_res.point.x=_startX+_res.totalBar.width-_res.point.width-5;
}
_res.nowBar.width=_res.point.x-_startX;
_nowTime=(_video.duration*(_res.point.x-_startX)/(_res.totalBar.width-_res.point.width));
// _time.x=_res.point.x-_time.width/2+_res.point.width/2;
_nowTimeText.text=String(int(Math.round(_nowTime)/60)<10?"0"+int(Math.round(_nowTime)/60):int(Math.round(_nowTime)/60))+":"+String(Math.round(_nowTime)%60<10?"0"+Math.round(_nowTime)%60:Math.round(_nowTime)%60);
_video.setSeek(_nowTime);
}
protected function onUp(event:MouseEvent):void
{
_video.resumeVideo();
this.addEventListener(Event.ENTER_FRAME,onENTER_FRAME);
stage.removeEventListener(MouseEvent.MOUSE_MOVE,onMOUSE_MOVE);
stage.removeEventListener(MouseEvent.MOUSE_UP,onUp);
}
2.视频缓冲完毕,获取视频时间
/**
*视频 缓冲完毕
* */
protected function onVideoFull(event:Event):void
{
_totalTime=_video.duration;
_video.setVideoSize(1920,1080);
if(_isStopSound)
{
_video.volume=0;
}else
{
_video.volume = _soundNum;
_sound.setVolume(_soundNum);
}
_totalTimeText.text=String(int(Math.round(_totalTime)/60)<10?"0"+int(Math.round(_totalTime)/60):int(Math.round(_totalTime)/60))+":"+String(Math.round(_totalTime)%60<10?"0"+Math.round(_totalTime)%60:Math.round(_totalTime)%60);
// _video.stopVideo();
// _totalTime=_video.duration;
// _time.setTotalTime(_totalTime);
// this.removeEventListener(Event.ENTER_FRAME,onENTER_FRAME);
this.addEventListener(Event.ENTER_FRAME,onENTER_FRAME);
}
3.播放时间,进度条,实时侦听
/**
* 实时侦听播放进度
* */
protected function onENTER_FRAME(event:Event):void
{
_nowTime=_video.playTime;
_res.nowBar.width=(_video.playTime*(_res.totalBar.width-_res.point.width)/_video.duration);
_res.point.x=_startX+int((_video.playTime*(_res.totalBar.width-_res.point.width)/_video.duration));
_nowTimeText.text=String(int(Math.round(_nowTime)/60)<10?"0"+int(Math.round(_nowTime)/60):int(Math.round(_nowTime)/60))+":"+String(Math.round(_nowTime)%60<10?"0"+Math.round(_nowTime)%60:Math.round(_nowTime)%60);
}
4. 声音条控制
protected function onDown(event:MouseEvent):void
{
_downX=mouseX;
stage.addEventListener(MouseEvent.MOUSE_MOVE,onMove);
stage.addEventListener(MouseEvent.MOUSE_UP,onUp);
}
protected function onMove(event:MouseEvent):void
{
_res.point.x+=mouseX-_downX;
_downX=mouseX;
if(_res.point.x<=0)
{
_res.point.x=0;
}
if(_res.point.x>=(_res.total.width-_res.point.width))
{
_res.point.x=_res.total.width-_res.point.width;
}
_res.bar.width=_res.point.x+_res.point.width;
}
protected function onUp(event:MouseEvent):void
{
volume=(_res.point.x/(_res.total.width-_res.point.width));
this.dispatchEvent(new Event(Event.CHANGE));
stage.removeEventListener(MouseEvent.MOUSE_MOVE,onMove);
stage.removeEventListener(MouseEvent.MOUSE_UP,onUp);
}
/**
* 声音
* */
protected function onSoundClick(event:Event):void
{
_soundNum=_sound.volume;
_video.volume=_soundNum;
_soundMc.gotoAndStop(1);
_isStopSound=false;
}

浙公网安备 33010602011771号