Menu

[r200]: / trunk / plugins / YouTubePlugin / src / org / osmf / youtube / YouTubePlayerProxy.as  Maximize  Restore  History

Download this file

250 lines (207 with data), 7.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
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
/***********************************************************
* Copyright 2010 Adobe Systems Incorporated. All Rights Reserved.
*
* *********************************************************
* The contents of this file are subject to the Berkeley Software Distribution (BSD) Licence
* (the "License"); you may not use this file except in
* compliance with the License.
*
* 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) 2010 Adobe Systems
* Incorporated. All Rights Reserved.
**********************************************************/
package org.osmf.youtube
{
import flash.display.DisplayObject;
import flash.display.InteractiveObject;
import flash.display.LoaderInfo;
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
/**
* This event is fired when the player is loaded and initialized,
* meaning it is ready to receive API calls.
*/
[Event(name="onReady",type="flash.events.Event")]
/**
* This event is fired when an error in the player occurs.
* The possible error codes are 100, 101, and 150.
* The 100 error code is broadcast when the video requested is not found.
* This occurs when a video has been removed (for any reason),
* or it has been marked as private.
* The 101 error code is broadcast when the video requested does not
* allow playback in the embedded players.
* The error code 150 is the same as 101, it's just 101 in disguise!
*/
[Event(name="onError",type="flash.events.Event")]
/**
* This event is fired whenever the player's state changes.
* Possible values are unstarted (-1), ended (0), playing (1), paused (2), buffering (3), video cued (5).
* When the SWF is first loaded it will broadcast an unstarted (-1) event.
* When the video is cued and ready to play it will broadcast a video cued event (5).
*/
[Event(name="onStateChange",type="flash.events.Event")]
/**
* This event is fired whenever the video playback quality changes. For example, if you call the setPlaybackQuality(suggestedQuality) function, this event will fire if the playback quality actually changes. Your code should respond to the event and should not assume that the quality will automatically change when the setPlaybackQuality(suggestedQuality) function is called. Similarly, your code should not assume that playback quality will only change as a result of an explicit call to setPlaybackQuality or any other function that allows you to set a suggested playback quality.
*
* The value that the event broadcasts is the new playback quality. Possible values are "small", "medium", "large", "hd720", "hd1080", and "highres"
*/
[Event(name="onPlaybackQualityChange",type="flash.events.Event")]
/**
* Proxy Sprite that wraps the DisplayObject contained within the YouTube
* SWF. This class provides a means of strongly-typing the YouTube API,
* as well as isolating our own code from changes to YouTube's API.
**/
public class YouTubePlayerProxy extends Sprite
{
/**
* Defines the YouTube chromeless player state of ended.
*
*/
public static const YOUTUBE_STATE_ENDED:int = 0;
/**
* Defines the YouTube chromeless player state of playing.
*
*/
public static const YOUTUBE_STATE_PLAYING:int = 1;
/**
* Defines the YouTube chromeless player state of cued (video loaded).
*
*/
public static const YOUTUBE_STATE_CUED:int = 5;
/**
* The YouTube chromeless player url.
*
*/
public static const CHROMELESS_PLAYER:String = "http://www.youtube.com/apiplayer?version=3";
public function YouTubePlayerProxy(playerObject:Object)
{
player = playerObject;
this.addChild(player as DisplayObject);
this.addEventListener(MouseEvent.MOUSE_MOVE, onMouseEvent);
}
public function setSize(width:Number, height:Number):void
{
player.setSize(width, height);
}
public function getDuration():Number
{
return player.getDuration();
}
public function cueVideoById(id:String, startSeconds:Number = 0, suggestedQuality:String = "default"):void
{
player.cueVideoById(id, startSeconds, suggestedQuality);
}
public function loadVideoById(id:String, startSeconds:Number = 0, suggestedQuality:String = "default"):void
{
player.loadVideoById(id, startSeconds, suggestedQuality);
}
public function getCurrentTime():Number
{
return player.getCurrentTime();
}
public function seekTo(time:Number, allowSeekAhead:Boolean=false):void
{
player.seekTo(time, allowSeekAhead);
}
public function playVideo():void
{
trace(getPlayerState());
player.playVideo();
}
public function pauseVideo():void
{
trace(getPlayerState());
player.pauseVideo();
}
public function stopVideo():void
{
player.stopVideo();
}
public function getPlayerState():int
{
return player.getPlayerState();
}
public function getAvailableQualityLevels():Array
{
return player.getAvailableQualityLevels();
}
public function setPlaybackQuality(suggestedQualityLevel:String):void
{
player.setPlaybackQuality(suggestedQualityLevel);
}
public function getPlaybackQuality():String
{
return player.getPlaybackQuality();
}
public function isMuted():Boolean
{
return player.isMuted();
}
public function getVolume():Number
{
return player.getVolume();
}
public function mute():void
{
player.mute();
}
public function unMute():void
{
player.unMute();
}
public function setVolume(value:Number):void
{
player.setVolume(value);
}
public function getVideoStartBytes():Number
{
return player.getVideoStartBytes();
}
public function getVideoBytesLoaded():Number
{
return player.getVideoBytesLoaded();
}
public function getVideoBytesTotal():Number
{
return player.getVideoBytesTotal();
}
public function destroy():void
{
player.destroy();
}
// Overrides
//
override public function addEventListener(type:String, listener:Function, useCapture:Boolean = false,
priority:int = 0, useWeakReference:Boolean = false):void
{
player.addEventListener(type, listener, useCapture, priority, useWeakReference);
}
override public function removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void
{
player.removeEventListener(type, listener, useCapture);
}
override public function dispatchEvent(event:Event):Boolean
{
return player.dispatchEvent(event);
}
override public function get loaderInfo():LoaderInfo
{
return player.loaderInfo;
}
// Internals
//
private function onMouseEvent(event:Event):void
{
super.dispatchEvent(event);
}
private var player:Object;
}
}
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.