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

Unified Diff: ui/file_manager/video_player/js/media_controls.js

Issue 2535713003: Remember the last volume level in Video Player. (Closed)
Patch Set: Move the constants for volume control to its relevant section. Created 4 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/file_manager/video_player/js/media_controls.js
diff --git a/ui/file_manager/video_player/js/media_controls.js b/ui/file_manager/video_player/js/media_controls.js
index a2b44eb160d9e17ab3ce523e4c8e10ae94bce0ca..f5d456cf40e84934f31e5ec6d5c74885db623f32 100644
--- a/ui/file_manager/video_player/js/media_controls.js
+++ b/ui/file_manager/video_player/js/media_controls.js
@@ -489,6 +489,10 @@ MediaControls.prototype.updateTimeLabel_ = function(current, opt_duration) {
* Volume controls
*/
+MediaControls.STORAGE_PREFIX = 'videoplayer-';
+
+MediaControls.KEY_VOLUME = MediaControls.STORAGE_PREFIX + 'volume';
+
/**
* @param {HTMLElement=} opt_parent Parent element for the controls.
*/
@@ -512,10 +516,24 @@ MediaControls.prototype.initVolumeControls = function(opt_parent) {
this.volume_.addEventListener('immediate-value-change', function(event) {
this.onVolumeDrag_();
}.bind(this));
- this.volume_.value = this.volume_.max;
+ this.loadVolumeControlState();
volumeControls.appendChild(this.volume_);
};
+MediaControls.prototype.loadVolumeControlState = function() {
+ chrome.storage.local.get([MediaControls.KEY_VOLUME], function(retrieved) {
+ var volume = (MediaControls.KEY_VOLUME in retrieved)
+ ? retrieved[MediaControls.KEY_VOLUME] : 1;
oka 2016/11/29 05:58:41 retrieved[MediaControls.KEY_VOLUME] || 1; is commo
yamaguchi 2016/11/29 06:51:32 The stored volume can be 0 when muted or the slide
oka 2016/11/29 07:13:57 Ah. Sorry.
+ this.volume_.value = this.volume_.max * volume;
+ }.bind(this));
+};
+
+MediaControls.prototype.saveVolumeControlState = function() {
+ var valuesToStore = {};
+ valuesToStore[MediaControls.KEY_VOLUME] = this.media_.volume;
oka 2016/11/29 05:58:41 Optional: media_.volume actually means the ratio o
yamaguchi 2016/11/29 06:51:32 Added "normalized" to those symbol names. I also t
+ chrome.storage.local.set(valuesToStore, function() {});
oka 2016/11/29 05:58:41 Remove the callback, which is optional.
yamaguchi 2016/11/29 06:51:32 Done.
+};
+
/**
* Click handler for the sound level button.
* @private
@@ -559,6 +577,7 @@ MediaControls.prototype.onVolumeChange_ = function(value) {
this.soundButton_.setAttribute('aria-label',
value === 0 ? str('MEDIA_PLAYER_UNMUTE_BUTTON_LABEL')
: str('MEDIA_PLAYER_MUTE_BUTTON_LABEL'));
+ this.saveVolumeControlState();
};
/**
« 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