• 视频播放器


    //创建一个 NetConnection 对象 
    var netConnection:NetConnection = new NetConnection();
    /*如果连接到没有使用服务器的FLV 文件,则通过向 connect() 方法传递值
     null,来播放流式 FLV 文件*/
    netConnection.connect(null);
    /*创建一个 NetStream 对象(该对象将 NetConnection 对象作为参数)并
     指定要加载的 FLV 文件*/
    var netStream:NetStream = new NetStream(netConnection);
    netStream.play("test.flv");
    /*使用 Video 类的 attachNetStream() 方法附加以前创建的 NetStream
     对象(视频实例名为vid)*/
    vid.attachNetStream(netStream);
    //音量初始值 
    var yl:Number = 0.5;
    var nsyl:SoundTransform = new SoundTransform();
    //nsyl.volume=yl 
    
    //播放进度与加载进度影片缩放为0 
    bfjd_mc.scaleX = jzjd_mc.scaleX = 0;
    //申明变量播放与下载百分比以及总时间(秒)的初始值为0 
    var bf_percent:int = 0;
    var xz_percent:int = 0;
    var _duration:Number = 0;
    
    //指定在其上调用回调方法的对象 
    var _client:Object = new Object();
    _client.onMetaData = onMetaData;
    netStream.client = _client;
    //按钮可见性与添加侦听事件 
    play_btn.visible = false;
    pause_btn.visible = true;
    pause_btn.addEventListener(MouseEvent.CLICK, zt);
    play_btn.addEventListener(MouseEvent.CLICK, bf);
    //忽略错误 
    netStream.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);
    
    function asyncErrorHandler(event:AsyncErrorEvent):void {
    }
    
    //暂停 
    function zt(event:MouseEvent):void {
    	play_btn.visible = true;
    	pause_btn.visible = false;
    	//视频暂停 
    	netStream.pause();
    }
    
    //播放 
    function bf(event:MouseEvent):void {
    	play_btn.visible = false;
    	pause_btn.visible = true;
    	//恢复回放暂停的视频流 
    	netStream.resume();
    	addEventListener(Event.ENTER_FRAME, gx);
    }
    
    //接收在正播放的 FLV 文件中嵌入的描述性信息时调度 
    function onMetaData(data:Object):void {
    	_duration = data.duration;
    }
    //申明变量播放信号 
    var bfxh:String;
    //侦听视频流的开始和末尾 
    netStream.addEventListener(NetStatusEvent.NET_STATUS, statusHandler);
    
    function statusHandler(event:NetStatusEvent):void {
    	bfxh = event.info.code;
    }
    //不断更新进度与文本的显示 
    addEventListener(Event.ENTER_FRAME, gx);
    
    function gx(event:Event):void {
    	if (netStream.bytesLoaded > 0){
    		//加载进度 
    		xz_percent = netStream.bytesLoaded / netStream.bytesTotal * 100;
    		jzjd_mc.scaleX = xz_percent / 100;
    	}
    
    	if (_duration > 0 && netStream.time > 0){
    		//播放进度 
    		bf_percent = netStream.time / _duration * 100;
    		bfjd_mc.scaleX = bf_percent / 100;
    	}
    	
    	if (bfxh == "NetStream.Play.Stop"){
    		//播放完毕时的设置 
    		bf_percent = 0;
    		bfjd_mc.scaleX = 0;
    		netStream.close();
    		//netStream.pause();
    		//netStream.seek(0); //将播放头置于视频开始处 
    		play_btn.visible = true;
    		pause_btn.visible = false;
    	}
    	//文本显示内容 
    	bftxt.text = Math.round(netStream.time / 60) + ":" + Math.round(netStream.time % 60);
    	zcdtxt.text = Math.round(_duration / 60) + ":" + Math.round(_duration % 60);
    	//音量控制 
    	yl = (ylhk_mc.x - 345) / 50;
    	ylt_mc.scaleX = yl;
    	nsyl.volume = yl;
    	netStream.soundTransform = nsyl;
    }
    //音量滑块拖动控制 
    var fw:Rectangle = new Rectangle(345, 328, 50, 0); //拖动范围 
    ylhk_mc.addEventListener(MouseEvent.MOUSE_DOWN, ylhkax);
    ylhk_mc.addEventListener(MouseEvent.MOUSE_UP, ylhksk);
    stage.addEventListener(MouseEvent.MOUSE_UP, ylhksk);
    
    function ylhkax(event:MouseEvent):void {
    	ylhk_mc.startDrag(false, fw);
    }
    
    function ylhksk(event:MouseEvent):void {
    	ylhk_mc.stopDrag();
    }
    
  • 相关阅读:
    环境部署:Linux下查看JDK安装路径
    环境部署(一):Linux下安装JDK
    linux常见命令
    设计用例
    测试用例的优先级
    快速幂和快速乘
    docker-compose安装
    jmeter通过命令生成自动测试报告
    jmeter环境变量配置
    java将毫秒转化为当前时间
  • 原文地址:https://www.cnblogs.com/leon3286/p/1901363.html
Copyright © 2020-2023  润新知