PageRenderTime 57ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 0ms

/strobe-milyoni/src/framework/OSMF/org/osmf/elements/XMLLoader.as

https://github.com/krokhale/milyoniplayer
ActionScript | 133 lines | 76 code | 14 blank | 43 comment | 3 complexity | 528d0d425b816a22efb372bc1cc77802 MD5 | raw file
  1. /*****************************************************
  2. *
  3. * Copyright 2009 Adobe Systems Incorporated. All Rights Reserved.
  4. *
  5. *****************************************************
  6. * The contents of this file are subject to the Mozilla Public License
  7. * Version 1.1 (the "License"); you may not use this file except in
  8. * compliance with the License. You may obtain a copy of the License at
  9. * http://www.mozilla.org/MPL/
  10. *
  11. * Software distributed under the License is distributed on an "AS IS"
  12. * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing rights and limitations
  14. * under the License.
  15. *
  16. *
  17. * The Initial Developer of the Original Code is Adobe Systems Incorporated.
  18. * Portions created by Adobe Systems Incorporated are Copyright (C) 2009 Adobe Systems
  19. * Incorporated. All Rights Reserved.
  20. *
  21. *****************************************************/
  22. package org.osmf.elements
  23. {
  24. import flash.events.TimerEvent;
  25. import flash.external.ExternalInterface;
  26. import flash.utils.Timer;
  27. import org.osmf.elements.f4mClasses.DRMAdditionalHeader;
  28. import org.osmf.elements.f4mClasses.Manifest;
  29. import org.osmf.elements.f4mClasses.ManifestParser;
  30. import org.osmf.elements.f4mClasses.builders.BaseManifestBuilder;
  31. import org.osmf.elements.f4mClasses.builders.ManifestBuilder;
  32. import org.osmf.elements.f4mClasses.builders.MultiLevelManifestBuilder;
  33. import org.osmf.elements.proxyClasses.LoadFromDocumentLoadTrait;
  34. import org.osmf.events.MediaError;
  35. import org.osmf.events.MediaErrorCodes;
  36. import org.osmf.events.MediaErrorEvent;
  37. import org.osmf.events.ParseEvent;
  38. import org.osmf.media.DefaultMediaFactory;
  39. import org.osmf.media.MediaElement;
  40. import org.osmf.media.MediaFactory;
  41. import org.osmf.media.MediaResourceBase;
  42. import org.osmf.media.URLResource;
  43. import org.osmf.net.StreamingXMLResource;
  44. import org.osmf.traits.LoadState;
  45. import org.osmf.traits.LoadTrait;
  46. import org.osmf.traits.LoaderBase;
  47. import org.osmf.utils.OSMFSettings;
  48. import org.osmf.utils.OSMFStrings;
  49. import org.osmf.utils.URL;
  50. [ExcludeClass]
  51. /**
  52. * @private
  53. *
  54. * XMLLoader is a loader that is capable of loading F4M Strings. F4M files are
  55. * XML documents that adhere to the Flash Media Manifest format, and which
  56. * represent all of the information needed to load and play a media file.
  57. *
  58. * @see http://opensource.adobe.com/wiki/display/osmf/Flash%2BMedia%2BManifest%2BFile%2BFormat%2BSpecification Flash Media Manifest File Format Specification
  59. *
  60. * @langversion 3.0
  61. * @playerversion Flash 10
  62. * @playerversion AIR 1.5
  63. * @productversion OSMF 1.6
  64. */
  65. public class XMLLoader extends ManifestLoaderBase
  66. {
  67. public function XMLLoader(factory:MediaFactory = null)
  68. {
  69. super();
  70. if (factory == null)
  71. {
  72. factory = new DefaultMediaFactory();
  73. }
  74. this.factory = factory;
  75. this.builders = getBuilders();
  76. }
  77. /**
  78. * @private
  79. */
  80. override public function canHandleResource(resource:MediaResourceBase):Boolean
  81. {
  82. if (resource is StreamingXMLResource)
  83. {
  84. return true;
  85. }
  86. else
  87. {
  88. return false;
  89. }
  90. }
  91. /**
  92. * @private
  93. */
  94. override protected function executeLoad(loadTrait:LoadTrait):void
  95. {
  96. this.loadTrait = loadTrait;
  97. updateLoadTrait(loadTrait, LoadState.LOADING);
  98. var manifest:Manifest;
  99. try
  100. {
  101. var resourceData:String = (loadTrait.resource as StreamingXMLResource).manifest;
  102. parser = getParser(resourceData);
  103. // Begin parsing.
  104. parser.addEventListener(ParseEvent.PARSE_COMPLETE, onParserLoadComplete);
  105. parser.addEventListener(ParseEvent.PARSE_ERROR, onParserLoadError);
  106. // Set up the timeout.
  107. parserTimer = new Timer(OSMFSettings.f4mParseTimeout, 1);
  108. parserTimer.addEventListener(TimerEvent.TIMER_COMPLETE, onParserTimerComplete);
  109. parserTimer.start();
  110. parser.parse(resourceData, URL.getRootUrl(StreamingXMLResource(loadTrait.resource).url));
  111. }
  112. catch (parseError:Error)
  113. {
  114. updateLoadTrait(loadTrait, LoadState.LOAD_ERROR);
  115. loadTrait.dispatchEvent(new MediaErrorEvent(MediaErrorEvent.MEDIA_ERROR, false, false, new MediaError(parseError.errorID, parseError.message)));
  116. }
  117. }
  118. }
  119. }