OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 'use strict'; | 5 'use strict'; |
6 | 6 |
7 /** | 7 /** |
8 * Interval for updating media info (in ms). | 8 * Interval for updating media info (in ms). |
9 * @type {number} | 9 * @type {number} |
10 * @const | 10 * @const |
(...skipping 23 matching lines...) Expand all Loading... |
34 this.castMedia_ = null; | 34 this.castMedia_ = null; |
35 this.castSession_ = session; | 35 this.castSession_ = session; |
36 this.currentTime_ = null; | 36 this.currentTime_ = null; |
37 this.src_ = ''; | 37 this.src_ = ''; |
38 this.volume_ = 100; | 38 this.volume_ = 100; |
39 this.currentMediaPlayerState_ = null; | 39 this.currentMediaPlayerState_ = null; |
40 this.currentMediaCurrentTime_ = null; | 40 this.currentMediaCurrentTime_ = null; |
41 this.currentMediaDuration_ = null; | 41 this.currentMediaDuration_ = null; |
42 this.playInProgress_ = false; | 42 this.playInProgress_ = false; |
43 this.pauseInProgress_ = false; | 43 this.pauseInProgress_ = false; |
| 44 this.errorCode_ = 0; |
44 | 45 |
45 this.onMessageBound_ = this.onMessage_.bind(this); | 46 this.onMessageBound_ = this.onMessage_.bind(this); |
46 this.onCastMediaUpdatedBound_ = this.onCastMediaUpdated_.bind(this); | 47 this.onCastMediaUpdatedBound_ = this.onCastMediaUpdated_.bind(this); |
47 this.castSession_.addMessageListener( | 48 this.castSession_.addMessageListener( |
48 CAST_MESSAGE_NAMESPACE, this.onMessageBound_); | 49 CAST_MESSAGE_NAMESPACE, this.onMessageBound_); |
49 } | 50 } |
50 | 51 |
51 CastVideoElement.prototype = { | 52 CastVideoElement.prototype = { |
52 __proto__: cr.EventTarget.prototype, | 53 __proto__: cr.EventTarget.prototype, |
53 | 54 |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 * @type {?string} | 183 * @type {?string} |
183 */ | 184 */ |
184 get src() { | 185 get src() { |
185 return null; | 186 return null; |
186 }, | 187 }, |
187 set src(value) { | 188 set src(value) { |
188 // Do nothing. | 189 // Do nothing. |
189 }, | 190 }, |
190 | 191 |
191 /** | 192 /** |
| 193 * Returns the error object if available. |
| 194 * @type {?Object} |
| 195 */ |
| 196 get error() { |
| 197 if (this.errorCode_ === 0) |
| 198 return null; |
| 199 |
| 200 return {code: this.errorCode_}; |
| 201 }, |
| 202 |
| 203 /** |
192 * Plays the video. | 204 * Plays the video. |
193 */ | 205 */ |
194 play: function() { | 206 play: function() { |
195 var play = function() { | 207 var play = function() { |
196 this.castMedia_.play(null, | 208 this.castMedia_.play(null, |
197 function() { | 209 function() { |
198 this.playInProgress_ = false; | 210 this.playInProgress_ = false; |
199 }.wrap(this), | 211 }.wrap(this), |
200 function(error) { | 212 function(error) { |
201 this.playInProgress_ = false; | 213 this.playInProgress_ = false; |
(...skipping 29 matching lines...) Expand all Loading... |
231 | 243 |
232 /** | 244 /** |
233 * Loads the video. | 245 * Loads the video. |
234 */ | 246 */ |
235 load: function(opt_callback) { | 247 load: function(opt_callback) { |
236 var sendTokenPromise = this.mediaManager_.getToken().then(function(token) { | 248 var sendTokenPromise = this.mediaManager_.getToken().then(function(token) { |
237 this.token_ = token; | 249 this.token_ = token; |
238 this.sendMessage_({message: 'push-token', token: token}); | 250 this.sendMessage_({message: 'push-token', token: token}); |
239 }.bind(this)); | 251 }.bind(this)); |
240 | 252 |
| 253 // Resets the error code. |
| 254 this.errorCode_ = 0; |
| 255 |
241 Promise.all([ | 256 Promise.all([ |
242 sendTokenPromise, | 257 sendTokenPromise, |
243 this.mediaManager_.getUrl(), | 258 this.mediaManager_.getUrl(), |
244 this.mediaManager_.getMime(), | 259 this.mediaManager_.getMime(), |
245 this.mediaManager_.getThumbnail()]). | 260 this.mediaManager_.getThumbnail()]). |
246 then(function(results) { | 261 then(function(results) { |
247 var url = results[1]; | 262 var url = results[1]; |
248 var mime = results[2]; | 263 var mime = results[2]; |
249 var thumbnailUrl = results[3]; | 264 var thumbnailUrl = results[3]; |
250 | 265 |
(...skipping 29 matching lines...) Expand all Loading... |
280 function() {}, | 295 function() {}, |
281 function(error) { | 296 function(error) { |
282 // Ignores session error, since session may already be closed. | 297 // Ignores session error, since session may already be closed. |
283 if (error.code !== chrome.cast.ErrorCode.SESSION_ERROR) | 298 if (error.code !== chrome.cast.ErrorCode.SESSION_ERROR) |
284 this.onCastCommandError_(error); | 299 this.onCastCommandError_(error); |
285 }.wrap(this)); | 300 }.wrap(this)); |
286 | 301 |
287 this.castMedia_.removeUpdateListener(this.onCastMediaUpdatedBound_); | 302 this.castMedia_.removeUpdateListener(this.onCastMediaUpdatedBound_); |
288 this.castMedia_ = null; | 303 this.castMedia_ = null; |
289 } | 304 } |
| 305 |
290 clearInterval(this.updateTimerId_); | 306 clearInterval(this.updateTimerId_); |
291 }, | 307 }, |
292 | 308 |
293 /** | 309 /** |
294 * Sends the message to cast. | 310 * Sends the message to cast. |
295 * @param {Object} message Message to be sent (Must be JSON-able object). | 311 * @param {Object} message Message to be sent (Must be JSON-able object). |
296 * @private | 312 * @private |
297 */ | 313 */ |
298 sendMessage_: function(message) { | 314 sendMessage_: function(message) { |
299 this.castSession_.sendMessage(CAST_MESSAGE_NAMESPACE, message); | 315 this.castSession_.sendMessage(CAST_MESSAGE_NAMESPACE, message); |
(...skipping 18 matching lines...) Expand all Loading... |
318 }.bind(this)).catch(function(error) { | 334 }.bind(this)).catch(function(error) { |
319 // Send an empty token as an error. | 335 // Send an empty token as an error. |
320 this.sendMessage_({message: 'push-token', token: ''}); | 336 this.sendMessage_({message: 'push-token', token: ''}); |
321 // TODO(yoshiki): Revokes the previous token. | 337 // TODO(yoshiki): Revokes the previous token. |
322 console.error(error.stack || error); | 338 console.error(error.stack || error); |
323 }); | 339 }); |
324 } else { | 340 } else { |
325 console.error( | 341 console.error( |
326 'New token is requested, but the previous token mismatches.'); | 342 'New token is requested, but the previous token mismatches.'); |
327 } | 343 } |
| 344 } else if (message['message'] === 'playback-error') { |
| 345 if (message['detail'] === 'src-not-supported') |
| 346 this.errorCode_ = MediaError.MEDIA_ERR_SRC_NOT_SUPPORTED; |
328 } | 347 } |
329 }, | 348 }, |
330 | 349 |
331 /** | 350 /** |
332 * This method is called periodically to update media information while the | 351 * This method is called periodically to update media information while the |
333 * media is loaded. | 352 * media is loaded. |
334 * @private | 353 * @private |
335 */ | 354 */ |
336 onPeriodicalUpdateTimer_: function() { | 355 onPeriodicalUpdateTimer_: function() { |
337 if (!this.castMedia_) | 356 if (!this.castMedia_) |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 this.dispatchEvent(new Event('durationchange')); | 434 this.dispatchEvent(new Event('durationchange')); |
416 } | 435 } |
417 | 436 |
418 // Media is being unloaded. | 437 // Media is being unloaded. |
419 if (!alive) { | 438 if (!alive) { |
420 this.unloadMedia_(); | 439 this.unloadMedia_(); |
421 return; | 440 return; |
422 } | 441 } |
423 }, | 442 }, |
424 }; | 443 }; |
OLD | NEW |