Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(68)

Side by Side Diff: ui/file_manager/video_player/js/media_controls.js

Issue 2535713003: Remember the last volume level in Video Player. (Closed)
Patch Set: Use lowerCamelCase for local variable. Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 /** 5 /**
6 * @fileoverview MediaControls class implements media playback controls 6 * @fileoverview MediaControls class implements media playback controls
7 * that exist outside of the audio/video HTML element. 7 * that exist outside of the audio/video HTML element.
8 */ 8 */
9 9
10 /** 10 /**
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 // not known to be bounded yet. In such cases, we should hide duration. 482 // not known to be bounded yet. In such cases, we should hide duration.
483 this.currentTime_.textContent = MediaControls.formatTime_(current); 483 this.currentTime_.textContent = MediaControls.formatTime_(current);
484 this.currentTimeSpacer_.textContent = MediaControls.formatTime_(current); 484 this.currentTimeSpacer_.textContent = MediaControls.formatTime_(current);
485 } 485 }
486 }; 486 };
487 487
488 /* 488 /*
489 * Volume controls 489 * Volume controls
490 */ 490 */
491 491
492 MediaControls.STORAGE_PREFIX = 'videoplayer-';
493
494 MediaControls.KEY_NORMALIZED_VOLUME =
495 MediaControls.STORAGE_PREFIX + 'normalized-volume';
496
492 /** 497 /**
493 * @param {HTMLElement=} opt_parent Parent element for the controls. 498 * @param {HTMLElement=} opt_parent Parent element for the controls.
494 */ 499 */
495 MediaControls.prototype.initVolumeControls = function(opt_parent) { 500 MediaControls.prototype.initVolumeControls = function(opt_parent) {
496 var volumeControls = this.createControl('volume-controls', opt_parent); 501 var volumeControls = this.createControl('volume-controls', opt_parent);
497 502
498 this.soundButton_ = this.createButton('sound media-control', 503 this.soundButton_ = this.createButton('sound media-control',
499 this.onSoundButtonClick_.bind(this), volumeControls); 504 this.onSoundButtonClick_.bind(this), volumeControls);
500 this.soundButton_.setAttribute('level', 3); // max level. 505 this.soundButton_.setAttribute('level', 3); // max level.
501 this.soundButton_.setAttribute('aria-label', 506 this.soundButton_.setAttribute('aria-label',
502 str('MEDIA_PLAYER_MUTE_BUTTON_LABEL')); 507 str('MEDIA_PLAYER_MUTE_BUTTON_LABEL'));
503 508
504 this.volume_ = /** @type {!PaperSliderElement} */ ( 509 this.volume_ = /** @type {!PaperSliderElement} */ (
505 document.createElement('paper-slider')); 510 document.createElement('paper-slider'));
506 this.volume_.classList.add('volume', 'media-control'); 511 this.volume_.classList.add('volume', 'media-control');
507 this.volume_.setAttribute('aria-label', 512 this.volume_.setAttribute('aria-label',
508 str('MEDIA_PLAYER_VOLUME_SLIDER_LABEL')); 513 str('MEDIA_PLAYER_VOLUME_SLIDER_LABEL'));
509 this.volume_.addEventListener('change', function(event) { 514 this.volume_.addEventListener('change', function(event) {
510 this.onVolumeChange_(this.volume_.ratio); 515 this.onVolumeChange_(this.volume_.ratio);
511 }.bind(this)); 516 }.bind(this));
512 this.volume_.addEventListener('immediate-value-change', function(event) { 517 this.volume_.addEventListener('immediate-value-change', function(event) {
513 this.onVolumeDrag_(); 518 this.onVolumeDrag_();
514 }.bind(this)); 519 }.bind(this));
515 this.volume_.value = this.volume_.max; 520 this.loadVolumeControlState();
516 volumeControls.appendChild(this.volume_); 521 volumeControls.appendChild(this.volume_);
517 }; 522 };
518 523
524 MediaControls.prototype.loadVolumeControlState = function() {
525 chrome.storage.local.get([MediaControls.KEY_NORMALIZED_VOLUME],
526 function(retrieved) {
527 var normalizedVolume = (MediaControls.KEY_NORMALIZED_VOLUME
528 in retrieved)
529 ? retrieved[MediaControls.KEY_NORMALIZED_VOLUME] : 1;
530 this.volume_.value = this.volume_.max * normalizedVolume;
531 }.bind(this));
532 };
533
534 MediaControls.prototype.saveVolumeControlState = function() {
535 var valuesToStore = {};
536 valuesToStore[MediaControls.KEY_NORMALIZED_VOLUME] = this.media_.volume;
537 chrome.storage.local.set(valuesToStore);
538 };
539
519 /** 540 /**
520 * Click handler for the sound level button. 541 * Click handler for the sound level button.
521 * @private 542 * @private
522 */ 543 */
523 MediaControls.prototype.onSoundButtonClick_ = function() { 544 MediaControls.prototype.onSoundButtonClick_ = function() {
524 if (this.media_.volume == 0) { 545 if (this.media_.volume == 0) {
525 this.volume_.value = (this.savedVolume_ || 1) * this.volume_.max; 546 this.volume_.value = (this.savedVolume_ || 1) * this.volume_.max;
526 this.soundButton_.setAttribute('aria-label', 547 this.soundButton_.setAttribute('aria-label',
527 str('MEDIA_PLAYER_MUTE_BUTTON_LABEL')); 548 str('MEDIA_PLAYER_MUTE_BUTTON_LABEL'));
528 } else { 549 } else {
(...skipping 23 matching lines...) Expand all
552 */ 573 */
553 MediaControls.prototype.onVolumeChange_ = function(value) { 574 MediaControls.prototype.onVolumeChange_ = function(value) {
554 if (!this.media_) 575 if (!this.media_)
555 return; // Media is detached. 576 return; // Media is detached.
556 577
557 this.media_.volume = value; 578 this.media_.volume = value;
558 this.soundButton_.setAttribute('level', MediaControls.getVolumeLevel_(value)); 579 this.soundButton_.setAttribute('level', MediaControls.getVolumeLevel_(value));
559 this.soundButton_.setAttribute('aria-label', 580 this.soundButton_.setAttribute('aria-label',
560 value === 0 ? str('MEDIA_PLAYER_UNMUTE_BUTTON_LABEL') 581 value === 0 ? str('MEDIA_PLAYER_UNMUTE_BUTTON_LABEL')
561 : str('MEDIA_PLAYER_MUTE_BUTTON_LABEL')); 582 : str('MEDIA_PLAYER_MUTE_BUTTON_LABEL'));
583 this.saveVolumeControlState();
562 }; 584 };
563 585
564 /** 586 /**
565 * @private 587 * @private
566 */ 588 */
567 MediaControls.prototype.onVolumeDrag_ = function() { 589 MediaControls.prototype.onVolumeDrag_ = function() {
568 if (this.media_.volume !== 0) { 590 if (this.media_.volume !== 0) {
569 this.savedVolume_ = this.media_.volume; 591 this.savedVolume_ = this.media_.volume;
570 } 592 }
571 }; 593 };
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after
1093 this.fullscreenButton_.setAttribute('aria-label', 1115 this.fullscreenButton_.setAttribute('aria-label',
1094 fullscreen ? str('VIDEO_PLAYER_EXIT_FULL_SCREEN_BUTTON_LABEL') 1116 fullscreen ? str('VIDEO_PLAYER_EXIT_FULL_SCREEN_BUTTON_LABEL')
1095 : str('VIDEO_PLAYER_FULL_SCREEN_BUTTON_LABEL'));; 1117 : str('VIDEO_PLAYER_FULL_SCREEN_BUTTON_LABEL'));;
1096 // If the fullscreen button has focus on entering fullscreen mode, reset the 1118 // If the fullscreen button has focus on entering fullscreen mode, reset the
1097 // focus to make the spacebar toggle play/pause state. This is the 1119 // focus to make the spacebar toggle play/pause state. This is the
1098 // consistent behavior with Youtube Web UI. 1120 // consistent behavior with Youtube Web UI.
1099 if (fullscreen) 1121 if (fullscreen)
1100 this.fullscreenButton_.blur(); 1122 this.fullscreenButton_.blur();
1101 } 1123 }
1102 }; 1124 };
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698