home *** CD-ROM | disk | FTP | other *** search
/ i·claim - visualizing argument / ICLAIM.ISO / pc / gloss.swf / scripts / __Packages / mx / controls / MediaPlayback.as < prev    next >
Encoding:
Text File  |  2005-02-26  |  18.7 KB  |  661 lines

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