| 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 18 matching lines...) Expand all Loading... |
| 29 */ | 29 */ |
| 30 function CastVideoElement(media, session) { | 30 function CastVideoElement(media, session) { |
| 31 this.mediaManager_ = media; | 31 this.mediaManager_ = media; |
| 32 this.mediaInfo_ = null; | 32 this.mediaInfo_ = null; |
| 33 | 33 |
| 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.loop_ = false; |
| 39 this.currentMediaPlayerState_ = null; | 40 this.currentMediaPlayerState_ = null; |
| 40 this.currentMediaCurrentTime_ = null; | 41 this.currentMediaCurrentTime_ = null; |
| 41 this.currentMediaDuration_ = null; | 42 this.currentMediaDuration_ = null; |
| 42 this.playInProgress_ = false; | 43 this.playInProgress_ = false; |
| 43 this.pauseInProgress_ = false; | 44 this.pauseInProgress_ = false; |
| 44 this.errorCode_ = 0; | 45 this.errorCode_ = 0; |
| 45 | 46 |
| 46 this.onMessageBound_ = this.onMessage_.bind(this); | 47 this.onMessageBound_ = this.onMessage_.bind(this); |
| 47 this.onCastMediaUpdatedBound_ = this.onCastMediaUpdated_.bind(this); | 48 this.onCastMediaUpdatedBound_ = this.onCastMediaUpdated_.bind(this); |
| 48 this.castSession_.addMessageListener( | 49 this.castSession_.addMessageListener( |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 * @type {?string} | 187 * @type {?string} |
| 187 */ | 188 */ |
| 188 get src() { | 189 get src() { |
| 189 return null; | 190 return null; |
| 190 }, | 191 }, |
| 191 set src(value) { | 192 set src(value) { |
| 192 // Do nothing. | 193 // Do nothing. |
| 193 }, | 194 }, |
| 194 | 195 |
| 195 /** | 196 /** |
| 197 * Returns the flag if the video loops at end or not. |
| 198 * @type {boolean} |
| 199 */ |
| 200 get loop() { |
| 201 return this.loop_; |
| 202 }, |
| 203 set loop(value) { |
| 204 this.loop_ = !!value; |
| 205 }, |
| 206 |
| 207 /** |
| 196 * Returns the error object if available. | 208 * Returns the error object if available. |
| 197 * @type {?Object} | 209 * @type {?Object} |
| 198 */ | 210 */ |
| 199 get error() { | 211 get error() { |
| 200 if (this.errorCode_ === 0) | 212 if (this.errorCode_ === 0) |
| 201 return null; | 213 return null; |
| 202 | 214 |
| 203 return {code: this.errorCode_}; | 215 return {code: this.errorCode_}; |
| 204 }, | 216 }, |
| 205 | 217 |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 * is fired. | 413 * is fired. |
| 402 * | 414 * |
| 403 * @param {boolean} alive Media availability. False if it's unavailable. | 415 * @param {boolean} alive Media availability. False if it's unavailable. |
| 404 * @private | 416 * @private |
| 405 */ | 417 */ |
| 406 onCastMediaUpdated_: function(alive) { | 418 onCastMediaUpdated_: function(alive) { |
| 407 if (!this.castMedia_) | 419 if (!this.castMedia_) |
| 408 return; | 420 return; |
| 409 | 421 |
| 410 var media = this.castMedia_; | 422 var media = this.castMedia_; |
| 423 if (this.loop_ && |
| 424 media.idleReason === chrome.cast.media.IdleReason.FINISHED && |
| 425 !alive) { |
| 426 // Resets the previous media silently. |
| 427 this.castMedia_ = null; |
| 428 |
| 429 // Replay the current media. |
| 430 this.currentMediaPlayerState_ = chrome.cast.media.PlayerState.BUFFERING; |
| 431 this.currentMediaCurrentTime_ = 0; |
| 432 this.dispatchEvent(new Event('play')); |
| 433 this.dispatchEvent(new Event('timeupdate')); |
| 434 this.play(); |
| 435 return; |
| 436 } |
| 437 |
| 411 if (this.currentMediaPlayerState_ !== media.playerState) { | 438 if (this.currentMediaPlayerState_ !== media.playerState) { |
| 412 var oldPlayState = false; | 439 var oldPlayState = false; |
| 413 var oldState = this.currentMediaPlayerState_; | 440 var oldState = this.currentMediaPlayerState_; |
| 414 if (oldState === chrome.cast.media.PlayerState.BUFFERING || | 441 if (oldState === chrome.cast.media.PlayerState.BUFFERING || |
| 415 oldState === chrome.cast.media.PlayerState.PLAYING) { | 442 oldState === chrome.cast.media.PlayerState.PLAYING) { |
| 416 oldPlayState = true; | 443 oldPlayState = true; |
| 417 } | 444 } |
| 418 var newPlayState = false; | 445 var newPlayState = false; |
| 419 var newState = media.playerState; | 446 var newState = media.playerState; |
| 420 if (newState === chrome.cast.media.PlayerState.BUFFERING || | 447 if (newState === chrome.cast.media.PlayerState.BUFFERING || |
| (...skipping 17 matching lines...) Expand all Loading... |
| 438 this.dispatchEvent(new Event('durationchange')); | 465 this.dispatchEvent(new Event('durationchange')); |
| 439 } | 466 } |
| 440 | 467 |
| 441 // Media is being unloaded. | 468 // Media is being unloaded. |
| 442 if (!alive) { | 469 if (!alive) { |
| 443 this.unloadMedia_(); | 470 this.unloadMedia_(); |
| 444 return; | 471 return; |
| 445 } | 472 } |
| 446 }, | 473 }, |
| 447 }; | 474 }; |
| OLD | NEW |