diff options
author | Nivesh Rajbhandari | 2012-03-27 09:32:53 -0700 |
---|---|---|
committer | Nivesh Rajbhandari | 2012-03-27 09:32:53 -0700 |
commit | 406bbfc63f8ed42d7da105dbd068a49ff8fb5f09 (patch) | |
tree | 3a8b45f4802f002269ff1bcf596f94cee4679a07 /node_modules/montage/ui/youtube-player.reel/youtube-player.js | |
parent | bda9f8f5829c943486f8850e68c991e83f8fb8c8 (diff) | |
parent | 309dde5a8c4599cef6a1052c1ff9ee1ad8ec5858 (diff) | |
download | ninja-406bbfc63f8ed42d7da105dbd068a49ff8fb5f09.tar.gz |
Merge branch 'refs/heads/ninja-internal' into WebGLMaterials
Signed-off-by: Nivesh Rajbhandari <mqg734@motorola.com>
Diffstat (limited to 'node_modules/montage/ui/youtube-player.reel/youtube-player.js')
-rw-r--r-- | node_modules/montage/ui/youtube-player.reel/youtube-player.js | 216 |
1 files changed, 216 insertions, 0 deletions
diff --git a/node_modules/montage/ui/youtube-player.reel/youtube-player.js b/node_modules/montage/ui/youtube-player.reel/youtube-player.js new file mode 100644 index 00000000..b49f6ae1 --- /dev/null +++ b/node_modules/montage/ui/youtube-player.reel/youtube-player.js | |||
@@ -0,0 +1,216 @@ | |||
1 | /* <copyright> | ||
2 | This file contains proprietary software owned by Motorola Mobility, Inc.<br/> | ||
3 | No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/> | ||
4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. | ||
5 | </copyright> */ | ||
6 | /*global require,exports,YT */ | ||
7 | var Montage = require("montage").Montage, | ||
8 | Component = require("ui/component").Component; | ||
9 | |||
10 | var YoutubePlayer = exports.YoutubePlayer = Montage.create(Component, { | ||
11 | |||
12 | // Stores a queue of function calls to make on the player in the draw | ||
13 | // function | ||
14 | _playerQueue: { | ||
15 | enumerable: false, | ||
16 | value: [] | ||
17 | }, | ||
18 | |||
19 | _ready: { | ||
20 | enumerable: false, | ||
21 | value: false | ||
22 | }, | ||
23 | |||
24 | _player: { | ||
25 | enumerable: false, | ||
26 | value: null | ||
27 | }, | ||
28 | player: { | ||
29 | get: function() { | ||
30 | return this._player; | ||
31 | }, | ||
32 | set: function(value) { | ||
33 | if (this._player !== value) { | ||
34 | this._player = value; | ||
35 | } | ||
36 | } | ||
37 | }, | ||
38 | |||
39 | _width: { | ||
40 | enumerable: false, | ||
41 | value: 640 | ||
42 | }, | ||
43 | width: { | ||
44 | get: function() { | ||
45 | return this._width; | ||
46 | }, | ||
47 | set: function(value) { | ||
48 | if (this._width !== value) { | ||
49 | this._width = value; | ||
50 | this.needsDraw = true; | ||
51 | } | ||
52 | } | ||
53 | }, | ||
54 | _height: { | ||
55 | enumerable: false, | ||
56 | value: 385 | ||
57 | }, | ||
58 | height: { | ||
59 | get: function() { | ||
60 | return this._height; | ||
61 | }, | ||
62 | set: function(value) { | ||
63 | if (this._height !== value) { | ||
64 | this._height = value; | ||
65 | this.needsDraw = true; | ||
66 | } | ||
67 | } | ||
68 | }, | ||
69 | |||
70 | _autoplay: { | ||
71 | enumerable: false, | ||
72 | value: false | ||
73 | }, | ||
74 | autoplay: { | ||
75 | get: function() { | ||
76 | return this._autoplay; | ||
77 | }, | ||
78 | set: function(value) { | ||
79 | if (this._autoplay !== value) { | ||
80 | this._autoplay = value; | ||
81 | this.needsDraw = true; | ||
82 | } | ||
83 | } | ||
84 | }, | ||
85 | |||
86 | _videoId: { | ||
87 | enumerable: false, | ||
88 | value: null | ||
89 | }, | ||
90 | videoId: { | ||
91 | get: function() { | ||
92 | return this._videoId; | ||
93 | }, | ||
94 | set: function(value) { | ||
95 | if (this._videoId !== value) { | ||
96 | // TODO handle URLs as well | ||
97 | this._videoId = value; | ||
98 | |||
99 | // If the video isn't in the playlist, clear the playlist, | ||
100 | if (this._playlist && this._playlist.indexOf(value) === -1) { | ||
101 | this._playlist = null; | ||
102 | } | ||
103 | // TODO if the video is in the playlist use playVideoAt | ||
104 | |||
105 | if (this._autoplay) { | ||
106 | this._playerQueue.push(["loadVideoById", value]); | ||
107 | } else { | ||
108 | this._playerQueue.push(["cueVideoById", value]); | ||
109 | } | ||
110 | this.needsDraw = true; | ||
111 | } | ||
112 | } | ||
113 | }, | ||
114 | |||
115 | _playlist: { | ||
116 | enumerable: false, | ||
117 | value: null | ||
118 | }, | ||
119 | playlist: { | ||
120 | get: function() { | ||
121 | return this._playlist; | ||
122 | }, | ||
123 | set: function(value) { | ||
124 | if (this._playlist !== value) { | ||
125 | this._playlist = value; | ||
126 | |||
127 | if (this._autoplay) { | ||
128 | this._playerQueue.push(["loadPlaylist", value]); | ||
129 | } else { | ||
130 | this._playerQueue.push(["cuePlaylist", value]); | ||
131 | } | ||
132 | this.needsDraw = true; | ||
133 | } | ||
134 | } | ||
135 | }, | ||
136 | |||
137 | play: { | ||
138 | value: function() { | ||
139 | this._playerQueue.push("playVideo"); | ||
140 | this.needsDraw = true; | ||
141 | } | ||
142 | }, | ||
143 | pause: { | ||
144 | value: function() { | ||
145 | this._playerQueue.push("pauseVideo"); | ||
146 | this.needsDraw = true; | ||
147 | } | ||
148 | }, | ||
149 | stop: { | ||
150 | value: function() { | ||
151 | this._playerQueue.push("stopVideo"); | ||
152 | this.needsDraw = true; | ||
153 | } | ||
154 | }, | ||
155 | |||
156 | prepareForDraw: { | ||
157 | value: function() { | ||
158 | // Create the callback if it doesn't exist, and make it dispatch | ||
159 | // an event on the document instead | ||
160 | if (!window.onYouTubePlayerAPIReady) { | ||
161 | window.onYouTubePlayerAPIReady = function() { | ||
162 | var event = document.createEvent("CustomEvent"); | ||
163 | event.initEvent("youtubePlayerApiReady", true, true); | ||
164 | document.dispatchEvent(event); | ||
165 | }; | ||
166 | } | ||
167 | |||
168 | this._element.src += (this._videoId ? "/" + this._videoId : "") + "?enablejsapi=1"; | ||
169 | |||
170 | if (typeof YT !== "undefined" && YT.Player) { | ||
171 | this.handleYoutubePlayerApiReady(); | ||
172 | } else { | ||
173 | document.addEventListener("youtubePlayerApiReady", this, false); | ||
174 | } | ||
175 | } | ||
176 | }, | ||
177 | |||
178 | handleYoutubePlayerApiReady: { | ||
179 | value: function(event) { | ||
180 | document.removeEventListener("youtubePlayerApiReady", this); | ||
181 | |||
182 | var self = this; | ||
183 | this.player = new YT.Player(this._element, { events: { | ||
184 | onReady: function(event) { | ||
185 | self._ready = true; | ||
186 | self.needsDraw = true; | ||
187 | } | ||
188 | }}); | ||
189 | } | ||
190 | }, | ||
191 | |||
192 | draw: { | ||
193 | value: function() { | ||
194 | if (!this._ready) { | ||
195 | return; | ||
196 | } | ||
197 | |||
198 | for (var i = 0, len = this._playerQueue.length; i < len; i++) { | ||
199 | var fnName, args; | ||
200 | if (typeof this._playerQueue[i] === "string") { | ||
201 | fnName = this._playerQueue[i]; | ||
202 | args = []; | ||
203 | } else { | ||
204 | fnName = this._playerQueue[i].shift(); | ||
205 | args = this._playerQueue[i]; | ||
206 | } | ||
207 | |||
208 | this._player[fnName].apply(this._player, args); | ||