Menu

[r331]: / trunk / framework / OSMF / org / osmf / elements / ManifestLoaderBase.as  Maximize  Restore  History

Download this file

195 lines (170 with data), 6.4 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/*****************************************************
*
* Copyright 2009 Adobe Systems Incorporated. All Rights Reserved.
*
*****************************************************
* The contents of this file are subject to the Mozilla Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
*
* The Initial Developer of the Original Code is Adobe Systems Incorporated.
* Portions created by Adobe Systems Incorporated are Copyright (C) 2009 Adobe Systems
* Incorporated. All Rights Reserved.
*
*****************************************************/
package org.osmf.elements
{
import flash.events.TimerEvent;
import flash.utils.Timer;
import org.osmf.elements.f4mClasses.Manifest;
import org.osmf.elements.f4mClasses.ManifestParser;
import org.osmf.elements.f4mClasses.builders.BaseManifestBuilder;
import org.osmf.elements.f4mClasses.builders.MultiLevelManifestBuilder;
import org.osmf.elements.f4mClasses.builders.ManifestBuilder;
import org.osmf.elements.proxyClasses.LoadFromDocumentLoadTrait;
import org.osmf.events.MediaError;
import org.osmf.events.MediaErrorCodes;
import org.osmf.events.MediaErrorEvent;
import org.osmf.events.ParseEvent;
import org.osmf.media.DefaultMediaFactory;
import org.osmf.media.MediaElement;
import org.osmf.media.MediaFactory;
import org.osmf.media.MediaResourceBase;
import org.osmf.traits.LoadState;
import org.osmf.traits.LoadTrait;
import org.osmf.traits.LoaderBase;
import org.osmf.utils.OSMFStrings;
/**
* ManifestLoader is a base loader class for objects that are capable of loading Flash Media Manifests
* either from F4M files or from the direct String representation of the manifest.
*
* @see http://opensource.adobe.com/wiki/display/osmf/Flash%2BMedia%2BManifest%2BFile%2BFormat%2BSpecification Flash Media Manifest File Format Specification
*
* @langversion 3.0
* @playerversion Flash 10
* @playerversion AIR 1.5
* @productversion OSMF 1.6
*/
public class ManifestLoaderBase extends LoaderBase
{
public function ManifestLoaderBase()
{
super();
}
/**
* @private
*/
protected function onParserTimerComplete(event:TimerEvent):void
{
if (parserTimer)
{
parserTimer.removeEventListener(TimerEvent.TIMER_COMPLETE, onParserTimerComplete);
parserTimer = null;
}
// Parsing hasn't finished, so throw an error.
updateLoadTrait(loadTrait, LoadState.LOAD_ERROR);
loadTrait.dispatchEvent(new MediaErrorEvent(MediaErrorEvent.MEDIA_ERROR, false, false, new MediaError(MediaErrorCodes.F4M_FILE_INVALID, OSMFStrings.getString(OSMFStrings.F4M_PARSE_ERROR))));
}
/**
* @private
*/
protected function onParserLoadComplete(event:ParseEvent):void
{
if (parserTimer)
{
parserTimer.removeEventListener(TimerEvent.TIMER_COMPLETE, onParserTimerComplete);
parserTimer.stop();
parserTimer = null;
}
parser.removeEventListener(ParseEvent.PARSE_COMPLETE, onParserLoadComplete);
parser.removeEventListener(ParseEvent.PARSE_ERROR, onParserLoadError);
var manifest:Manifest = event.data as Manifest;
finishManifestLoad(manifest);
}
/**
* @private
*/
protected function onParserLoadError(event:ParseEvent):void
{
if (parserTimer)
{
parserTimer.removeEventListener(TimerEvent.TIMER_COMPLETE, onParserTimerComplete);
parserTimer.stop();
parserTimer = null;
}
parser.removeEventListener(ParseEvent.PARSE_COMPLETE, onParserLoadComplete);
parser.removeEventListener(ParseEvent.PARSE_ERROR, onParserLoadError);
updateLoadTrait(loadTrait, LoadState.LOAD_ERROR);
loadTrait.dispatchEvent(new MediaErrorEvent(MediaErrorEvent.MEDIA_ERROR, false, false, new MediaError(MediaErrorCodes.F4M_FILE_INVALID, OSMFStrings.getString(OSMFStrings.F4M_PARSE_ERROR))));
}
/**
* @private
*/
protected function finishManifestLoad(manifest:Manifest):void
{
try
{
var netResource:MediaResourceBase = parser.createResource(manifest, loadTrait.resource);
var loadedElem:MediaElement = factory.createMediaElement(netResource);
if (loadedElem.hasOwnProperty("defaultDuration") && !isNaN(manifest.duration))
{
loadedElem["defaultDuration"] = manifest.duration;
}
LoadFromDocumentLoadTrait(loadTrait).mediaElement = loadedElem;
updateLoadTrait(loadTrait, LoadState.READY);
}
catch (error:Error)
{
updateLoadTrait(loadTrait, LoadState.LOAD_ERROR);
loadTrait.dispatchEvent(new MediaErrorEvent(MediaErrorEvent.MEDIA_ERROR, false, false, new MediaError(MediaErrorCodes.F4M_FILE_INVALID, error.message)));
}
}
/**
* @private
*/
override protected function executeUnload(loadTrait:LoadTrait):void
{
updateLoadTrait(loadTrait, LoadState.UNINITIALIZED);
}
/**
* @private
*
* Defines the <code>BaseManifestBuilder</code> objects used to create the <code>ManifestParser</code>.
*
* @return A <code>Vector</code> of <code>BaseManifestBuilder</code> objects.
*
*/
protected function getBuilders():Vector.<BaseManifestBuilder>
{
var b:Vector.<BaseManifestBuilder> = new Vector.<BaseManifestBuilder>();
b.push(new MultiLevelManifestBuilder());
b.push(new ManifestBuilder());
return b;
}
protected function getParser(resourceData:String):ManifestParser
{
var parser:ManifestParser;
for each (var b:BaseManifestBuilder in builders)
{
if (b.canParse(resourceData))
{
parser = b.build(resourceData) as ManifestParser;
break;
}
}
return parser;
}
protected var factory:MediaFactory;
protected var builders:Vector.<BaseManifestBuilder>;
protected var loadTrait:LoadTrait;
protected var parserTimer:Timer;
protected var parser:ManifestParser;
}
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.