[r255]: trunk / framework / OSMF / org / osmf / net / DynamicStreamingResource.as Maximize Restore History

Download this file

DynamicStreamingResource.as    193 lines (175 with data), 5.5 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
/*****************************************************
*
* Copyright 2009 Akamai Technologies, Inc. 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 Akamai Technologies, Inc.
* Portions created by Akamai Technologies, Inc. are Copyright (C) 2009 Akamai
* Technologies, Inc. All Rights Reserved.
*
* Contributor: Adobe Systems Inc.
*
*****************************************************/
package org.osmf.net
{
import __AS3__.vec.Vector;
import org.osmf.utils.OSMFStrings;
/**
* DynamicStreamingResource encapsulates multiple representations of a
* piece of media, such that the player application can dynamically
* switch from one representation to another. Typically (though not
* always), each representation is encoded at a different bitrate,
* and the player application switches between representations based
* on changes to the client's available bandwidth.
*
* <p>This class provides an object representation of a dynamic streaming
* resource without any knowledge or assumption of any file format,
* such as SMIL, Media RSS, F4M, etc.</p>
*
* @includeExample DynamicStreamingResourceExample.as -noswf
*
* @langversion 3.0
* @playerversion Flash 10
* @playerversion AIR 1.5
* @productversion OSMF 1.0
*/
public class DynamicStreamingResource extends StreamingURLResource
{
/**
* Constructor.
*
* @param host A URL representing the host of the dynamic streaming resource.
* @param streamType The type of the stream. If null, defaults to StreamType.RECORDED.
*
* @langversion 3.0
* @playerversion Flash 10
* @playerversion AIR 1.5
* @productversion OSMF 1.0
*/
public function DynamicStreamingResource(host:String, streamType:String=null)
{
super(host, streamType);
_initialIndex = 0;
}
/**
* A URL representing the host of the dynamic streaming resource.
*
* @langversion 3.0
* @playerversion Flash 10
* @playerversion AIR 1.5
* @productversion OSMF 1.0
*/
public function get host():String
{
return url;
}
/**
* Vector of DynamicStreamingItems. Each item represents a
* different bitrate stream.
*
* @langversion 3.0
* @playerversion Flash 10
* @playerversion AIR 1.5
* @productversion OSMF 1.0
*/
public function get streamItems():Vector.<DynamicStreamingItem>
{
if (_streamItems == null)
{
_streamItems = new Vector.<DynamicStreamingItem>();
}
return _streamItems;
}
public function set streamItems(value:Vector.<DynamicStreamingItem>):void
{
_streamItems = value;
if (value != null)
{
value.sort(compareStreamItems);
}
}
/**
* The preferred starting index.
*
* @throws RangeError If the index is out of range.
*
* @langversion 3.0
* @playerversion Flash 10
* @playerversion AIR 1.5
* @productversion OSMF 1.0
*/
public function get initialIndex():int
{
return _initialIndex;
}
public function set initialIndex(value:int):void
{
if (_streamItems == null || value >= _streamItems.length)
{
throw new RangeError(OSMFStrings.getString(OSMFStrings.INVALID_PARAM));
}
_initialIndex = value;
}
// Internals
//
/**
* @private
*
* Returns the index associated with a stream name. The match will be tried
* both with and without a mp4: prefix. Returns -1 if no match is found.
*/
internal function indexFromName(name:String):int
{
for (var i:int = 0; i < _streamItems.length; i++)
{
// FM-925, stream name may be appended with parameters.
if (_streamItems[i].streamName.indexOf(name) == 0 ||
_streamItems[i].streamName.indexOf("mp4:" + name) == 0)
{
return i;
}
}
return -1;
}
/**
* A comparison method that determines the behavior of the sort of the vector member variable.
* Given two elements a and b, the function returns one of the following three values:
* <ol>
* <li>a negative number, if a should appear before b in the sorted sequence</li>
* <li>0, if a equals b</li>
* <li>a positive number, if a should appear after b in the sorted sequence</li>
* </ol>
*
* @langversion 3.0
* @playerversion Flash 10
* @playerversion AIR 1.5
* @productversion OSMF 1.0
*/
private function compareStreamItems(a:DynamicStreamingItem, b:DynamicStreamingItem):Number
{
var result:Number = -1;
if (a.bitrate == b.bitrate)
{
result = 0;
}
else if (a.bitrate > b.bitrate)
{
result = 1;
}
return result;
}
private var _streamItems:Vector.<DynamicStreamingItem>;
private var _initialIndex:int;
}
}