• 视频类 的练习


                                                                      视频播放器

    首先做好UI界面,本播放器有自带的截图功能

    package  {
     
     import flash.display.BitmapData;
     import flash.display.MovieClip;
     import flash.events.AsyncErrorEvent;
     import flash.events.Event;
     import flash.events.MouseEvent;
     import flash.geom.Rectangle;
     import flash.media.SoundTransform;
     import flash.media.Video;
     import flash.net.FileReference;
     import flash.net.NetConnection;
     import flash.net.NetStream;
     import flash.utils.ByteArray;
     import JPGEncoder.JPGEncoder;
     
     
     public class videoPlayer extends MovieClip {
      
      private var netS:NetStream;
      private var netC:NetConnection;
      private var video:Video;
      private var flag:int = 1;
      private var soundT:SoundTransform;
      private var totalTimes:Number = 0;
      private var fullflag:Boolean;
      
      public function videoPlayer()
      {
       initBar();
       init();
       SetDispatcher();
      }
      private function  initBar():void
      {
       __bar1.scaleX = 0;
       __bar2.scaleX = 0;
       
      }
      private function init():void
      {
       netC = new NetConnection();
       netC.connect(null);
       netS = new NetStream(netC);
       netS.play('1.flv');
       netS.addEventListener(AsyncErrorEvent.ASYNC_ERROR, onMeta);
       video = new Video();
       video.attachNetStream(netS);
       video.x = 5;
       video.y = 3;
       this.addChild(video);
       addEventListener(Event.ENTER_FRAME, getpro);
       var obj:Object = new Object();
       obj.onMetaData = getLen;
       netS.client = obj;
       addEventListener(Event.ENTER_FRAME, onPlaying);
       
      }
      private function onMeta(e:AsyncErrorEvent):void
      {
       
      }
      private function getpro(e:Event):void
      {
       //totalTimes = Object.duration;
       __bar1.scaleX = netS.bytesLoaded / netS.bytesTotal;
       if (netS.bytesLoaded / netS.bytesTotal == 1)
       {
        removeEventListener(Event.ENTER_FRAME, getpro);
       }
       
      }
      private function onPlaying(e:Event):void
      {
       __bar2.scaleX = netS.time / totalTimes;
      }
      private function SetDispatcher():void
      {
       netS.seek(0);
       netS.togglePause();
       play_stop.buttonMode = true;
       stop_btn.buttonMode = true;
       bar._bar.buttonMode = true;
       jieP.buttonMode = true;
       
       bar._bar.addEventListener(MouseEvent.MOUSE_DOWN, ondown);
       bar._bar.addEventListener(MouseEvent.MOUSE_UP, onup);
       stage.addEventListener(MouseEvent.MOUSE_UP, onup);
       play_stop.addEventListener(MouseEvent.CLICK, onps);
       stop_btn.addEventListener(MouseEvent.CLICK, onstop);
       jieP.addEventListener(MouseEvent.CLICK, onjiep);
       
       
      }
      private function ondown(e:MouseEvent):void
      {
       bar._bar.startDrag(true, new Rectangle(0, 0, bar.bar2.width, 0));
      }
      private function onup(e:MouseEvent):void
      {
       bar._bar.stopDrag();
       if (bar._bar.x > bar.bar2.width)
       {
        bar._bar.x = bar.bar2.width;
       }
       soundT = new SoundTransform();
       soundT.volume = bar._bar.x / bar.bar2.width;
       netS.soundTransform = soundT;
      }
      private function getLen(obj:Object):void
      {
       totalTimes = obj.duration;
      }
      private function onps(e:MouseEvent):void
      {
       netS.togglePause();
       if (flag == 1)
       {
        flag = 2;
        play_stop.gotoAndStop(flag);
       }else
       {
        flag = 1;
        play_stop.gotoAndStop(flag);
       }
      }
      private function onstop(e:MouseEvent):void
      {
       flag = 1;
       netS.pause();
       netS.seek(0);
       play_stop.gotoAndStop(flag);
       
      }
      private function onjiep(e:MouseEvent):void
      {
       var bitmapdata:BitmapData = new BitmapData(video.width, video.height);
       bitmapdata.draw(video);
       var jpgEncode:JPGEncoder = new JPGEncoder();
       var bytesArr:ByteArray=ByteArray(jpgEncode.encode(bitmapdata));
       var file:FileReference = new FileReference();
       file.addEventListener(Event.SELECT, onselect);
       file.addEventListener(Event.CANCEL, oncancel);
       file.save(bytesArr, "未命名.jpg");
      }
      private function onselect(e:Event):void
      {
       trace("图片已保存");
      }
      private function oncancel(e:Event):void
      {
       trace("你取消了保存");
      }
     }
     
    }

                                                       系统播放器

    首先从主件元件中拉出视屏类主件(FLVplayback),然后写上如下代码:

    import fl.video.FLVPlayback;
    mc.source = "1.flv";
    mc.skinBackgroundColor = 0xff0000;
    mc.skinBackgroundAlpha = 1;

  • 相关阅读:
    MonoRail学习Component
    Eclipse中用户库的使用
    ASP.Net2.0中自定义控件在page中的注册
    WF学习Console Workflow Application
    Which Style of Workflow When?[转]
    使用UserControl时,在Page中定义方式
    参数类型异常
    GridView使用一些记录
    在使用Mybatis进行测试时出现报错:Caused by: java.lang.ClassNotFoundException: Cannot find class: Student
    递归反向输出字符串
  • 原文地址:https://www.cnblogs.com/klh5211314/p/2763375.html
Copyright © 2020-2023  润新知