as3.0视频的快进有拖动条
Posted zqiang0803
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了as3.0视频的快进有拖动条相关的知识,希望对你有一定的参考价值。
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; import flash.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 var lineMc: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视频的快进有拖动条的主要内容,如果未能解决你的问题,请参考以下文章
关于前端video标签视频无法拖动进度条快进问题(Django)