home *** CD-ROM | disk | FTP | other *** search
/ grafika-wolowiec.cba.pl / grafika-wolowiec.cba.pl.tar / grafika-wolowiec.cba.pl / res / imVideo.swf / scripts / imVideo_fla / MainTimeline.as
Text File  |  2014-01-24  |  13KB  |  401 lines

  1. package imVideo_fla
  2. {
  3.    import adobe.utils.*;
  4.    import flash.accessibility.*;
  5.    import flash.desktop.*;
  6.    import flash.display.*;
  7.    import flash.errors.*;
  8.    import flash.events.*;
  9.    import flash.external.*;
  10.    import flash.filters.*;
  11.    import flash.geom.*;
  12.    import flash.globalization.*;
  13.    import flash.media.*;
  14.    import flash.net.*;
  15.    import flash.net.drm.*;
  16.    import flash.printing.*;
  17.    import flash.profiler.*;
  18.    import flash.sampler.*;
  19.    import flash.sensors.*;
  20.    import flash.system.*;
  21.    import flash.text.*;
  22.    import flash.text.engine.*;
  23.    import flash.text.ime.*;
  24.    import flash.ui.*;
  25.    import flash.utils.*;
  26.    import flash.xml.*;
  27.    
  28.    public dynamic class MainTimeline extends MovieClip
  29.    {
  30.        
  31.       
  32.       public var file:String;
  33.       
  34.       public var cWidth:Number;
  35.       
  36.       public var cHeight:Number;
  37.       
  38.       public var player:Video;
  39.       
  40.       public var loader:Loader;
  41.       
  42.       public var videoContainer:Object;
  43.       
  44.       public var cwidth:Number;
  45.       
  46.       public var cheight:Number;
  47.       
  48.       public var connection:NetConnection;
  49.       
  50.       public var stream:NetStream;
  51.       
  52.       public var video:Video;
  53.       
  54.       public var firstPlay:Boolean;
  55.       
  56.       public var duration:uint;
  57.       
  58.       public var origVolume:Number;
  59.       
  60.       public var endTimer:Timer;
  61.       
  62.       public var pausePlaceHolder:MovieClip;
  63.       
  64.       public var playPlaceHolder:MovieClip;
  65.       
  66.       public var isPlaying;
  67.       
  68.       public var playerWidth;
  69.       
  70.       public var playerHeight;
  71.       
  72.       public var bg:MovieClip;
  73.       
  74.       public var vobject:Object;
  75.       
  76.       public var fullScreenRect:MovieClip;
  77.       
  78.       public function MainTimeline()
  79.       {
  80.          super();
  81.          addFrameScript(0,this.frame1);
  82.       }
  83.       
  84.       public function startLoading() : void
  85.       {
  86.          var vector3:Vector.<Number> = null;
  87.          this.bg = new MovieClip();
  88.          this.bg.graphics.beginFill(0);
  89.          this.bg.graphics.drawRect(0,0,stage.fullScreenWidth,stage.fullScreenHeight);
  90.          this.bg.graphics.endFill();
  91.          this.bg.visible = false;
  92.          addChild(this.bg);
  93.          try
  94.          {
  95.             this.connection = new NetConnection();
  96.             this.connection.connect(null);
  97.             this.stream = new NetStream(this.connection);
  98.             this.stream.client = this;
  99.             this.player = new Video();
  100.             addChild(this.player);
  101.             this.player.attachNetStream(this.stream);
  102.             this.stream.bufferTime = 1;
  103.             this.stream.receiveAudio(true);
  104.             this.stream.receiveVideo(true);
  105.          }
  106.          catch(e:*)
  107.          {
  108.             setTimeout(startLoading,100);
  109.             return;
  110.          }
  111.          finally
  112.          {
  113.             vector3 = new Vector.<Number>();
  114.             vector3[0] = 0;
  115.             vector3[1] = 100;
  116.             vector3[2] = 80;
  117.             vector3[3] = 50;
  118.             vector3[4] = 0;
  119.             vector3[5] = 0;
  120.             this.playPlaceHolder = new MovieClip();
  121.             this.playPlaceHolder.graphics.lineStyle(1,0);
  122.             this.playPlaceHolder.graphics.beginFill(16777215);
  123.             this.playPlaceHolder.alpha = 0.5;
  124.             this.playPlaceHolder.graphics.drawTriangles(vector3);
  125.             this.playPlaceHolder.graphics.endFill();
  126.             this.playPlaceHolder.x = (this.cWidth - 80) / 2;
  127.             this.playPlaceHolder.y = (this.cHeight - 100) / 2;
  128.             addChild(this.playPlaceHolder);
  129.             this.pausePlaceHolder = new MovieClip();
  130.             this.pausePlaceHolder.graphics.lineStyle(1,0);
  131.             this.pausePlaceHolder.graphics.beginFill(16777215);
  132.             this.pausePlaceHolder.alpha = 0.5;
  133.             this.pausePlaceHolder.graphics.drawRect(0,0,20,100);
  134.             this.pausePlaceHolder.graphics.drawRect(40,0,20,100);
  135.             this.pausePlaceHolder.graphics.endFill();
  136.             this.pausePlaceHolder.visible = false;
  137.             this.pausePlaceHolder.x = (this.cWidth - 80) / 2;
  138.             this.pausePlaceHolder.y = (this.cHeight - 100) / 2;
  139.             this.pausePlaceHolder.visible = false;
  140.             addChild(this.pausePlaceHolder);
  141.          }
  142.          stage.addEventListener(MouseEvent.CLICK,function(param1:Event):*
  143.          {
  144.             if(!isPlaying)
  145.             {
  146.                playVideo();
  147.             }
  148.             else
  149.             {
  150.                pauseVideo();
  151.             }
  152.          });
  153.          stage.addEventListener(MouseEvent.MOUSE_MOVE,function():*
  154.          {
  155.             if(isPlaying && !pausePlaceHolder.visible && stage.displayState != StageDisplayState.FULL_SCREEN)
  156.             {
  157.                pausePlaceHolder.visible = true;
  158.             }
  159.          });
  160.          stage.addEventListener(Event.MOUSE_LEAVE,function():*
  161.          {
  162.             pausePlaceHolder.visible = false;
  163.          });
  164.          stage.addEventListener(Event.FULLSCREEN,function(param1:FullScreenEvent):*
  165.          {
  166.             if(stage.displayState == StageDisplayState.FULL_SCREEN)
  167.             {
  168.                playerWidth = cWidth;
  169.                playerHeight = cHeight;
  170.                cWidth = stage.fullScreenWidth;
  171.                cHeight = stage.fullScreenHeight;
  172.                bg.visible = true;
  173.                playPlaceHolder.visible = false;
  174.                pausePlaceHolder.visible = false;
  175.                if(fullScreenRect != null)
  176.                {
  177.                   fullScreenRect.visible = false;
  178.                }
  179.             }
  180.             else
  181.             {
  182.                cWidth = playerWidth;
  183.                cHeight = playerHeight;
  184.                bg.visible = false;
  185.             }
  186.             onMetaData(vobject);
  187.          });
  188.       }
  189.       
  190.       public function playVideo() : void
  191.       {
  192.          if(this.endTimer != null)
  193.          {
  194.             this.endTimer.start();
  195.          }
  196.          if(this.firstPlay)
  197.          {
  198.             this.firstPlay = false;
  199.             this.stream.play(this.file);
  200.          }
  201.          else
  202.          {
  203.             this.stream.resume();
  204.          }
  205.          this.isPlaying = true;
  206.          this.playPlaceHolder.visible = false;
  207.       }
  208.       
  209.       public function onMetaData(param1:Object) : void
  210.       {
  211.          if(param1 != null)
  212.          {
  213.             if(this.vobject == null)
  214.             {
  215.                this.vobject = param1;
  216.             }
  217.             this.duration = param1.duration;
  218.             this.player.height = this.cWidth / param1.width * param1.height;
  219.             this.player.width = this.cWidth;
  220.             if(this.player.height > this.cHeight)
  221.             {
  222.                this.player.width = this.cHeight / param1.height * param1.width;
  223.                this.player.height = this.cHeight;
  224.             }
  225.             this.player.x = (this.cWidth - this.player.width) / 2;
  226.             this.player.y = (this.cHeight - this.player.height) / 2;
  227.          }
  228.          this.playPlaceHolder.x = (this.cWidth - 80) / 2;
  229.          this.playPlaceHolder.y = (this.cHeight - 100) / 2;
  230.          this.pausePlaceHolder.x = (this.cWidth - 80) / 2;
  231.          this.pausePlaceHolder.y = (this.cHeight - 100) / 2;
  232.       }
  233.       
  234.       public function stopVideo() : void
  235.       {
  236.          this.pauseVideo();
  237.       }
  238.       
  239.       public function pauseVideo() : void
  240.       {
  241.          this.pausePlaceHolder.visible = false;
  242.          this.playPlaceHolder.visible = true;
  243.          this.stream.pause();
  244.          this.isPlaying = false;
  245.       }
  246.       
  247.       public function seekTo(param1:Number) : void
  248.       {
  249.          this.stream.seek(param1);
  250.       }
  251.       
  252.       public function setVol(param1:Number) : void
  253.       {
  254.          this.origVolume = param1;
  255.          this.stream.soundTransform = new SoundTransform(param1);
  256.       }
  257.       
  258.       function frame1() : *
  259.       {
  260.          this.file = "";
  261.          this.cWidth = 400;
  262.          this.cHeight = 400;
  263.          stage.align = StageAlign.TOP_LEFT;
  264.          stage.scaleMode = StageScaleMode.NO_SCALE;
  265.          if(this.root.loaderInfo.parameters.cWidth != null)
  266.          {
  267.             this.cWidth = this.root.loaderInfo.parameters.cWidth;
  268.          }
  269.          else
  270.          {
  271.             stage.scaleMode = StageScaleMode.SHOW_ALL;
  272.             stage.align = StageAlign.TOP;
  273.          }
  274.          if(this.root.loaderInfo.parameters.cHeight != null)
  275.          {
  276.             this.cHeight = this.root.loaderInfo.parameters.cHeight;
  277.          }
  278.          else
  279.          {
  280.             stage.scaleMode = StageScaleMode.SHOW_ALL;
  281.             stage.align = StageAlign.TOP;
  282.          }
  283.          if(this.root.loaderInfo.parameters.fileName != null)
  284.          {
  285.             this.file = this.root.loaderInfo.parameters.fileName;
  286.          }
  287.          this.file = this.file.replace("{amp}","&");
  288.          if(this.file.length == 0 || this.file.indexOf(".swf") != -1 || this.file.indexOf(".js") != -1)
  289.          {
  290.             return;
  291.          }
  292.          this.loader = new Loader();
  293.          this.firstPlay = true;
  294.          this.duration = 0;
  295.          this.origVolume = 0.75;
  296.          this.isPlaying = false;
  297.          this.playerWidth = null;
  298.          this.playerHeight = null;
  299.          this.bg = null;
  300.          this.vobject = null;
  301.          this.fullScreenRect = null;
  302.          if(ExternalInterface.available)
  303.          {
  304.             try
  305.             {
  306.                ExternalInterface.addCallback("FlashPlay",function(param1:String = ""):*
  307.                {
  308.                   playVideo();
  309.                });
  310.                ExternalInterface.addCallback("FlashPause",function(param1:String = ""):*
  311.                {
  312.                   pauseVideo();
  313.                });
  314.                ExternalInterface.addCallback("FlashStop",function(param1:String = ""):*
  315.                {
  316.                   stopVideo();
  317.                });
  318.                ExternalInterface.addCallback("FlashLength",function(param1:String = ""):*
  319.                {
  320.                   return duration;
  321.                });
  322.                ExternalInterface.addCallback("FlashCurrentPosition",function(param1:String = ""):*
  323.                {
  324.                   if(stream == null)
  325.                   {
  326.                      return 0;
  327.                   }
  328.                   return stream.time;
  329.                });
  330.                ExternalInterface.addCallback("FlashBuffer",function(param1:String = ""):*
  331.                {
  332.                   if(stream == null)
  333.                   {
  334.                      return 0;
  335.                   }
  336.                   return stream.bytesLoaded / stream.bytesTotal;
  337.                });
  338.                ExternalInterface.addCallback("FlashScroll",function(param1:Number = 0):*
  339.                {
  340.                   seekTo(param1);
  341.                });
  342.                ExternalInterface.addCallback("FlashSetVolume",function(param1:Number = 0):*
  343.                {
  344.                   setVol(param1);
  345.                });
  346.                ExternalInterface.addCallback("FlashGetVolume",function(param1:String = ""):*
  347.                {
  348.                   return origVolume;
  349.                });
  350.                ExternalInterface.addCallback("FlashIsPlaying",function(param1:String = ""):*
  351.                {
  352.                   return isPlaying;
  353.                });
  354.                ExternalInterface.addCallback("FlashFullScreen",function(param1:String = ""):*
  355.                {
  356.                   var value:String = param1;
  357.                   fullScreenRect = new MovieClip();
  358.                   fullScreenRect.graphics.beginFill(10066329);
  359.                   fullScreenRect.graphics.drawRect(0,0,cWidth,30);
  360.                   fullScreenRect.graphics.endFill();
  361.                   fullScreenRect.x = 0;
  362.                   fullScreenRect.y = 0;
  363.                   fullScreenRect.width = cWidth;
  364.                   fullScreenRect.height = 30;
  365.                   addChild(fullScreenRect);
  366.                   var txt:TextField = new TextField();
  367.                   txt.width = cWidth - 20;
  368.                   txt.height = 27;
  369.                   txt.x = 10;
  370.                   txt.y = 3;
  371.                   txt.text = "Click here to go Full Screen";
  372.                   txt.setTextFormat(new TextFormat("Arial",16,16777215,false,false,false,null,null,"center"));
  373.                   fullScreenRect.addChild(txt);
  374.                   fullScreenRect.buttonMode = true;
  375.                   fullScreenRect.useHandCursor = true;
  376.                   fullScreenRect.mouseChildren = false;
  377.                   fullScreenRect.addEventListener(MouseEvent.CLICK,function(param1:Event):*
  378.                   {
  379.                      param1.stopImmediatePropagation();
  380.                      removeChild(fullScreenRect);
  381.                      fullScreenRect = null;
  382.                      txt = null;
  383.                      stage.displayState = StageDisplayState.FULL_SCREEN;
  384.                   });
  385.                   setTimeout(function():*
  386.                   {
  387.                      removeChild(fullScreenRect);
  388.                      fullScreenRect = null;
  389.                      txt = null;
  390.                   },5000);
  391.                });
  392.             }
  393.             catch(e:*)
  394.             {
  395.             }
  396.          }
  397.          this.startLoading();
  398.       }
  399.    }
  400. }
  401.