OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 * @fileoverview MediaControls class implements media playback controls | 8 * @fileoverview MediaControls class implements media playback controls |
9 * that exist outside of the audio/video HTML element. | 9 * that exist outside of the audio/video HTML element. |
10 */ | 10 */ |
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
483 */ | 483 */ |
484 MediaControls.prototype.restorePlayState = function() {}; | 484 MediaControls.prototype.restorePlayState = function() {}; |
485 | 485 |
486 /** | 486 /** |
487 * Encode current state into the page URL or the app state. | 487 * Encode current state into the page URL or the app state. |
488 */ | 488 */ |
489 MediaControls.prototype.encodeState = function() { | 489 MediaControls.prototype.encodeState = function() { |
490 if (!this.media_.duration) | 490 if (!this.media_.duration) |
491 return; | 491 return; |
492 | 492 |
493 window.appState.time = this.media_.currentTime; | 493 if (window.appState) { |
494 util.saveAppState(); | 494 window.appState.time = this.media_.currentTime; |
| 495 util.saveAppState(); |
| 496 } |
495 return; | 497 return; |
496 }; | 498 }; |
497 | 499 |
498 /** | 500 /** |
499 * Decode current state from the page URL or the app state. | 501 * Decode current state from the page URL or the app state. |
500 * @return {boolean} True if decode succeeded. | 502 * @return {boolean} True if decode succeeded. |
501 */ | 503 */ |
502 MediaControls.prototype.decodeState = function() { | 504 MediaControls.prototype.decodeState = function() { |
503 if (!('time' in window.appState)) | 505 if (!window.appState || !('time' in window.appState)) |
504 return false; | 506 return false; |
505 // There is no page reload for apps v2, only app restart. | 507 // There is no page reload for apps v2, only app restart. |
506 // Always restart in paused state. | 508 // Always restart in paused state. |
507 this.media_.currentTime = appState.time; | 509 this.media_.currentTime = window.appState.time; |
508 this.pause(); | 510 this.pause(); |
509 return true; | 511 return true; |
510 }; | 512 }; |
511 | 513 |
512 /** | 514 /** |
513 * Remove current state from the page URL or the app state. | 515 * Remove current state from the page URL or the app state. |
514 */ | 516 */ |
515 MediaControls.prototype.clearState = function() { | 517 MediaControls.prototype.clearState = function() { |
| 518 if (!window.appState) |
| 519 return; |
| 520 |
516 if ('time' in window.appState) | 521 if ('time' in window.appState) |
517 delete window.appState.time; | 522 delete window.appState.time; |
518 util.saveAppState(); | 523 util.saveAppState(); |
519 return; | 524 return; |
520 }; | 525 }; |
521 | 526 |
522 /** | 527 /** |
523 * Create a customized slider control. | 528 * Create a customized slider control. |
524 * | 529 * |
525 * @param {HTMLElement} container The containing div element. | 530 * @param {HTMLElement} container The containing div element. |
(...skipping 668 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1194 AudioControls.prototype.onAdvanceClick_ = function(forward) { | 1199 AudioControls.prototype.onAdvanceClick_ = function(forward) { |
1195 if (!forward && | 1200 if (!forward && |
1196 (this.getMedia().currentTime > AudioControls.TRACK_RESTART_THRESHOLD)) { | 1201 (this.getMedia().currentTime > AudioControls.TRACK_RESTART_THRESHOLD)) { |
1197 // We are far enough from the beginning of the current track. | 1202 // We are far enough from the beginning of the current track. |
1198 // Restart it instead of than skipping to the previous one. | 1203 // Restart it instead of than skipping to the previous one. |
1199 this.getMedia().currentTime = 0; | 1204 this.getMedia().currentTime = 0; |
1200 } else { | 1205 } else { |
1201 this.advanceTrack_(forward); | 1206 this.advanceTrack_(forward); |
1202 } | 1207 } |
1203 }; | 1208 }; |
OLD | NEW |