宜昌本地软件开发与弱电工程服务商
项目咨询 · 快速响应
您当前的位置: > 博客2 > 播放器教程

[AS3]as3中视频播放器截图功能实现源代码实现

2016-10-13 00:16:48 点击量:85 标签: 收藏本文

[AS3]as3中视频播放器截图功能实现源代码实现

  1. package  
  2.  
  3.    import Main.*; 
  4.    import flash.display.*; 
  5.    import flash.events.*; 
  6.    import flash.media.*; 
  7.    import flash.net.*; 
  8.    import flash.utils.*; 
  9.  
  10.    public class Main extends Sprite 
  11.    { 
  12.        private var _filePath:String = "/cuplayer/cuplayer.com.flv"
  13.        private var _ns:NetStream; 
  14.        private var _bmp:Bitmap; 
  15.        private var _metaDataObj:Object; 
  16.        private var _nc:NetConnection; 
  17.        private var _video:Video; 
  18.  
  19.        public function Main() : void 
  20.        { 
  21.            this._metaDataObj = {}; 
  22.            if (stage) 
  23.            { 
  24.                this.init(); 
  25.            } 
  26.            else 
  27.            { 
  28.                addEventListener(Event.ADDED_TO_STAGE, this.init); 
  29.            } 
  30.            return; 
  31.        } 
  32.  
  33.        private function getMetaData(param1:Object) : void 
  34.        { 
  35.            var _loc_2:Object = null
  36.            trace("=CuPlayer.com1==================="); 
  37.            for (_loc_2 in param1) 
  38.            { 
  39.                 
  40.                trace(_loc_2, param1[_loc_2]); 
  41.            } 
  42.            trace("=CuPlayer.com2===================="); 
  43.            return; 
  44.        }// end function 
  45.  
  46.        private function init(event:Event = null) : void 
  47.        { 
  48.            removeEventListener(Event.ADDED_TO_STAGE, this.init); 
  49.            this._nc = new NetConnection(); 
  50.            this._nc.connect(null); 
  51.            this._ns = new NetStream(this._nc); 
  52.            thisthis._ns.client = this._metaDataObj; 
  53.            thisthis._metaDataObj.onMetaData = this.getMetaData; 
  54.            this._ns.addEventListener(NetStatusEvent.NET_STATUS, this.onNsConnected); 
  55.            var _loc_2:* = Camera.getCamera(); 
  56.            this._video = new Video(_loc_2.width, _loc_2.height); 
  57.            this._video.smoothing = true
  58.            this._video.attachNetStream(this._ns); 
  59.            this._ns.play(this._filePath); 
  60.            addChild(this._video); 
  61.            return; 
  62.        } 
  63.  
  64.        private function pause() : void 
  65.        { 
  66.            this._ns.close(); 
  67.            addChild(this._bmp); 
  68.            thisthis._bmp.x = this._video.width + 5; 
  69.            removeEventListener(Event.ENTER_FRAME, this.captureBmp); 
  70.            return; 
  71.        } 
  72.  
  73.        private function onNsConnected(event:NetStatusEvent) : void 
  74.        { 
  75.            trace(event.info.code); 
  76.            switch(event.info.code) 
  77.            { 
  78.                case "NetStream.Play.Start": 
  79.                { 
  80.                    trace("准备播放"); 
  81.                    setTimeout(this.pause, 1000); 
  82.                    addEventListener(Event.ENTER_FRAME, this.captureBmp); 
  83.                    break; 
  84.                } 
  85.                case "NetStream.Play.StreamNotFound": 
  86.                { 
  87.                    trace("找不到文件"); 
  88.                    break; 
  89.                } 
  90.                case "NetStream.Play.Stop": 
  91.                { 
  92.                    trace("播放已停止"); 
  93.                    break; 
  94.                } 
  95.                default: 
  96.                { 
  97.                    break; 
  98.                } 
  99.            } 
  100.            return; 
  101.        } 
  102.  
  103.        private function captureBmp(event:Event) : void 
  104.        { 
  105.            var _loc_2:* = new BitmapData(this._video.width, this._video.height); 
  106.            _loc_2.draw(this._video); 
  107.            this._bmp = new Bitmap(_loc_2); 
  108.            trace("a"); 
  109.            return; 
  110.        } 
  111.  
  112.    } 

 

ABOUT US
宜昌农人网络科技有限公司

我们是一家提供综合软件外包与弱电工程服务的技术公司。

业务涵盖定制软件、管理系统、网站、小程序、APP、系统集成、网络布线、监控安防、门禁、机房建设及长期技术维护。

公司地址:湖北省宜昌市伍家岗区东站二路6号三峡(宜昌)大数据产业园海洋馆二楼A203室