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

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: Added a comment. 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 * Here we loads up to 25 songs concurrently to cover the number of songs in
53 * an album in most cases. This number should not be too large so that the
54 * number of open file descriptors will not hit the system limit.
55 * @private {AsyncUtil.ConcurrentQueue}
56 */
57 this.loadMetadataQueue_ = new AsyncUtil.ConcurrentQueue(25);
58
50 // Restore the saved state from local storage, and update the local storage 59 // Restore the saved state from local storage, and update the local storage
51 // if the states are changed. 60 // if the states are changed.
52 var STORAGE_PREFIX = 'audioplayer-'; 61 var STORAGE_PREFIX = 'audioplayer-';
53 var KEYS_TO_SAVE_STATES = 62 var KEYS_TO_SAVE_STATES =
54 ['shuffle', 63 ['shuffle',
55 'repeat-mode', 64 'repeat-mode',
56 'volume', 65 'volume',
57 'playlist-expanded', 66 'playlist-expanded',
58 'track-info-expanded']; 67 'track-info-expanded'];
59 var storageKeys = KEYS_TO_SAVE_STATES.map(a => STORAGE_PREFIX + a); 68 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)); 218 }.bind(this));
210 }.bind(this)); 219 }.bind(this));
211 }; 220 };
212 221
213 /** 222 /**
214 * Loads metadata for a track. 223 * Loads metadata for a track.
215 * @param {number} track Track number. 224 * @param {number} track Track number.
216 * @private 225 * @private
217 */ 226 */
218 AudioPlayer.prototype.loadMetadata_ = function(track) { 227 AudioPlayer.prototype.loadMetadata_ = function(track) {
219 this.fetchMetadata_( 228 this.loadMetadataQueue_.run(function(callback) {
220 this.entries_[track], this.displayMetadata_.bind(this, track)); 229 this.fetchMetadata_(this.entries_[track], function(metadata) {
230 this.displayMetadata_(track, metadata);
231 callback();
232 }.bind(this));
233 }.bind(this));
221 }; 234 };
222 235
223 /** 236 /**
224 * Displays track's metadata. 237 * Displays track's metadata.
225 * @param {number} track Track number. 238 * @param {number} track Track number.
226 * @param {Object} metadata Metadata object. 239 * @param {Object} metadata Metadata object.
227 * @param {string=} opt_error Error message. 240 * @param {string=} opt_error Error message.
228 * @private 241 * @private
229 */ 242 */
230 AudioPlayer.prototype.displayMetadata_ = function(track, metadata, opt_error) { 243 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. 621 // TODO(yoshiki): Handle error in better way.
609 this.title = metadata.mediaTitle || this.getDefaultTitle(); 622 this.title = metadata.mediaTitle || this.getDefaultTitle();
610 this.artist = error || metadata.mediaArtist || this.getDefaultArtist(); 623 this.artist = error || metadata.mediaArtist || this.getDefaultArtist();
611 this.artworkUrl = metadata.contentThumbnailUrl || ""; 624 this.artworkUrl = metadata.contentThumbnailUrl || "";
612 }; 625 };
613 626
614 // Starts loading the audio player. 627 // Starts loading the audio player.
615 window.addEventListener('DOMContentLoaded', function(e) { 628 window.addEventListener('DOMContentLoaded', function(e) {
616 AudioPlayer.load(); 629 AudioPlayer.load();
617 }); 630 });
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