加载视频看完重看,有拖动

package com{
    import flash.display.MovieClip;
    import flash.net.NetConnection;
    import flash.net.NetStream;
    import flash.events.AsyncErrorEvent;
    import flash.events.MouseEvent;
    import flash.media.Video;
    import flash.display.SimpleButton;
    import flash.events.Event;
    import flash.display.Loader;
    import flash.net.URLLoader;
    import flash.net.URLRequest;
    import flash.utils.Timer;
    import flash.events.TimerEvent;
    import flash.system.fscommand;
    import flash.media.SoundMixer;
    import flash.media.SoundTransform;
    import flash.display.Stage;
    import flash.geom.Rectangle;

    public class JYSLoader extends MovieClip {

        public static var nc:NetConnection;
        public static var ns:NetStream;
        public static var vid:Video;
        public static var emptyMc:MovieClip;
        public static var vidTotalTime:Number;
        public static var vidNowTime:Number;
        public static var obj:Object =new Object ();

        public static var videoPath:String;
        public static var vidProgressNum:Number;

        public static var soundTF:SoundTransform;

        public static var loader:Loader;
        public static var urlR:URLRequest;
        public static var backBtn:SimpleButton;
        public static var timer:Timer=new Timer(25);
        public static var thisMc:MovieClip;
        public static var stageMc:Stage;

        //视频====================================================================================================
        public function JYSLoader(_thisMc:MovieClip ,_stageMc:Stage) {
            thisMc=_thisMc;
            stageMc=_stageMc;
        }
        public function vidFun() {
            nc= new NetConnection();
            nc.connect(null);
            ns=new NetStream(nc);
            ns.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);
            ns.close();
            vid=new Video(1920,1080);
            function asyncErrorHandler(event:AsyncErrorEvent ):void {
                // 忽略错误
            }
            //vid.x=167.25;
            //vid.y=92.45;
            obj.onMetaData=onMetaData;
            ns.client=obj;
            function onMetaData(data:Object):void {
                vidTotalTime=data.duration;
            }
            vid.attachNetStream(ns);
            ns.pause();
            vid.smoothing=true;
        }

        //加载====================================================================================================

        public static function addMP4(str:String,_emptyMc:MovieClip,num:Number ) {
            emptyMc=_emptyMc;

            var string=stageMc.loaderInfo.url;
            var str1:int=string.lastIndexOf("/");
            var str2:String=string.slice(0,str1+1);
            ns.play(str2+"vid/"+str+".mp4");
            emptyMc.addChildAt(vid,num);
            /*if (timer.hasEventListener(TimerEvent.TIMER)==false) {
                timer.addEventListener(TimerEvent.TIMER,timerFun);
                timer.start();
            }*/
        }

        public static function timerFun(e:TimerEvent) {
            vidNowTime=ns.time;
            dragMc.x=int(lineMc.width*vidNowTime/vidTotalTime)+lineMc.x;
            var i:int=vidNowTime*lineMc.totalFrames/vidTotalTime;
            lineMc.gotoAndStop(i);
            if (vidTotalTime-vidNowTime<0.05||emptyMc.numChildren==0) {
                timer.removeEventListener(TimerEvent.TIMER,timerFun);
                ns.pause();
            }
        }

        //卸载====================================================================================================
        public static function removeMP4() {
            if (ns.time!=0) {
                ns.close();
                emptyMc.removeChild(vid);
                timer.removeEventListener(TimerEvent.TIMER,timerFun);
            }
        }

        //加载swf======================================================================================================

        public static function addSwf(swfStr:String,_emptyMc:MovieClip,num:Number ) {
            emptyMc=_emptyMc;
            removeMP4();
            if (emptyMc.numChildren!=0) {
                loader.unloadAndStop();
                while (emptyMc.numChildren>0) {
                    emptyMc.removeChildAt(0);
                }
            }
            if (emptyMc.numChildren==0) {

                var string=stageMc.loaderInfo.url;
                var str1:int=string.lastIndexOf("/");
                var str2:String=string.slice(0,str1+1);

                loader= new Loader();
                urlR = new URLRequest(str2+swfStr+".swf");
                loader.load(urlR);
                emptyMc.addChildAt(loader,num);

                //var loaderContent=loader.content;
                //trace(loaderContent.totalFrames)
                //loader.contentLoaderInfo.addEventListener(Event.COMPLETE,onLoader);
            }

        }

/*        public static function onLoader(e:Event) {
            loader.contentLoaderInfo.removeEventListener(Event.COMPLETE,onLoader);
            emptyMc.addChildAt(loader,0);
        }*/
        public static function removeSwf() {
            if (emptyMc.numChildren!=0) {
                loader.unloadAndStop();
                while (emptyMc.numChildren>0) {
                    emptyMc.removeChildAt(0);
                }
            }
        }

        //清空emptyMc
        public static function clearEmpty() {
            if (ns.time!=0) {
                ns.close();
                emptyMc.removeChild(vid);
            }
            if (emptyMc.numChildren!=0) {
                loader.unloadAndStop();
                while (emptyMc.numChildren>0) {
                    emptyMc.removeChildAt(0);
                }
            }
        }

        public static var lineMcWidth:Number;
        public static var lineMcX:Number;
        public static var mcN:uint;
        public static var bounds:Rectangle;

        public static var dragMc:MovieClip;
        public static var lineMc:MovieClip;
        public static function FlvFun(_dragMc:MovieClip ,_lineMc:MovieClip ,_stageMc:Stage ) {

            dragMc=_dragMc;
            lineMc=_lineMc;
            stageMc=_stageMc;
            lineMc.stop();
            dragMc.x=lineMc.x;
            dragMc.y=lineMc.y;
            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);

        }
        public static 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") {
                dragMc.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=lineMc.totalFrames*(dragMc.x-lineMc.x)/lineMc.width;
                lineMc.gotoAndStop(i);
            }
        }

        //================togglePause
        public static var togglePause:MovieClip;
        public static function togglePauseFun(_togglePause:MovieClip) {
            togglePause=_togglePause;
            togglePause.stop();
            togglePause.addEventListener(MouseEvent.CLICK,ontogglePause);
        }
        public static function ontogglePause(e:MouseEvent) {
            if (togglePause.currentFrame==1) {
                togglePause.gotoAndStop(2);
            } else {
                togglePause.gotoAndStop(1);
            }
            ns.togglePause();
        }

        //声音=========================
        public static var voiceMc:MovieClip;
        public static var rec:Rectangle;
        public static function voiceFun(_voiceMc:MovieClip) {
            voiceMc=_voiceMc;
            voiceMc.stop();
            voiceMc.addEventListener(MouseEvent.MOUSE_UP ,onVoice);
        }
        public static function onVoice(e:MouseEvent ) {
            if (voiceMc.currentFrame==1) {
                voiceMc.nextFrame();
                soundTF=ns.soundTransform;//控制的目标
                soundTF.volume=0;//设置目标的声音为0
                ns.soundTransform=soundTF;
            } else {
                voiceMc.prevFrame();
                soundTF=ns.soundTransform;//控制的目标
                soundTF.volume=1;//设置目标的声音为0
                ns.soundTransform=soundTF;
            }

        }

    }
}

原文地址:https://www.cnblogs.com/zqiang0803/p/10789944.html

时间: 2024-11-09 00:51:36

加载视频看完重看,有拖动的相关文章

videojs 动态加载视频

VideoJS dynamic source change via RESTful API 'Undefined' issue with changing RTMP source on compressed video.js build #1612 Dynamically change RTMP source #1399 根据这些问题,处理好了动态加载视频部分,src使用对象数据的方式存放,动态资源在ready的时候放入,嘻嘻

html加载视频文件的方法

在网页中怎么加载视频呢? 在body里加上下面的语句 <video        width=""      height=""       controls>//controls是播放控制 <source src="test.webm">//防止浏览器不兼容,所以2个格式 <source src="test.mp4"> </video> 另外  prelod="aut

XMLHttpRequest如何加载视频并播放

HTML5websocket的headr如何加入扩展参数博宠当家--博客里也养宠物THP509事件BEFORE_UPDATE无法完成更新THINKPHP验证码 silverlight打印,System.Exception:未知打印错误.TP323能支持PHP7吗TP5微信支付我用RESTFUL写了一个接口但是接收不到POST过来的JSO 用js写轮播图,运行结果不对,有假设问题,但是不知道怎么改~求助~个人博客欢迎支持{TP:MENU/}这个是什么意思简单的求平均值并找出最大最小值 EL表达式中

video.js分段自动加载视频【html5视频播放器】

突发奇想的需求,要在官网上放一个一个半小时的视频教程-- 然而,加载成了问题,页面是cshtml的.net混合网站,不知道哪儿的限制,导致视频加不出来. 没有办法,只能前端想办法了. 于是将视频切割成4个 依次加载自动播放.效果还可以. 代码: 引入:<link rel="stylesheet" href="//cdn.bootcss.com/video.js/6.0.0-RC.5/alt/video-js-cdn.min.css"> <scrip

Jquery实现按钮点击遮罩加载,处理完后恢复

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="EasyUiLoad.aspx.cs" Inherits="EasyUiLoad" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml

android mediaplayer VideoPlayerManager 加载视频闪屏问题排查解决

Android VideoPlayer 在滚动列表实现item视频播放(ListView控件和RecyclerView),在列表滚动时点击屏幕列表暂停,在item视频播放区域,视频播放时会出现闪屏问题. 排查解决,VideoPlayerManager->MediaPlayerWrapper.java->prepare() :                     { .prepareAsync().set(State.)(!= ) {                             

NVisionXR_iOS教程十 —— 加载视频控件

因为在下一章节我们需要和大家介绍多场景切换功能,所以在本章我们创建一个新的场景,如下图  重写NVScenePlay的生命周期  1.引用头文件#import ''NVVideoWidget.h''  2.在onCreate方法中实例话视频控件  代码:     video = [[NVVideoWidget alloc] initWithScenePlay:self WidgetName:@"video_widget"];      // 添加视频路径,可以是本地路径,也可以是网址(

加载视频缩略图列表

import android.content.ContentResolver; import android.content.Context; import android.database.Cursor; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Rect; import android.os.Bundle; import android.prov

webview加载 视频图片的 处理

- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. UIWebView *webview = [[UIWebView alloc] initWithFrame:self.view.bounds]; // [webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://