home *** CD-ROM | disk | FTP | other *** search
/ Canadian Forces: A World of Opportunities / CanadianForces-AWorldOfOpportunities-WinMac.bin / 04_WhatOptions_FR.swf / scripts / __Packages / mx / video / SMILManager.as < prev    next >
Text File  |  2006-07-20  |  9KB  |  246 lines

  1. class mx.video.SMILManager
  2. {
  3.    static var version = "1.0.0.103";
  4.    static var ELEMENT_NODE = 1;
  5.    function SMILManager(owner)
  6.    {
  7.       this._owner = owner;
  8.    }
  9.    function connectXML(url)
  10.    {
  11.       this._url = url;
  12.       this.xml = new XML();
  13.       this.xml.onLoad = mx.utils.Delegate.create(this,this.xmlOnLoad);
  14.       this.xml.load(url);
  15.       return false;
  16.    }
  17.    function xmlOnLoad(success)
  18.    {
  19.       try
  20.       {
  21.          if(!success)
  22.          {
  23.             this._owner.helperDone(this,false);
  24.          }
  25.          else
  26.          {
  27.             this.baseURLAttr = new Array();
  28.             this.videoTags = new Array();
  29.             var _loc4_ = this.xml.firstChild;
  30.             if(_loc4_.nodeName == null)
  31.             {
  32.                throw new mx.video.VideoError(mx.video.VideoError.INVALID_XML,"URL: \"" + this._url + "\" No root node found; if file is an flv it must have .flv extension");
  33.             }
  34.             else if(_loc4_.nodeName.toLowerCase() != "smil")
  35.             {
  36.                throw new mx.video.VideoError(mx.video.VideoError.INVALID_XML,"URL: \"" + this._url + "\" Root node not smil: " + _loc4_.nodeName);
  37.             }
  38.             else
  39.             {
  40.                var _loc5_ = false;
  41.                var _loc3_ = 0;
  42.                for(; _loc3_ < _loc4_.childNodes.length; _loc3_ = _loc3_ + 1)
  43.                {
  44.                   var _loc2_ = _loc4_.childNodes[_loc3_];
  45.                   if(_loc2_.nodeType != mx.video.SMILManager.ELEMENT_NODE)
  46.                   {
  47.                      continue;
  48.                   }
  49.                   if(_loc2_.nodeName.toLowerCase() == "head")
  50.                   {
  51.                      this.parseHead(_loc2_);
  52.                      continue;
  53.                   }
  54.                   if(_loc2_.nodeName.toLowerCase() == "body")
  55.                   {
  56.                      _loc5_ = true;
  57.                      this.parseBody(_loc2_);
  58.                      continue;
  59.                   }
  60.                   throw new mx.video.VideoError(mx.video.VideoError.INVALID_XML,"URL: \"" + this._url + "\" Tag " + _loc2_.nodeName + " not supported in " + _loc4_.nodeName + " tag.");
  61.                }
  62.                if(!_loc5_)
  63.                {
  64.                   throw new mx.video.VideoError(mx.video.VideoError.INVALID_XML,"URL: \"" + this._url + "\" Tag body is required.");
  65.                }
  66.                else
  67.                {
  68.                   this._owner.helperDone(this,true);
  69.                }
  70.             }
  71.          }
  72.       }
  73.       catch(err:Error)
  74.       {
  75.          this._owner.helperDone(this,false);
  76.          throw err;
  77.       }
  78.    }
  79.    function parseHead(parentNode)
  80.    {
  81.       var _loc4_ = false;
  82.       var _loc3_ = 0;
  83.       while(_loc3_ < parentNode.childNodes.length)
  84.       {
  85.          var _loc2_ = parentNode.childNodes[_loc3_];
  86.          if(_loc2_.nodeType == mx.video.SMILManager.ELEMENT_NODE)
  87.          {
  88.             if(_loc2_.nodeName.toLowerCase() == "meta")
  89.             {
  90.                ┬º┬ºenumerate(_loc2_.attributes);
  91.                var _loc0_ = null;
  92.                for(; (_loc0_ = ┬º┬ºenumeration()) != null; this.baseURLAttr.push(_loc2_.attributes[_loc6_]))
  93.                {
  94.                   var _loc6_ = ┬º┬ºenum_assign();
  95.                   if(_loc6_.toLowerCase() == "base")
  96.                   {
  97.                      continue;
  98.                   }
  99.                   throw new mx.video.VideoError(mx.video.VideoError.INVALID_XML,"URL: \"" + this._url + "\" Attribute " + _loc6_ + " not supported in " + _loc2_.nodeName + " tag.");
  100.                }
  101.             }
  102.             else if(_loc2_.nodeName.toLowerCase() == "layout")
  103.             {
  104.                if(!_loc4_)
  105.                {
  106.                   this.parseLayout(_loc2_);
  107.                   _loc4_ = true;
  108.                }
  109.             }
  110.          }
  111.          _loc3_ = _loc3_ + 1;
  112.       }
  113.    }
  114.    function parseLayout(parentNode)
  115.    {
  116.       var _loc3_ = 0;
  117.       for(; _loc3_ < parentNode.childNodes.length; _loc3_ = _loc3_ + 1)
  118.       {
  119.          var _loc2_ = parentNode.childNodes[_loc3_];
  120.          if(_loc2_.nodeType != mx.video.SMILManager.ELEMENT_NODE)
  121.          {
  122.             continue;
  123.          }
  124.          if(_loc2_.nodeName.toLowerCase() != "root-layout")
  125.          {
  126.             continue;
  127.          }
  128.          for(var _loc5_ in _loc2_.attributes)
  129.          {
  130.             if(_loc5_.toLowerCase() == "width")
  131.             {
  132.                this.width = Number(_loc2_.attributes[_loc5_]);
  133.             }
  134.             else if(_loc5_.toLowerCase() == "height")
  135.             {
  136.                this.height = Number(_loc2_.attributes[_loc5_]);
  137.             }
  138.          }
  139.          if(!(isNaN(this.width) || this.width < 0 || isNaN(this.height) || this.height < 0))
  140.          {
  141.             this.width = Math.round(this.width);
  142.             this.height = Math.round(this.height);
  143.             return undefined;
  144.          }
  145.          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.");
  146.       }
  147.    }
  148.    function parseBody(parentNode)
  149.    {
  150.       var _loc6_ = 0;
  151.       var _loc3_ = 0;
  152.       for(; _loc3_ < parentNode.childNodes.length; _loc3_ = _loc3_ + 1)
  153.       {
  154.          var _loc2_ = parentNode.childNodes[_loc3_];
  155.          if(_loc2_.nodeType != mx.video.SMILManager.ELEMENT_NODE)
  156.          {
  157.             continue;
  158.          }
  159.          if((_loc6_ = _loc6_ + 1) <= 1)
  160.          {
  161.             if(_loc2_.nodeName.toLowerCase() == "switch")
  162.             {
  163.                this.parseSwitch(_loc2_);
  164.             }
  165.             else if(_loc2_.nodeName.toLowerCase() == "video" || _loc2_.nodeName.toLowerCase() == "ref")
  166.             {
  167.                var _loc5_ = this.parseVideo(_loc2_);
  168.                this.videoTags.push(_loc5_);
  169.             }
  170.             continue;
  171.          }
  172.          throw new mx.video.VideoError(mx.video.VideoError.INVALID_XML,"URL: \"" + this._url + "\" Tag " + parentNode.nodeName + " is required to contain exactly one tag.");
  173.       }
  174.       if(this.videoTags.length < 1)
  175.       {
  176.          throw new mx.video.VideoError(mx.video.VideoError.INVALID_XML,"URL: \"" + this._url + "\" At least one video of ref tag is required.");
  177.       }
  178.    }
  179.    function parseSwitch(parentNode)
  180.    {
  181.       var _loc4_ = 0;
  182.       while(_loc4_ < parentNode.childNodes.length)
  183.       {
  184.          var _loc5_ = parentNode.childNodes[_loc4_];
  185.          if(_loc5_.nodeType == mx.video.SMILManager.ELEMENT_NODE)
  186.          {
  187.             if(_loc5_.nodeName.toLowerCase() == "video" || _loc5_.nodeName.toLowerCase() == "ref")
  188.             {
  189.                var _loc3_ = this.parseVideo(_loc5_);
  190.                if(_loc3_.bitrate == undefined)
  191.                {
  192.                   this.videoTags.push(_loc3_);
  193.                }
  194.                else
  195.                {
  196.                   var _loc6_ = false;
  197.                   var _loc2_ = 0;
  198.                   while(_loc2_ < this.videoTags.length)
  199.                   {
  200.                      if(this.videoTags[_loc2_].bitrate == undefined || _loc3_.bitrate < this.videoTags[_loc4_].bitrate)
  201.                      {
  202.                         _loc6_ = true;
  203.                         this.videoTags.splice(_loc2_,0,this.videoTags);
  204.                         break;
  205.                      }
  206.                      _loc2_ = _loc2_ + 1;
  207.                   }
  208.                   if(!_loc6_)
  209.                   {
  210.                      this.videoTags.push(_loc3_);
  211.                   }
  212.                }
  213.             }
  214.          }
  215.          _loc4_ = _loc4_ + 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 = Number(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. }
  246.