home *** CD-ROM | disk | FTP | other *** search
/ i·claim - visualizing argument / ICLAIM.ISO / mac / t_02.swf / scripts / __Packages / mx / controls / MediaPlayback.as < prev    next >
Text File  |  2005-02-25  |  19KB  |  645 lines

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