as3.0視頻的快進有拖動條
阿新 • • 發佈:2018-08-03
lse type geo pau iss mod mouse imp ring
package com{ import flash.display.MovieClip; import flash.events.MouseEvent; import fl.video.FLVPlayback; import fl.video.MetadataEvent; import flash.events.AsyncErrorEvent; import flash.net.NetConnection; import flash.net.NetStream; import flash.media.Video; importflash.utils.Timer; import flash.events.TimerEvent; import fl.video.VideoPlayer; import flash.media.SoundTransform; import flash.display.SimpleButton; import flash.geom.Rectangle; public class MyFlv extends MovieClip { private var dragMc:MovieClip; private varlineMc:MovieClip; private var backBtn:SimpleButton; private var stageMc:Object; private var emptyMc:MovieClip; private var progressMc:MovieClip; private var bounds:Rectangle; private var lineMcWidth:Number; private var lineMcX:Number;private var mcN:uint; //private var mm:MyMusic=new MyMusic(); public function MyFlv(_emptyMc:MovieClip) { emptyMc=_emptyMc; //MyMusic.initialSound("看一看"); } public function FlvFun(_dragMc:MovieClip ,_lineMc:MovieClip ,_stageMc:Object ,_progressMc:MovieClip ){ progressMc=_progressMc; dragMc=_dragMc; lineMc=_lineMc; stageMc=_stageMc; lineMcX=lineMc.x; bounds=new Rectangle(lineMc.x,lineMc.y,lineMc.width,0); dragMc.buttonMode=true; dragMc.addEventListener(MouseEvent.MOUSE_DOWN,dragFun); dragMc.addEventListener(MouseEvent.MOUSE_UP,dragFun); stageMc.addEventListener(MouseEvent.MOUSE_UP,dragFun); } private function dragFun(e:MouseEvent):void { if (e.type=="mouseDown") { e.target.startDrag(false,bounds); dragMc.addEventListener(MouseEvent.MOUSE_MOVE,dragFun); timer.stop(); } else if (e.type=="mouseUp") { stopDrag(); timer.start(); dragMc.removeEventListener(MouseEvent.MOUSE_MOVE,dragFun); } else if (e.type=="mouseMove") { vidProgressNum=vidTotalTime*(dragMc.x-lineMc.x)/lineMc.width ; ns.seek(vidProgressNum); var i:int=progressMc.totalFrames*(dragMc.x-lineMc.x)/lineMc.width; progressMc.gotoAndStop(i); } } //video===================================================== private var videoPath:String; private var vid:VideoPlayer; private var timer:Timer=new Timer(25); private var vidNowTime:Number; private var vidTotalTime:Number; private var vidProgressNum:Number; private var nc:NetConnection; public var ns:NetStream; private var soundTF:SoundTransform; private var obj:Object =new Object (); public function VideoFun() { vid=new VideoPlayer(1435.55,808.4); vid.x=241 vid.y=205.4 vid.smoothing=true; nc= new NetConnection(); nc.connect(null); ns=new NetStream(nc); ns.play("sdfsd.mp4"); vidTotalTime=vid.totalTime; vid.attachNetStream(ns); //ns.pause(); ns.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler); function asyncErrorHandler(event:AsyncErrorEvent):void { // 忽略錯誤 } obj.onMetaData=onMetaData; ns.client=obj; function onMetaData(data:Object):void { vidTotalTime=data.duration; } emptyMc.addChild(vid); timer.addEventListener(TimerEvent.TIMER,tiemrFun); //timer.start(); //聲音========================= //soundTF=ns.soundTransform;//控制的目標 //soundTF.volume=0;//設置目標的聲音為0 //ns.soundTransform=soundTF; } private function tiemrFun(e:TimerEvent) { vidNowTime=ns.time; dragMc.x = (lineMc.width) * vidNowTime / vidTotalTime + (lineMc.x); var i:int=progressMc.totalFrames*(dragMc.x-lineMc.x)/lineMc.width; progressMc.gotoAndStop(i); } //================togglePause private var togglePause:SimpleButton; public function togglePauseFun(_togglePause:SimpleButton) { togglePause=_togglePause; togglePause.alpha=1; togglePause.addEventListener(MouseEvent.CLICK,ontogglePause); } private function ontogglePause(e:MouseEvent) { //MyMusic.pauseFuntion() //MyMusic.isSoundPlay=false if (togglePause.alpha==0) { togglePause.alpha=1; } else { togglePause.alpha=0; } ns.togglePause(); } //===============up.down private var nextBtn:SimpleButton; private var prevBtn:SimpleButton; public function nextOrPrev(_nextBtn:SimpleButton,_prevBtn:SimpleButton) { prevBtn=_prevBtn; nextBtn=_nextBtn; nextBtn.addEventListener(MouseEvent.CLICK,onBtn); prevBtn.addEventListener(MouseEvent.CLICK,onBtn); } private function onBtn(e:MouseEvent) { if (e.target.name=="nextBtn") { ns.seek(vidNowTime+=5); } else { ns.seek(vidNowTime-=5); } } public function backFun(_backBtn:SimpleButton ) { backBtn=_backBtn; backBtn.addEventListener(MouseEvent.CLICK ,backBtnFun); } public function backBtnFun(e:MouseEvent ) { timer.removeEventListener(TimerEvent.TIMER,tiemrFun); dragMc.removeEventListener(MouseEvent.MOUSE_MOVE,dragFun); dragMc.removeEventListener(MouseEvent.MOUSE_DOWN,dragFun); dragMc.removeEventListener(MouseEvent.MOUSE_UP,dragFun); stageMc.removeEventListener(MouseEvent.MOUSE_UP,dragFun); emptyMc.removeChild(vid); } } }//ns.close();
as3.0視頻的快進有拖動條