home *** CD-ROM | disk | FTP | other *** search
/ Freelog 115 / FreelogNo115-MaiJuin2013.iso / Internet / Free Download Manager / fdminst.exe / {app} / player.swf / scripts / __Packages / mx / video / SMILManager.as < prev    next >
Encoding:
Text File  |  2012-08-12  |  8.2 KB  |  240 lines

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