home *** CD-ROM | disk | FTP | other *** search
/ csi.uticak12.org / csi.uticak12.org.tar / csi.uticak12.org / flashVideo / EchoGrove.swf / scripts / __Packages / mx / video / SMILManager.as < prev    next >
Text File  |  2010-12-15  |  9KB  |  269 lines

  1. class mx.video.SMILManager
  2. {
  3.    static var version = "1.0.2.7";
  4.    static var shortVersion = "1.0.2";
  5.    static var ELEMENT_NODE = 1;
  6.    function SMILManager(owner)
  7.    {
  8.       this._owner = owner;
  9.    }
  10.    function connectXML(url)
  11.    {
  12.       this._url = this.fixURL(url);
  13.       this.xml = new XML();
  14.       this.xml.onLoad = mx.utils.Delegate.create(this,this.xmlOnLoad);
  15.       this.xml.load(this._url);
  16.       return false;
  17.    }
  18.    function fixURL(origURL)
  19.    {
  20.       if(origURL.substr(0,5).toLowerCase() == "http:" || origURL.substr(0,6).toLowerCase() == "https:")
  21.       {
  22.          var _loc2_ = origURL.indexOf("?") < 0 ? "?" : "&";
  23.          return origURL + _loc2_ + "FLVPlaybackVersion=" + mx.video.SMILManager.shortVersion;
  24.       }
  25.       return origURL;
  26.    }
  27.    function xmlOnLoad(success)
  28.    {
  29.       try
  30.       {
  31.          if(!success)
  32.          {
  33.             this._owner.helperDone(this,false);
  34.          }
  35.          else
  36.          {
  37.             this.baseURLAttr = new Array();
  38.             this.videoTags = new Array();
  39.             var _loc2_ = this.xml.firstChild;
  40.             var _loc6_ = false;
  41.             while(_loc2_ != null)
  42.             {
  43.                if(_loc2_.nodeType == mx.video.SMILManager.ELEMENT_NODE)
  44.                {
  45.                   _loc6_ = true;
  46.                   if(_loc2_.nodeName.toLowerCase() == "smil")
  47.                   {
  48.                      break;
  49.                   }
  50.                }
  51.                _loc2_ = _loc2_.nextSibling;
  52.             }
  53.             if(!_loc6_)
  54.             {
  55.                throw new mx.video.VideoError(mx.video.VideoError.INVALID_XML,"URL: \"" + this._url + "\" No root node found; if url is for an flv it must have .flv extension and take no parameters");
  56.             }
  57.             else if(_loc2_ == null)
  58.             {
  59.                throw new mx.video.VideoError(mx.video.VideoError.INVALID_XML,"URL: \"" + this._url + "\" Root node not smil");
  60.             }
  61.             else
  62.             {
  63.                var _loc5_ = false;
  64.                var _loc4_ = 0;
  65.                for(; _loc4_ < _loc2_.childNodes.length; _loc4_ = _loc4_ + 1)
  66.                {
  67.                   var _loc3_ = _loc2_.childNodes[_loc4_];
  68.                   if(_loc3_.nodeType != mx.video.SMILManager.ELEMENT_NODE)
  69.                   {
  70.                      continue;
  71.                   }
  72.                   if(_loc3_.nodeName.toLowerCase() == "head")
  73.                   {
  74.                      this.parseHead(_loc3_);
  75.                      continue;
  76.                   }
  77.                   if(_loc3_.nodeName.toLowerCase() == "body")
  78.                   {
  79.                      _loc5_ = true;
  80.                      this.parseBody(_loc3_);
  81.                      continue;
  82.                   }
  83.                   throw new mx.video.VideoError(mx.video.VideoError.INVALID_XML,"URL: \"" + this._url + "\" Tag " + _loc3_.nodeName + " not supported in " + _loc2_.nodeName + " tag.");
  84.                }
  85.                if(!_loc5_)
  86.                {
  87.                   throw new mx.video.VideoError(mx.video.VideoError.INVALID_XML,"URL: \"" + this._url + "\" Tag body is required.");
  88.                }
  89.                else
  90.                {
  91.                   this._owner.helperDone(this,true);
  92.                }
  93.             }
  94.          }
  95.       }
  96.       catch(err:Error)
  97.       {
  98.          this._owner.helperDone(this,false);
  99.          throw err;
  100.       }
  101.    }
  102.    function parseHead(parentNode)
  103.    {
  104.       var _loc4_ = false;
  105.       var _loc3_ = 0;
  106.       while(_loc3_ < parentNode.childNodes.length)
  107.       {
  108.          var _loc2_ = parentNode.childNodes[_loc3_];
  109.          if(_loc2_.nodeType == mx.video.SMILManager.ELEMENT_NODE)
  110.          {
  111.             if(_loc2_.nodeName.toLowerCase() == "meta")
  112.             {
  113.                ┬º┬ºenumerate(_loc2_.attributes);
  114.                var _loc0_ = null;
  115.                for(; (_loc0_ = ┬º┬ºenumeration()) != null; this.baseURLAttr.push(_loc2_.attributes[_loc6_]))
  116.                {
  117.                   var _loc6_ = ┬º┬ºenum_assign();
  118.                   if(_loc6_.toLowerCase() == "base")
  119.                   {
  120.                      continue;
  121.                   }
  122.                   throw new mx.video.VideoError(mx.video.VideoError.INVALID_XML,"URL: \"" + this._url + "\" Attribute " + _loc6_ + " not supported in " + _loc2_.nodeName + " tag.");
  123.                }
  124.             }
  125.             else if(_loc2_.nodeName.toLowerCase() == "layout")
  126.             {
  127.                if(!_loc4_)
  128.                {
  129.                   this.parseLayout(_loc2_);
  130.                   _loc4_ = true;
  131.                }
  132.             }
  133.          }
  134.          _loc3_ = _loc3_ + 1;
  135.       }
  136.    }
  137.    function parseLayout(parentNode)
  138.    {
  139.       var _loc3_ = 0;
  140.       for(; _loc3_ < parentNode.childNodes.length; _loc3_ = _loc3_ + 1)
  141.       {
  142.          var _loc2_ = parentNode.childNodes[_loc3_];
  143.          if(_loc2_.nodeType != mx.video.SMILManager.ELEMENT_NODE)
  144.          {
  145.             continue;
  146.          }
  147.          if(_loc2_.nodeName.toLowerCase() != "root-layout")
  148.          {
  149.             continue;
  150.          }
  151.          for(var _loc5_ in _loc2_.attributes)
  152.          {
  153.             if(_loc5_.toLowerCase() == "width")
  154.             {
  155.                this.width = Number(_loc2_.attributes[_loc5_]);
  156.             }
  157.             else if(_loc5_.toLowerCase() == "height")
  158.             {
  159.                this.height = Number(_loc2_.attributes[_loc5_]);
  160.             }
  161.          }
  162.          if(!(isNaN(this.width) || this.width < 0 || isNaN(this.height) || this.height < 0))
  163.          {
  164.             this.width = Math.round(this.width);
  165.             this.height = Math.round(this.height);
  166.             return undefined;
  167.          }
  168.          throw new mx.video.VideoError(mx.video.VideoError.INVALID_XML,"URL: \"" + this._url + "\" Tag " + _loc2_.nodeName + " requires attributes id, width and height.  Width and height must be numbers greater than or equal to 0.");
  169.       }
  170.    }
  171.    function parseBody(parentNode)
  172.    {
  173.       var _loc6_ = 0;
  174.       var _loc3_ = 0;
  175.       for(; _loc3_ < parentNode.childNodes.length; _loc3_ = _loc3_ + 1)
  176.       {
  177.          var _loc2_ = parentNode.childNodes[_loc3_];
  178.          if(_loc2_.nodeType != mx.video.SMILManager.ELEMENT_NODE)
  179.          {
  180.             continue;
  181.          }
  182.          if((_loc6_ = _loc6_ + 1) <= 1)
  183.          {
  184.             if(_loc2_.nodeName.toLowerCase() == "switch")
  185.             {
  186.                this.parseSwitch(_loc2_);
  187.             }
  188.             else if(_loc2_.nodeName.toLowerCase() == "video" || _loc2_.nodeName.toLowerCase() == "ref")
  189.             {
  190.                var _loc5_ = this.parseVideo(_loc2_);
  191.                this.videoTags.push(_loc5_);
  192.             }
  193.             continue;
  194.          }
  195.          throw new mx.video.VideoError(mx.video.VideoError.INVALID_XML,"URL: \"" + this._url + "\" Tag " + parentNode.nodeName + " is required to contain exactly one tag.");
  196.       }
  197.       if(this.videoTags.length < 1)
  198.       {
  199.          throw new mx.video.VideoError(mx.video.VideoError.INVALID_XML,"URL: \"" + this._url + "\" At least one video of ref tag is required.");
  200.       }
  201.    }
  202.    function parseSwitch(parentNode)
  203.    {
  204.       var _loc3_ = 0;
  205.       while(_loc3_ < parentNode.childNodes.length)
  206.       {
  207.          var _loc2_ = parentNode.childNodes[_loc3_];
  208.          if(_loc2_.nodeType == mx.video.SMILManager.ELEMENT_NODE)
  209.          {
  210.             if(_loc2_.nodeName.toLowerCase() == "video" || _loc2_.nodeName.toLowerCase() == "ref")
  211.             {
  212.                this.videoTags.push(this.parseVideo(_loc2_));
  213.             }
  214.          }
  215.          _loc3_ = _loc3_ + 1;
  216.       }
  217.    }
  218.    function parseVideo(node)
  219.    {
  220.       var _loc3_ = new Object();
  221.       for(var _loc4_ in node.attributes)
  222.       {
  223.          if(_loc4_.toLowerCase() == "src")
  224.          {
  225.             _loc3_.src = node.attributes[_loc4_];
  226.          }
  227.          else if(_loc4_.toLowerCase() == "system-bitrate")
  228.          {
  229.             _loc3_.bitrate = Number(node.attributes[_loc4_]);
  230.          }
  231.          else if(_loc4_.toLowerCase() == "dur")
  232.          {
  233.             _loc3_.dur = this.parseTime(node.attributes[_loc4_]);
  234.          }
  235.       }
  236.       if(_loc3_.src == undefined)
  237.       {
  238.          throw new mx.video.VideoError(mx.video.VideoError.INVALID_XML,"URL: \"" + this._url + "\" Attribute src is required in " + node.nodeName + " tag.");
  239.       }
  240.       else
  241.       {
  242.          return _loc3_;
  243.       }
  244.    }
  245.    function parseTime(timeStr)
  246.    {
  247.       var _loc4_ = 0;
  248.       var _loc3_ = timeStr.split(":");
  249.       if(_loc3_.length < 1 || _loc3_.length > 3)
  250.       {
  251.          throw new mx.video.VideoError(mx.video.VideoError.INVALID_XML,"Invalid dur value: " + timeStr);
  252.       }
  253.       else
  254.       {
  255.          var _loc1_ = 0;
  256.          for(; _loc1_ < _loc3_.length; _loc4_ *= 60,_loc4_ += _loc2_,_loc1_ = _loc1_ + 1)
  257.          {
  258.             var _loc2_ = Number(_loc3_[_loc1_]);
  259.             if(!isNaN(_loc2_))
  260.             {
  261.                continue;
  262.             }
  263.             throw new mx.video.VideoError(mx.video.VideoError.INVALID_XML,"Invalid dur value: " + timeStr);
  264.          }
  265.          return _loc4_;
  266.       }
  267.    }
  268. }
  269.