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

Side by Side Diff: ui/file_manager/audio_player/js/audio_player.js

Issue 2456153002: Audio player: Throttle concurrent loading of audio metadata. (Closed)
Patch Set: 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 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 * Overrided metadata worker's path. 6 * Overrided metadata worker's path.
7 * @type {string} 7 * @type {string}
8 */ 8 */
9 ContentMetadataProvider.WORKER_SCRIPT = '/js/metadata_worker.js'; 9 ContentMetadataProvider.WORKER_SCRIPT = '/js/metadata_worker.js';
10 10
(...skipping 29 matching lines...) Expand all
40 * @type {?boolean} 40 * @type {?boolean}
41 * @private 41 * @private
42 */ 42 */
43 // Initial value is null. It'll be set in load(). 43 // Initial value is null. It'll be set in load().
44 this.isTrackInfoExpanded_ = null; 44 this.isTrackInfoExpanded_ = null;
45 45
46 this.player_ = 46 this.player_ =
47 /** @type {AudioPlayerElement} */ (document.querySelector('audio-player')); 47 /** @type {AudioPlayerElement} */ (document.querySelector('audio-player'));
48 this.player_.tracks = []; 48 this.player_.tracks = [];
49 49
50 /**
51 * Queue to throttle concurrent reading of audio file metadata.
52 * @private {AsyncUtil.ConcurrentQueue}
53 */
54 this.loadMetadataQueue_ = new AsyncUtil.ConcurrentQueue(25);
oka 2016/10/28 07:10:18 Could you explain why 25 is chosen?
fukino 2016/10/28 09:31:51 I elaborated it a bit more.
55
50 // Restore the saved state from local storage, and update the local storage 56 // Restore the saved state from local storage, and update the local storage
51 // if the states are changed. 57 // if the states are changed.
52 var STORAGE_PREFIX = 'audioplayer-'; 58 var STORAGE_PREFIX = 'audioplayer-';
53 var KEYS_TO_SAVE_STATES = 59 var KEYS_TO_SAVE_STATES =
54 ['shuffle', 60 ['shuffle',
55 'repeat-mode', 61 'repeat-mode',
56 'volume', 62 'volume',
57 'playlist-expanded', 63 'playlist-expanded',
58 'track-info-expanded']; 64 'track-info-expanded'];
59 var storageKeys = KEYS_TO_SAVE_STATES.map(a => STORAGE_PREFIX + a); 65 var storageKeys = KEYS_TO_SAVE_STATES.map(a => STORAGE_PREFIX + a);
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 }.bind(this)); 215 }.bind(this));
210 }.bind(this)); 216 }.bind(this));
211 }; 217 };
212 218
213 /** 219 /**
214 * Loads metadata for a track. 220 * Loads metadata for a track.
215 * @param {number} track Track number. 221 * @param {number} track Track number.
216 * @private 222 * @private
217 */ 223 */
218 AudioPlayer.prototype.loadMetadata_ = function(track) { 224 AudioPlayer.prototype.loadMetadata_ = function(track) {
219 this.fetchMetadata_( 225 this.loadMetadataQueue_.run(function(trackIndex, callback) {
oka 2016/10/28 07:10:18 fetchMetadata_ looks like more appropriate place t
fukino 2016/10/28 09:31:51 I think loadMetadata_ is better. We want to thrott
220 this.entries_[track], this.displayMetadata_.bind(this, track)); 226 this.fetchMetadata_(this.entries_[trackIndex], function(metadata) {
227 this.displayMetadata_(trackIndex, metadata);
228 callback();
229 }.bind(this));
230 }.bind(this, track));
oka 2016/10/28 07:13:43 I wonder if binding |track| is needed. Can't you u
fukino 2016/10/28 09:31:51 You're right. Thanks!
221 }; 231 };
222 232
223 /** 233 /**
224 * Displays track's metadata. 234 * Displays track's metadata.
225 * @param {number} track Track number. 235 * @param {number} track Track number.
226 * @param {Object} metadata Metadata object. 236 * @param {Object} metadata Metadata object.
227 * @param {string=} opt_error Error message. 237 * @param {string=} opt_error Error message.
228 * @private 238 * @private
229 */ 239 */
230 AudioPlayer.prototype.displayMetadata_ = function(track, metadata, opt_error) { 240 AudioPlayer.prototype.displayMetadata_ = function(track, metadata, opt_error) {
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after
608 // TODO(yoshiki): Handle error in better way. 618 // TODO(yoshiki): Handle error in better way.
609 this.title = metadata.mediaTitle || this.getDefaultTitle(); 619 this.title = metadata.mediaTitle || this.getDefaultTitle();
610 this.artist = error || metadata.mediaArtist || this.getDefaultArtist(); 620 this.artist = error || metadata.mediaArtist || this.getDefaultArtist();
611 this.artworkUrl = metadata.contentThumbnailUrl || ""; 621 this.artworkUrl = metadata.contentThumbnailUrl || "";
612 }; 622 };
613 623
614 // Starts loading the audio player. 624 // Starts loading the audio player.
615 window.addEventListener('DOMContentLoaded', function(e) { 625 window.addEventListener('DOMContentLoaded', function(e) {
616 AudioPlayer.load(); 626 AudioPlayer.load();
617 }); 627 });
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