-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEBVideoMgr.as
executable file
·294 lines (246 loc) · 8.15 KB
/
EBVideoMgr.as
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
//****************************************************************************
// EBVideoMgr class
//---------------------------
//
//This class contains the APIs related to controlling all the videos on stage
//
//ALL RIGHTS RESERVED TO MEDIAMIND INC. (C)
//****************************************************************************
package
{
import eyeblaster.core.Tracer;
import eyeblaster.events.EBNotificationEvent;
import eyeblaster.events.EBVideoEvent;
import eyeblaster.events.EBVideoManagerEvent;
import eyeblaster.videoPlayer.IVideoScreen;
import eyeblaster.videoPlayer.controls.IVideoControl;
import eyeblaster.videoPlayer.core.RunLoop;
import flash.display.MovieClip;
import flash.events.*;
import flash.utils.setInterval;
import flash.utils.setTimeout;
public class EBVideoMgr
{
public static var isForcedStreaming:Boolean;
//++++++++++++++++++++++++++++++++++++++++++++++++++++
// Private Attributes
//++++++++++++++++++++++++++++++++++++++++++++++++++++
private static var videos:Object;
private static var tempFuncArray:Array;
private static var checkInterval:Number;
private static var _currId:int = 1;
private static var initialized:Boolean = false;
private static var _current:IVideoScreen;
private static var _adVolume:int = 100;
private static var dispatcher:EventDispatcher = new EventDispatcher();
//++++++++++++++++++++++++++++++++++++++++++++++++++++
// Methods
//++++++++++++++++++++++++++++++++++++++++++++++++++++
//++++++++++++++++++++++++++++++++++++++++++++++++++++
// public Methods
//++++++++++++++++++++++++++++++++++++++++++++++++++++
public static function Init():void
{
videos = new Array();
initialized = true;
if(typeof(EBBase.urlParams.ebForcePlayMode) != "undefined")
{
isForcedStreaming = Boolean(Number(EBBase.urlParams.ebForcePlayMode));
}
if(tempFuncArray != null){
for( var i:int = 0; i < tempFuncArray.length; i++) tempFuncArray[i]();
}
EBBase.addEventListener(EBNotificationEvent.NOTIFICATION,_OnNotification);
}
/**
* Registers a video with the EBVideoMgr. Videos should already be registered automatically however.
*/
public static function RegisterVideo(screen:*):void
{
if(screen is IVideoScreen){
if(initialized){
setTimeout( initializeView, 1, screen );
} else initCall(EBVideoMgr.RegisterVideo, arguments);
} else {
var screenName:String = screen.name;
if(screenName == "_videoLoader"){
// _videoLoader is used by the private instance inside a VideoPlayback control. We instead register it using the VideoPlayback control name
screenName = screen.parent.name;
}
videos[screenName] = screen;
dispatchEvent(new EBVideoManagerEvent(EBVideoManagerEvent.VIDEO_REGISTERED, screen));
}
}
/**
* Register a video control (implementor of IVideoControl) by its instance name.
* Once the video is available, the initialize function of the IVideoControl will be called.
*
* @param displayObject:IVideoControl Video Control to associate a video with
* @return Whether or not video already existed. If not, control will be queued into video is available
*
*/
public static function RegisterControlToScreen(control:IVideoControl ):Boolean
{
if(initialized){
setTimeout(initializeControl,1, control);
return true;
} else initCall(EBVideoMgr.RegisterControlToScreen, arguments);
return false;
}
private static function initializeView( screen:IVideoScreen ):void
{
_current = screen; // Go ahead and set as current
var _id:int = _currId++;
videos[screen.name] = screen;
screen.initialize(_id);
screen.addEventListener(EBVideoEvent.PLAYBACK_START,_OnVideoStart);
dispatchEvent(new EBVideoManagerEvent(EBVideoManagerEvent.VIDEO_REGISTERED, screen));
dispatchEvent(new EBVideoManagerEvent(EBVideoManagerEvent.VIDEO_CHANGED, screen));
}
private static function initializeControl(control:IVideoControl):void
{
control.initialize();
}
private static function _OnVideoStart(event:EBVideoEvent):void
{
_current = event.target as IVideoScreen; // automatically set when playing
dispatchEvent(new EBVideoManagerEvent(EBVideoManagerEvent.VIDEO_CHANGED, event.target));
}
private static function _OnNotification(event:EBNotificationEvent):void
{
if(event.subtype == EBNotificationEvent.CLOSE){
StopAll();
}
}
private static function initCall( func:Function, argref:Array ):void
{
var delayFunction:Function = function():void
{
func.apply( this, argref );
};
if(tempFuncArray == null){
tempFuncArray = new Array();
}
tempFuncArray.push( delayFunction );
}
/**
* Stops all of the videos in the ad
*/
public static function StopAll():void
{
for each(var video:* in videos)
{
video.stop();
}
}
/**
* Sets the volume to all videos in the ad.
*
* @param nVolLevel:Number The volume to set all of the videos to, on a scale of 0-100
*/
public static function SetAdVolume(nVolLevel:Number):void
{
_adVolume = nVolLevel;
for each(var video:* in videos)
{
video.volume = nVolLevel;
}
}
/**
* Toggles the audio for all videos in the ad
*
* @param nMuteVal:int 0 = unmute all , 1 = mute all, 2 = toggle all
* @param nAutoInit:int 0 = user-initiated, 1 = auto-initiated
*/
public static function ToggleAdAudio(nMuteVal:int = 2, nAutoInit:int = 0):void
{
for each(var video:* in videos)
{
if(video is IVideoScreen){
if(nMuteVal == 2){
if(video.isMuted){
nMuteVal = 0;
} else {
nMuteVal = 1;
}
}
switch(nMuteVal){
case 0:
video.unmute();
if(nAutoInit == 0){
video.track("ebVideoUnmute");
}
break;
case 1:
video.mute();
if(nAutoInit == 1){
video.track("VideoMute");
}
break;
}
} else {
video.setMute(nMuteVal,nAutoInit);
}
}
}
/**
* Gets an instance of a IVideoScreen from anywhere.
*
* @param screenName:String Instance name of video to get
* @return An instance of IVideoScreen with that name.
*
*/
public static function GetScreen(screenName:String):IVideoScreen
{
return GetVideo(screenName) as IVideoScreen;
}
/**
* Gets an instance of a video object from anywhere. If you know that the video object will be IVideoScreen, use GetScreen()
* This will work automatically for any VideoScreen component instances, but will require that a VideoLoader be registered.
*
* @param screenName:String instance name of video to get
* @return An instance of the video with that name
* @see #GetScreen()
*/
public static function GetVideo(screenName:String):*
{
var video:*;
video = videos[screenName];
if( videos[screenName] == undefined ) return null;
return video;
}
/**
* Gets the current playing IVideoScreen. This does not work for VideoLoader
*/
public static function get Current():IVideoScreen
{
return _current;
}
/**
* Retrieves the current volume that the ad should use.
*/
public static function get AdVolume():int
{
return _adVolume;
}
/**
* An array of the videos. If you know the name of the video already, you can use #GetVideo() instead.
*/
public static function get Videos():Array
{
var v:Array = new Array();
for (var prop:String in videos) {
v.push(videos[prop]);
}
return v;
}
public static function addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void
{
dispatcher.addEventListener(type, listener, useCapture, priority, useWeakReference);
}
public static function dispatchEvent(e:Event):void
{
dispatcher.dispatchEvent(e);
}
}
}