home *** CD-ROM | disk | FTP | other *** search
/ 600 Games / 600games.iso / Nave / sky-chopper.swf / scripts / __Packages / mx / controls / MediaPlayback.as < prev    next >
Encoding:
Text File  |  2005-09-29  |  17.6 KB  |  615 lines

  1. class mx.controls.MediaPlayback extends mx.core.UIComponent implements mx.controls.streamingmedia.ICuePointHolder
  2. {
  3.    var _deadPreview;
  4.    var initCuePointTimes;
  5.    var initCuePointNames;
  6.    var _totalTime;
  7.    var _aspectRatio;
  8.    var _autoSize;
  9.    var _autoPlay;
  10.    var _mediaType;
  11.    var _contentPath;
  12.    var _controllerPolicy;
  13.    var _controller;
  14.    var _display;
  15.    var _enabled;
  16.    var _flvLoaded;
  17.    var _chrome;
  18.    var dispatchEvent;
  19.    var _controlPlacement;
  20.    static var symbolName = "MediaPlayback";
  21.    static var symbolOwner = mx.controls.MediaPlayback;
  22.    var className = "MediaPlayback";
  23.    static var version = "2.0.0.360";
  24.    var clipParameters = {mediaType:"FLV",contentPath:"",totalTime:0,autoSize:true,autoPlay:true,controllerPolicy:"auto",initCuePointNames:new Array(),initCuePointTimes:new Array(),controlPlacement:"bottom",fps:30};
  25.    static var TOP_CONTROL_POSITION = "top";
  26.    static var BOTTOM_CONTROL_POSITION = "bottom";
  27.    static var LEFT_CONTROL_POSITION = "left";
  28.    static var RIGHT_CONTROL_POSITION = "right";
  29.    static var H_BORDER = 8;
  30.    static var V_BORDER = 8;
  31.    function MediaPlayback()
  32.    {
  33.       super();
  34.    }
  35.    function init(Void)
  36.    {
  37.       this.initializeParameters();
  38.       var _loc4_ = this._width;
  39.       var _loc7_ = this._height;
  40.       this._deadPreview._visible = false;
  41.       super.init();
  42.       var _loc3_ = {contentPath:this._contentPath,mediaType:this._mediaType,autoPlay:this._autoPlay,autoSize:this._autoSize,aspectRatio:this._aspectRatio,totalTime:this._totalTime,initCuePointNames:this.initCuePointNames,initCuePointTimes:this.initCuePointTimes};
  43.       this.attachMovie("MediaDisplay","_display",1,_loc3_);
  44.       var _loc8_ = !this._autoPlay ? mx.controls.streamingmedia.StreamingMediaConstants.PLAY_PLAY_CONTROL : mx.controls.streamingmedia.StreamingMediaConstants.PAUSE_PLAY_CONTROL;
  45.       var _loc5_ = this._mediaType != "MP3" ? "none" : "default";
  46.       var _loc6_ = this.controlPlacement == "top" || this.controlPlacement == "bottom";
  47.       _loc3_ = {horizontal:_loc6_,controllerPolicy:this._controllerPolicy,backgroundStyle:_loc5_,activePlayControl:_loc8_};
  48.       this.attachMovie("MediaController","_controller",2,_loc3_);
  49.       this.setSize(_loc4_,_loc7_,true);
  50.       this._display.associateController(this._controller);
  51.       this._controller.addEventListener("click",this);
  52.       this._controller.addEventListener("playheadChange",this);
  53.       this._controller.addEventListener("volume",this);
  54.       this._display.addEventListener("change",this);
  55.       this._display.addEventListener("progress",this);
  56.       this._display.addEventListener("start",this);
  57.       this._display.addEventListener("cuePoint",this);
  58.       this._display.addEventListener("complete",this);
  59.       this._enabled = true;
  60.       this.tabEnabled = false;
  61.       this.tabChildren = true;
  62.       this._flvLoaded = false;
  63.       this.redraw(true);
  64.    }
  65.    function initializeParameters()
  66.    {
  67.       if(this.mediaType == null)
  68.       {
  69.          this.mediaType = "FLV";
  70.       }
  71.       if(this.totalTime == null)
  72.       {
  73.          this.totalTime = 0;
  74.       }
  75.       if(this.contentPath == null)
  76.       {
  77.          this.contentPath = "";
  78.       }
  79.       if(this.autoPlay == null)
  80.       {
  81.          this.autoPlay = true;
  82.       }
  83.       if(this.autoSize == null)
  84.       {
  85.          this.autoSize = true;
  86.       }
  87.       if(this.aspectRatio == null)
  88.       {
  89.          this.aspectRatio = true;
  90.       }
  91.       if(this.controllerPolicy == null)
  92.       {
  93.          this.controllerPolicy = "auto";
  94.       }
  95.       if(this.controlPlacement == null)
  96.       {
  97.          this.controlPlacement = "bottom";
  98.       }
  99.    }
  100.    function draw(Void)
  101.    {
  102.       if(this._mediaType == "MP3")
  103.       {
  104.          this.drawMP3();
  105.       }
  106.       else
  107.       {
  108.          this.drawFLV();
  109.       }
  110.    }
  111.    function drawMP3()
  112.    {
  113.       this._display._x = 0;
  114.       this._display._y = 0;
  115.       this._controller._x = 0;
  116.       this._controller._y = 0;
  117.       this._controller.setSize(this.width,this.height,true);
  118.       this._controller.backgroundStyle = "default";
  119.       this._controller.setOpenUpOrLeft(false);
  120.       this._controller.redraw(true);
  121.       this._chrome.visible = false;
  122.       this._chrome.showToggles = false;
  123.       this._chrome.draw();
  124.    }
  125.    function drawFLV()
  126.    {
  127.       this.drawChrome();
  128.       this.drawFLVController();
  129.       this.drawFLVDisplay();
  130.    }
  131.    function drawChrome()
  132.    {
  133.       var _loc3_ = undefined;
  134.       var _loc2_ = undefined;
  135.       if(this._controller.horizontal)
  136.       {
  137.          _loc2_ = this.height - this._controller.getMinimumOpenHeight() + this._controller.getMinimumClosedHeight();
  138.          _loc3_ = this.width;
  139.       }
  140.       else
  141.       {
  142.          _loc3_ = this.width - this._controller.getMinimumOpenWidth() + this._controller.getMinimumClosedWidth();
  143.          _loc2_ = this.height;
  144.       }
  145.       var _loc5_ = this.width;
  146.       var _loc4_ = this.height;
  147.       var _loc7_ = this._controllerPolicy != "on" ? _loc3_ : _loc5_;
  148.       var _loc6_ = this._controllerPolicy != "on" ? _loc2_ : _loc4_;
  149.       var _loc8_ = this.isTopControlPlacement() || this.isLeftControlPlacement();
  150.       this._chrome._x = 0;
  151.       this._chrome._y = 0;
  152.       if(this.isTopControlPlacement() && (this._controllerPolicy == "off" || this._controllerPolicy == "auto"))
  153.       {
  154.          this._chrome._y = this._controller.getMinimumOpenHeight() - this._controller.getMinimumClosedHeight();
  155.       }
  156.       else if(this.isLeftControlPlacement() && (this._controllerPolicy == "off" || this._controllerPolicy == "auto"))
  157.       {
  158.          this._chrome._x = this._controller.getMinimumOpenWidth() - this._controller.getMinimumClosedWidth();
  159.       }
  160.       this._chrome.visible = true;
  161.       this._chrome.showToggles = true;
  162.       this._chrome.setSize(_loc7_,_loc6_);
  163.       this._chrome.draw();
  164.       this.addSecondChrome(this._chrome,_loc2_,_loc4_,_loc3_,_loc5_,_loc8_);
  165.    }
  166.    function drawFLVController()
  167.    {
  168.       if(this.isBottomControlPlacement())
  169.       {
  170.          this._controller.setSize(this.width,this._controller.getMinimumOpenHeight(),true);
  171.          this._controller.horizontal = true;
  172.          this._controller._x = 0;
  173.          this._controller._y = this.height - this._controller.height;
  174.       }
  175.       else if(this.isTopControlPlacement())
  176.       {
  177.          this._controller.setSize(this.width,this._controller.getMinimumOpenHeight(),true);
  178.          this._controller.horizontal = true;
  179.          this._controller.setOpenUpOrLeft(true);
  180.          this._controller._x = 0;
  181.          if(this._controllerPolicy == "on")
  182.          {
  183.             this._controller._y = 0;
  184.          }
  185.          else
  186.          {
  187.             this._controller._y = this._controller.height - this._controller.getMinimumClosedHeight();
  188.          }
  189.       }
  190.       else if(this.isRightControlPlacement())
  191.       {
  192.          this._controller.setSize(this._controller.getMinimumOpenWidth(),this.height,true);
  193.          this._controller.horizontal = false;
  194.          this._controller._x = this.width - this._controller.width;
  195.          this._controller._y = 0;
  196.       }
  197.       else if(this.isLeftControlPlacement())
  198.       {
  199.          this._controller.setSize(this._controller.getMinimumOpenWidth(),this.height,true);
  200.          this._controller.horizontal = false;
  201.          this._controller.setOpenUpOrLeft(true);
  202.          if(this._controllerPolicy == "on")
  203.          {
  204.             this._controller._x = 0;
  205.          }
  206.          else
  207.          {
  208.             this._controller._x = this._controller.width - this._controller.getMinimumClosedWidth();
  209.          }
  210.          this._controller._y = 0;
  211.       }
  212.       this._controller.backgroundStyle = "none";
  213.       this._controller.invalidate();
  214.    }
  215.    function drawFLVDisplay()
  216.    {
  217.       var _loc2_ = this.width - mx.controls.MediaPlayback.H_BORDER * 2;
  218.       var _loc3_ = this.height - mx.controls.MediaPlayback.V_BORDER * 2;
  219.       if(this.isBottomControlPlacement() || this.isTopControlPlacement())
  220.       {
  221.          _loc3_ -= this._controller.height;
  222.       }
  223.       else
  224.       {
  225.          _loc2_ -= this._controller.width;
  226.       }
  227.       if(this._autoSize && (this._display.preferredWidth > _loc2_ || this._display.preferredHeight > _loc3_))
  228.       {
  229.          this._display.autoSize = false;
  230.          this._display.aspectRatio = true;
  231.       }
  232.       else
  233.       {
  234.          this._display.autoSize = this._autoSize;
  235.          this._display.aspectRatio = this._aspectRatio;
  236.       }
  237.       this._display.setSize(_loc2_,_loc3_,true);
  238.       this._display.invalidate();
  239.       var _loc5_ = 0;
  240.       var _loc4_ = 0;
  241.       if(this.isTopControlPlacement())
  242.       {
  243.          _loc4_ = this._controller.height;
  244.       }
  245.       else if(this.isLeftControlPlacement())
  246.       {
  247.          _loc5_ = this._controller.width;
  248.       }
  249.       this._display._x = _loc5_ + mx.controls.MediaPlayback.H_BORDER;
  250.       this._display._y = _loc4_ + mx.controls.MediaPlayback.V_BORDER;
  251.    }
  252.    function handleEvent(ev)
  253.    {
  254.       this.dispatchEvent(ev);
  255.       if(ev.type == "start" && this._mediaType == "FLV" && !this._flvLoaded)
  256.       {
  257.          this._flvLoaded = true;
  258.          this._display.makeVideoVisible = true;
  259.          this.redraw(true);
  260.       }
  261.    }
  262.    function toString()
  263.    {
  264.       return "MediaPlayback: media=" + this._contentPath;
  265.    }
  266.    function getController()
  267.    {
  268.       return this._controller;
  269.    }
  270.    function load()
  271.    {
  272.       this._display.load();
  273.    }
  274.    function play(startingPoint)
  275.    {
  276.       this._display.play(startingPoint);
  277.       this._controller.setPlaying(true);
  278.    }
  279.    function pause()
  280.    {
  281.       this._display.pause();
  282.       this._controller.setPlaying(false);
  283.    }
  284.    function stop()
  285.    {
  286.       this._display.stop();
  287.       this._controller.setPlaying(false);
  288.    }
  289.    function get autoSize()
  290.    {
  291.       if(this._display != null)
  292.       {
  293.          this._autoSize = this._display.autoSize;
  294.       }
  295.       return this._autoSize;
  296.    }
  297.    function set autoSize(flag)
  298.    {
  299.       this._autoSize = flag;
  300.       if(this._display != null)
  301.       {
  302.          this.invalidate();
  303.       }
  304.    }
  305.    function get aspectRatio()
  306.    {
  307.       if(this._display != null)
  308.       {
  309.          this._aspectRatio = this._display.aspectRatio;
  310.       }
  311.       return this._aspectRatio;
  312.    }
  313.    function set aspectRatio(flag)
  314.    {
  315.       this._aspectRatio = flag;
  316.       if(this._display != null)
  317.       {
  318.          this._display.aspectRatio = flag;
  319.          this.invalidate();
  320.       }
  321.    }
  322.    function get autoPlay()
  323.    {
  324.       if(this._display != null)
  325.       {
  326.          this._autoPlay = this._display.autoPlay;
  327.       }
  328.       return this._autoPlay;
  329.    }
  330.    function set autoPlay(flag)
  331.    {
  332.       this._autoPlay = flag;
  333.       if(this._display != null)
  334.       {
  335.          this._display.autoPlay = flag;
  336.       }
  337.    }
  338.    function get playheadTime()
  339.    {
  340.       return this._display.playheadTime;
  341.    }
  342.    function set playheadTime(position)
  343.    {
  344.       this._display.playheadTime = position;
  345.    }
  346.    function get contentPath()
  347.    {
  348.       if(this._display != null)
  349.       {
  350.          this._contentPath = this._display.contentPath;
  351.       }
  352.       return this._contentPath;
  353.    }
  354.    function set contentPath(aUrl)
  355.    {
  356.       this._contentPath = aUrl;
  357.       this._flvLoaded = false;
  358.       if(this._display != null)
  359.       {
  360.          this._display.contentPath = aUrl;
  361.       }
  362.    }
  363.    function get volume()
  364.    {
  365.       return this._display.volume;
  366.    }
  367.    function set volume(aVol)
  368.    {
  369.       this._display.volume = aVol;
  370.       this._controller.volume = aVol;
  371.    }
  372.    function get playing()
  373.    {
  374.       return this._display.playing;
  375.    }
  376.    function get preferredWidth()
  377.    {
  378.       return this._display.preferredWidth;
  379.    }
  380.    function get preferredHeight()
  381.    {
  382.       return this._display.preferredHeight;
  383.    }
  384.    function get bytesLoaded()
  385.    {
  386.       return this._display.bytesLoaded;
  387.    }
  388.    function get bytesTotal()
  389.    {
  390.       return this._display.bytesTotal;
  391.    }
  392.    function get mediaType()
  393.    {
  394.       if(this._display != null)
  395.       {
  396.          this._mediaType = this._display.mediaType;
  397.       }
  398.       return this._mediaType;
  399.    }
  400.    function set mediaType(aType)
  401.    {
  402.       this._mediaType = aType;
  403.       if(this._display != null)
  404.       {
  405.          this._display.mediaType = aType;
  406.          if(aType == "MP3")
  407.          {
  408.             this._controller.backgroundStyle = "none";
  409.             this.removeSecondChrome();
  410.          }
  411.          else
  412.          {
  413.             this._controller.backgroundStyle = "default";
  414.             this.drawChrome();
  415.          }
  416.          this.invalidate();
  417.       }
  418.    }
  419.    function setMedia(aUrl, aType)
  420.    {
  421.       var _loc5_ = this._mediaType;
  422.       this._display.setMedia(aUrl,aType);
  423.       if(aType == null)
  424.       {
  425.          var _loc3_ = aUrl.substr(-3);
  426.          if(_loc3_ == "flv" || _loc3_ == "FLV")
  427.          {
  428.             aType = "FLV";
  429.          }
  430.          else if(_loc3_ == "mp3" || _loc3_ == "MP3")
  431.          {
  432.             aType = "MP3";
  433.          }
  434.          else
  435.          {
  436.             aType = this._mediaType;
  437.          }
  438.       }
  439.       if(_loc5_ != aType)
  440.       {
  441.          this.mediaType = aType;
  442.       }
  443.       this.contentPath = aUrl;
  444.    }
  445.    function get totalTime()
  446.    {
  447.       if(this._display != null)
  448.       {
  449.          this._totalTime = this._display.totalTime;
  450.       }
  451.       return this._totalTime;
  452.    }
  453.    function set totalTime(aTime)
  454.    {
  455.       this._totalTime = aTime;
  456.       if(this._display != null)
  457.       {
  458.          this._display.totalTime = this._totalTime;
  459.       }
  460.    }
  461.    function getCuePoints()
  462.    {
  463.       return this._display.getCuePoints();
  464.    }
  465.    function get cuePoints()
  466.    {
  467.       return this.getCuePoints();
  468.    }
  469.    function setCuePoints(cp)
  470.    {
  471.       var _loc2_ = 0;
  472.       while(_loc2_ < cp.length)
  473.       {
  474.          cp[_loc2_].playback = this;
  475.          _loc2_ = _loc2_ + 1;
  476.       }
  477.       this._display.cuePoints = cp;
  478.    }
  479.    function set cuePoints(cp)
  480.    {
  481.       this.setCuePoints(cp);
  482.    }
  483.    function getCuePoint(pointName)
  484.    {
  485.       return this._display.getCuePoint(pointName);
  486.    }
  487.    function addCuePoint(aName, aTime)
  488.    {
  489.       var _loc2_ = new mx.controls.streamingmedia.CuePoint(aName,aTime);
  490.       _loc2_.playback = this;
  491.       this.addCuePointObject(_loc2_);
  492.    }
  493.    function addCuePointObject(aCuePoint)
  494.    {
  495.       aCuePoint.playback = this;
  496.       this._display.addCuePointObject(aCuePoint);
  497.    }
  498.    function removeCuePoint(aCuePoint)
  499.    {
  500.       this._display.removeCuePoint(aCuePoint);
  501.    }
  502.    function removeAllCuePoints()
  503.    {
  504.       this._display.removeAllCuePoints();
  505.    }
  506.    function get controllerPolicy()
  507.    {
  508.       if(this._controller != null)
  509.       {
  510.          this._controllerPolicy = this._controller.controllerPolicy;
  511.       }
  512.       return this._controllerPolicy;
  513.    }
  514.    function set controllerPolicy(aPolicy)
  515.    {
  516.       this._controllerPolicy = aPolicy;
  517.       if(this._controller != null)
  518.       {
  519.          this._controller.controllerPolicy = aPolicy;
  520.       }
  521.    }
  522.    function addSecondChrome(theChrome, closedHeight, openHeight, closedWidth, openWidth, fixedEnd)
  523.    {
  524.       this._controller.addSecondChrome(theChrome,closedHeight,openHeight,closedWidth,openWidth,fixedEnd);
  525.    }
  526.    function removeSecondChrome()
  527.    {
  528.       this._controller.removeSecondChrome();
  529.    }
  530.    function getMinimumOpenHeight()
  531.    {
  532.       return this._controller.getMinimumOpenHeight();
  533.    }
  534.    function getMinimumOpenWidth()
  535.    {
  536.       return this._controller.getMinimumOpenWidth();
  537.    }
  538.    function getMinimumClosedHeight()
  539.    {
  540.       return this._controller.getMinimumClosedHeight();
  541.    }
  542.    function getMinimumClosedWidth()
  543.    {
  544.       return this._controller.getMinimumClosedWidth();
  545.    }
  546.    function expand(force)
  547.    {
  548.       this._controller.expand(force);
  549.    }
  550.    function contract(force)
  551.    {
  552.       this._controller.contract(force);
  553.    }
  554.    function get controlPlacement()
  555.    {
  556.       return this._controlPlacement;
  557.    }
  558.    function set controlPlacement(aPos)
  559.    {
  560.       this._controlPlacement = aPos;
  561.       if(this._controller != null)
  562.       {
  563.          var _loc2_ = this.isTopControlPlacement() || this.isLeftControlPlacement();
  564.          this._controller.setOpenUpOrLeft(_loc2_);
  565.          var _loc3_ = this.isTopControlPlacement() || this.isBottomControlPlacement();
  566.          this._controller.horizontal = _loc3_;
  567.          this.invalidate();
  568.       }
  569.    }
  570.    function isTopControlPlacement()
  571.    {
  572.       return this._controlPlacement == mx.controls.MediaPlayback.TOP_CONTROL_POSITION;
  573.    }
  574.    function isBottomControlPlacement()
  575.    {
  576.       return this._controlPlacement == mx.controls.MediaPlayback.BOTTOM_CONTROL_POSITION;
  577.    }
  578.    function isLeftControlPlacement()
  579.    {
  580.       return this._controlPlacement == mx.controls.MediaPlayback.LEFT_CONTROL_POSITION;
  581.    }
  582.    function isRightControlPlacement()
  583.    {
  584.       return this._controlPlacement == mx.controls.MediaPlayback.RIGHT_CONTROL_POSITION;
  585.    }
  586.    function displayFull()
  587.    {
  588.       var _loc2_ = this._chrome.getOneToggle();
  589.       _loc2_.displayFull(false);
  590.    }
  591.    function displayNormal()
  592.    {
  593.       var _loc2_ = this._chrome.getOneToggle();
  594.       _loc2_.displayNormal(false);
  595.    }
  596.    function setSize(w, h, noEvent)
  597.    {
  598.       w = Math.max(w,this._controller.getMinimumOpenWidth() + 17);
  599.       h = Math.max(h,this._controller.getMinimumOpenHeight() + 17);
  600.       super.setSize(w,h,noEvent);
  601.       this.invalidate();
  602.    }
  603.    function get enabled()
  604.    {
  605.       return this._enabled;
  606.    }
  607.    function set enabled(is)
  608.    {
  609.       this._enabled = is;
  610.       this._display.enabled = is;
  611.       this._controller.enabled = is;
  612.       this._chrome.setEnabled(is);
  613.    }
  614. }
  615.