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

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

Issue 1176483002: AudioPlayer.app: Migrate to Polymer 1.0. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 months 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
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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 * 42 *
43 * @type {?boolean} 43 * @type {?boolean}
44 * @private 44 * @private
45 */ 45 */
46 this.isExpanded_ = null; // Initial value is null. It'll be set in load(). 46 this.isExpanded_ = null; // Initial value is null. It'll be set in load().
47 47
48 this.player_ = 48 this.player_ =
49 /** @type {AudioPlayerElement} */ (document.querySelector('audio-player')); 49 /** @type {AudioPlayerElement} */ (document.querySelector('audio-player'));
50 // TODO(yoshiki): Move tracks into the model. 50 // TODO(yoshiki): Move tracks into the model.
51 this.player_.tracks = []; 51 this.player_.tracks = [];
52 this.player_.model = this.model_; 52 this.model_.initialize(function() {
53 this.player_.model = this.model_;
54 if (this.player_.expanded)
55 this.onModelExpandedChanged(false, true);
yawano 2015/06/10 05:47:48 Can we remove this onModelExpanededChanged call if
fukino 2015/06/10 06:24:03 Done. Thank you for pointing this out!
56 }.bind(this));
53 57
54 // Run asynchronously after an event of model change is delivered. 58 // Run asynchronously after an event of model change is delivered.
55 setTimeout(function() { 59 setTimeout(function() {
56 this.errorString_ = ''; 60 this.errorString_ = '';
57 this.offlineString_ = ''; 61 this.offlineString_ = '';
58 chrome.fileManagerPrivate.getStrings(function(strings) { 62 chrome.fileManagerPrivate.getStrings(function(strings) {
59 container.ownerDocument.title = strings['AUDIO_PLAYER_TITLE']; 63 container.ownerDocument.title = strings['AUDIO_PLAYER_TITLE'];
60 this.errorString_ = strings['AUDIO_ERROR']; 64 this.errorString_ = strings['AUDIO_ERROR'];
61 this.offlineString_ = strings['AUDIO_OFFLINE']; 65 this.offlineString_ = strings['AUDIO_OFFLINE'];
62 AudioPlayer.TrackInfo.DEFAULT_ARTIST = 66 AudioPlayer.TrackInfo.DEFAULT_ARTIST =
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 */ 113 */
110 AudioPlayer.prototype.load = function(playlist) { 114 AudioPlayer.prototype.load = function(playlist) {
111 this.playlistGeneration_++; 115 this.playlistGeneration_++;
112 this.currentTrackIndex_ = -1; 116 this.currentTrackIndex_ = -1;
113 117
114 // Save the app state, in case of restart. Make a copy of the object, so the 118 // Save the app state, in case of restart. Make a copy of the object, so the
115 // playlist member is not changed after entries are resolved. 119 // playlist member is not changed after entries are resolved.
116 window.appState = JSON.parse(JSON.stringify(playlist)); // cloning 120 window.appState = JSON.parse(JSON.stringify(playlist)); // cloning
117 util.saveAppState(); 121 util.saveAppState();
118 122
119 this.isExpanded_ = this.model_.expanded; 123 this.isExpanded_ = this.player_.expanded;
120 124
121 // Resolving entries has to be done after the volume manager is initialized. 125 // Resolving entries has to be done after the volume manager is initialized.
122 this.volumeManager_.ensureInitialized(function() { 126 this.volumeManager_.ensureInitialized(function() {
123 util.URLsToEntries(playlist.items, function(entries) { 127 util.URLsToEntries(playlist.items, function(entries) {
124 this.entries_ = entries; 128 this.entries_ = entries;
125 129
126 var position = playlist.position || 0; 130 var position = playlist.position || 0;
127 var time = playlist.time || 0; 131 var time = playlist.time || 0;
128 132
129 if (this.entries_.length == 0) 133 if (this.entries_.length == 0)
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 * Selects a new track to play. 215 * Selects a new track to play.
212 * @param {number} newTrack New track number. 216 * @param {number} newTrack New track number.
213 * @param {number} time New playback position (in second). 217 * @param {number} time New playback position (in second).
214 * @private 218 * @private
215 */ 219 */
216 AudioPlayer.prototype.select_ = function(newTrack, time) { 220 AudioPlayer.prototype.select_ = function(newTrack, time) {
217 if (this.currentTrackIndex_ == newTrack) return; 221 if (this.currentTrackIndex_ == newTrack) return;
218 222
219 this.currentTrackIndex_ = newTrack; 223 this.currentTrackIndex_ = newTrack;
220 this.player_.currentTrackIndex = this.currentTrackIndex_; 224 this.player_.currentTrackIndex = this.currentTrackIndex_;
221 this.player_.audioController.time = time; 225 this.player_.time = time;
222 226
223 // Run asynchronously after an event of current track change is delivered. 227 // Run asynchronously after an event of current track change is delivered.
224 setTimeout(function() { 228 setTimeout(function() {
225 if (!window.appReopen) 229 if (!window.appReopen)
226 this.player_.audioElement.play(); 230 this.player_.audioElement.play();
227 231
228 window.appState.position = this.currentTrackIndex_; 232 window.appState.position = this.currentTrackIndex_;
229 window.appState.time = 0; 233 window.appState.time = 0;
230 util.saveAppState(); 234 util.saveAppState();
231 235
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 /** 281 /**
278 * Toggles the expanded mode when resizing. 282 * Toggles the expanded mode when resizing.
279 * 283 *
280 * @param {Event} event Resize event. 284 * @param {Event} event Resize event.
281 * @private 285 * @private
282 */ 286 */
283 AudioPlayer.prototype.onResize_ = function(event) { 287 AudioPlayer.prototype.onResize_ = function(event) {
284 if (!this.isExpanded_ && 288 if (!this.isExpanded_ &&
285 window.innerHeight >= AudioPlayer.EXPANDED_MODE_MIN_HEIGHT) { 289 window.innerHeight >= AudioPlayer.EXPANDED_MODE_MIN_HEIGHT) {
286 this.isExpanded_ = true; 290 this.isExpanded_ = true;
287 this.model_.expanded = true; 291 this.player_.expanded = true;
288 } else if (this.isExpanded_ && 292 } else if (this.isExpanded_ &&
289 window.innerHeight < AudioPlayer.EXPANDED_MODE_MIN_HEIGHT) { 293 window.innerHeight < AudioPlayer.EXPANDED_MODE_MIN_HEIGHT) {
290 this.isExpanded_ = false; 294 this.isExpanded_ = false;
291 this.model_.expanded = false; 295 this.player_.expanded = false;
292 } 296 }
293 }; 297 };
294 298
295 /** 299 /**
296 * Handles keydown event to open inspector with shortcut keys. 300 * Handles keydown event to open inspector with shortcut keys.
297 * 301 *
298 * @param {Event} event KeyDown event. 302 * @param {Event} event KeyDown event.
299 * @private 303 * @private
300 */ 304 */
301 AudioPlayer.prototype.onKeyDown_ = function(event) { 305 AudioPlayer.prototype.onKeyDown_ = function(event) {
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 util.saveAppState(); 380 util.saveAppState();
377 } 381 }
378 }; 382 };
379 383
380 /** 384 /**
381 * @private 385 * @private
382 */ 386 */
383 AudioPlayer.prototype.syncHeight_ = function() { 387 AudioPlayer.prototype.syncHeight_ = function() {
384 var targetHeight; 388 var targetHeight;
385 389
386 if (this.model_.expanded) { 390 if (this.player_.expanded) {
387 // Expanded. 391 // Expanded.
388 if (!this.lastExpandedHeight_ || 392 if (!this.lastExpandedHeight_ ||
389 this.lastExpandedHeight_ < AudioPlayer.EXPANDED_MODE_MIN_HEIGHT) { 393 this.lastExpandedHeight_ < AudioPlayer.EXPANDED_MODE_MIN_HEIGHT) {
390 var expandedListHeight = 394 var expandedListHeight =
391 Math.min(this.entries_.length, AudioPlayer.DEFAULT_EXPANDED_ITEMS) * 395 Math.min(this.entries_.length, AudioPlayer.DEFAULT_EXPANDED_ITEMS) *
392 AudioPlayer.TRACK_HEIGHT; 396 AudioPlayer.TRACK_HEIGHT;
393 targetHeight = AudioPlayer.CONTROLS_HEIGHT + expandedListHeight; 397 targetHeight = AudioPlayer.CONTROLS_HEIGHT + expandedListHeight;
394 this.lastExpandedHeight_ = targetHeight; 398 this.lastExpandedHeight_ = targetHeight;
395 } else { 399 } else {
396 targetHeight = this.lastExpandedHeight_; 400 targetHeight = this.lastExpandedHeight_;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 */ 453 */
450 AudioPlayer.TrackInfo.prototype.setMetadata = function( 454 AudioPlayer.TrackInfo.prototype.setMetadata = function(
451 metadata, error) { 455 metadata, error) {
452 // TODO(yoshiki): Handle error in better way. 456 // TODO(yoshiki): Handle error in better way.
453 // TODO(yoshiki): implement artwork (metadata.thumbnail) 457 // TODO(yoshiki): implement artwork (metadata.thumbnail)
454 this.title = metadata.mediaTitle || this.getDefaultTitle(); 458 this.title = metadata.mediaTitle || this.getDefaultTitle();
455 this.artist = error || metadata.mediaArtist || this.getDefaultArtist(); 459 this.artist = error || metadata.mediaArtist || this.getDefaultArtist();
456 }; 460 };
457 461
458 // Starts loading the audio player. 462 // Starts loading the audio player.
459 window.addEventListener('polymer-ready', function(e) { 463 window.addEventListener('DOMContentLoaded', function(e) {
460 AudioPlayer.load(); 464 AudioPlayer.load();
461 }); 465 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698