| 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 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 */ | 210 */ |
| 211 get error() { | 211 get error() { |
| 212 if (this.errorCode_ === 0) | 212 if (this.errorCode_ === 0) |
| 213 return null; | 213 return null; |
| 214 | 214 |
| 215 return {code: this.errorCode_}; | 215 return {code: this.errorCode_}; |
| 216 }, | 216 }, |
| 217 | 217 |
| 218 /** | 218 /** |
| 219 * Plays the video. | 219 * Plays the video. |
| 220 * @param {boolean=} opt_seeking True when seeking. False otherwise. |
| 220 */ | 221 */ |
| 221 play: function() { | 222 play: function(opt_seeking) { |
| 223 if (this.playInProgress_) |
| 224 return; |
| 225 |
| 222 var play = function() { | 226 var play = function() { |
| 223 this.castMedia_.play(null, | 227 if (this.castMedia_.playerState === |
| 228 chrome.cast.media.PlayerState.PLAYING) { |
| 229 return; |
| 230 } |
| 231 |
| 232 var playRequest = new chrome.cast.media.PlayRequest(); |
| 233 playRequest.customData = {seeking: !!opt_seeking}; |
| 234 |
| 235 this.castMedia_.play( |
| 236 playRequest, |
| 224 function() { | 237 function() { |
| 225 this.playInProgress_ = false; | 238 this.playInProgress_ = false; |
| 226 }.wrap(this), | 239 }.wrap(this), |
| 227 function(error) { | 240 function(error) { |
| 228 this.playInProgress_ = false; | 241 this.playInProgress_ = false; |
| 229 this.onCastCommandError_(error); | 242 this.onCastCommandError_(error); |
| 230 }.wrap(this)); | 243 }.wrap(this)); |
| 231 }.wrap(this); | 244 }.wrap(this); |
| 232 | 245 |
| 233 this.playInProgress_ = true; | 246 this.playInProgress_ = true; |
| 234 | 247 |
| 235 if (!this.castMedia_) | 248 if (!this.castMedia_) |
| 236 this.load(play); | 249 this.load(play); |
| 237 else | 250 else |
| 238 play(); | 251 play(); |
| 239 }, | 252 }, |
| 240 | 253 |
| 241 /** | 254 /** |
| 242 * Pauses the video. | 255 * Pauses the video. |
| 256 * @param {boolean=} opt_seeking True when seeking. False otherwise. |
| 243 */ | 257 */ |
| 244 pause: function() { | 258 pause: function(opt_seeking) { |
| 245 if (!this.castMedia_) | 259 if (!this.castMedia_) |
| 246 return; | 260 return; |
| 247 | 261 |
| 262 if (this.pauseInProgress_ || |
| 263 this.castMedia_.playerState === chrome.cast.media.PlayerState.PAUSED) { |
| 264 return; |
| 265 } |
| 266 |
| 267 var pauseRequest = new chrome.cast.media.PauseRequest(); |
| 268 pauseRequest.customData = {seeking: !!opt_seeking}; |
| 269 |
| 248 this.pauseInProgress_ = true; | 270 this.pauseInProgress_ = true; |
| 249 this.castMedia_.pause(null, | 271 this.castMedia_.pause( |
| 272 pauseRequest, |
| 250 function() { | 273 function() { |
| 251 this.pauseInProgress_ = false; | 274 this.pauseInProgress_ = false; |
| 252 }.wrap(this), | 275 }.wrap(this), |
| 253 function(error) { | 276 function(error) { |
| 254 this.pauseInProgress_ = false; | 277 this.pauseInProgress_ = false; |
| 255 this.onCastCommandError_(error); | 278 this.onCastCommandError_(error); |
| 256 }.wrap(this)); | 279 }.wrap(this)); |
| 257 }, | 280 }, |
| 258 | 281 |
| 259 /** | 282 /** |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 465 this.dispatchEvent(new Event('durationchange')); | 488 this.dispatchEvent(new Event('durationchange')); |
| 466 } | 489 } |
| 467 | 490 |
| 468 // Media is being unloaded. | 491 // Media is being unloaded. |
| 469 if (!alive) { | 492 if (!alive) { |
| 470 this.unloadMedia_(); | 493 this.unloadMedia_(); |
| 471 return; | 494 return; |
| 472 } | 495 } |
| 473 }, | 496 }, |
| 474 }; | 497 }; |
| OLD | NEW |