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

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

Issue 936243004: Files.app: Start to use new metadata model in Audio Player. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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 * @const 8 * @const
9 */ 9 */
10 ContentProvider.WORKER_SCRIPT = '/js/metadata_worker.js'; 10 ContentMetadataProvider.WORKER_SCRIPT = '/js/metadata_worker.js';
11 11
12 /** 12 /**
13 * @param {HTMLElement} container Container element. 13 * @param {HTMLElement} container Container element.
14 * @constructor 14 * @constructor
15 */ 15 */
16 function AudioPlayer(container) { 16 function AudioPlayer(container) {
17 this.container_ = container; 17 this.container_ = container;
18 this.volumeManager_ = new VolumeManagerWrapper( 18 this.volumeManager_ = new VolumeManagerWrapper(
19 VolumeManagerWrapper.DriveEnabledStatus.DRIVE_ENABLED); 19 VolumeManagerWrapper.DriveEnabledStatus.DRIVE_ENABLED);
20 this.metadataCache_ = MetadataCache.createFull(this.volumeManager_); 20 this.fileSystemMetadata_ = FileSystemMetadata.create(
21 new MetadataProviderCache(), this.volumeManager_);
21 this.selectedEntry_ = null; 22 this.selectedEntry_ = null;
22 23
23 this.model_ = new AudioPlayerModel(); 24 this.model_ = new AudioPlayerModel();
24 var observer = new PathObserver(this.model_, 'expanded'); 25 var observer = new PathObserver(this.model_, 'expanded');
25 observer.open(function(newValue, oldValue) { 26 observer.open(function(newValue, oldValue) {
26 // Inverse arguments intentionally to match the Polymer way. 27 // Inverse arguments intentionally to match the Polymer way.
27 this.onModelExpandedChanged(oldValue, newValue); 28 this.onModelExpandedChanged(oldValue, newValue);
28 }.bind(this)); 29 }.bind(this));
29 30
30 this.entries_ = []; 31 this.entries_ = [];
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 // Show the window after DOM is processed. 66 // Show the window after DOM is processed.
66 var currentWindow = chrome.app.window.current(); 67 var currentWindow = chrome.app.window.current();
67 if (currentWindow) 68 if (currentWindow)
68 setTimeout(currentWindow.show.bind(currentWindow), 0); 69 setTimeout(currentWindow.show.bind(currentWindow), 0);
69 } 70 }
70 71
71 /** 72 /**
72 * Initial load method (static). 73 * Initial load method (static).
73 */ 74 */
74 AudioPlayer.load = function() { 75 AudioPlayer.load = function() {
75 document.ondragstart = function(e) { e.preventDefault() }; 76 document.ondragstart = function(e) { e.preventDefault(); };
76 77
77 AudioPlayer.instance = 78 AudioPlayer.instance =
78 new AudioPlayer(document.querySelector('.audio-player')); 79 new AudioPlayer(document.querySelector('.audio-player'));
79 80
80 reload(); 81 reload();
81 }; 82 };
82 83
83 /** 84 /**
84 * Unloads the player. 85 * Unloads the player.
85 */ 86 */
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 this.selectedEntry_ = entry; 231 this.selectedEntry_ = entry;
231 }.bind(this)); 232 }.bind(this));
232 }; 233 };
233 234
234 /** 235 /**
235 * @param {FileEntry} entry Track file entry. 236 * @param {FileEntry} entry Track file entry.
236 * @param {function(object)} callback Callback. 237 * @param {function(object)} callback Callback.
237 * @private 238 * @private
238 */ 239 */
239 AudioPlayer.prototype.fetchMetadata_ = function(entry, callback) { 240 AudioPlayer.prototype.fetchMetadata_ = function(entry, callback) {
240 this.metadataCache_.getOne(entry, 'thumbnail|media|external', 241 this.fileSystemMetadata_.get(
242 [entry], ['mediaTitle', 'mediaArtist', 'present']).then(
241 function(generation, metadata) { 243 function(generation, metadata) {
242 // Do nothing if another load happened since the metadata request. 244 // Do nothing if another load happened since the metadata request.
243 if (this.playlistGeneration_ == generation) 245 if (this.playlistGeneration_ == generation)
244 callback(metadata); 246 callback(metadata[0]);
245 }.bind(this, this.playlistGeneration_)); 247 }.bind(this, this.playlistGeneration_));
246 }; 248 };
247 249
248 /** 250 /**
249 * Media error handler. 251 * Media error handler.
250 * @private 252 * @private
251 */ 253 */
252 AudioPlayer.prototype.onError_ = function() { 254 AudioPlayer.prototype.onError_ = function() {
253 var track = this.currentTrackIndex_; 255 var track = this.currentTrackIndex_;
254 256
255 this.invalidTracks_[track] = true; 257 this.invalidTracks_[track] = true;
256 258
257 this.fetchMetadata_( 259 this.fetchMetadata_(
258 this.entries_[track], 260 this.entries_[track],
259 function(metadata) { 261 function(metadata) {
260 var error = (!navigator.onLine && !metadata.external.present) ? 262 var error = (!navigator.onLine && !metadata.present) ?
261 this.offlineString_ : this.errorString_; 263 this.offlineString_ : this.errorString_;
262 this.displayMetadata_(track, metadata, error); 264 this.displayMetadata_(track, metadata, error);
263 this.scheduleAutoAdvance_(); 265 this.scheduleAutoAdvance_();
264 }.bind(this)); 266 }.bind(this));
265 }; 267 };
266 268
267 /** 269 /**
268 * Toggles the expanded mode when resizing. 270 * Toggles the expanded mode when resizing.
269 * 271 *
270 * @param {Event} event Resize event. 272 * @param {Event} event Resize event.
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 this.artist = this.getDefaultArtist(); 384 this.artist = this.getDefaultArtist();
383 385
384 // TODO(yoshiki): implement artwork. 386 // TODO(yoshiki): implement artwork.
385 this.artwork = null; 387 this.artwork = null;
386 this.active = false; 388 this.active = false;
387 }; 389 };
388 390
389 /** 391 /**
390 * @return {HTMLDivElement} The wrapper element for the track. 392 * @return {HTMLDivElement} The wrapper element for the track.
391 */ 393 */
392 AudioPlayer.TrackInfo.prototype.getBox = function() { return this.box_ }; 394 AudioPlayer.TrackInfo.prototype.getBox = function() { return this.box_; };
393 395
394 /** 396 /**
395 * @return {string} Default track title (file name extracted from the url). 397 * @return {string} Default track title (file name extracted from the url).
396 */ 398 */
397 AudioPlayer.TrackInfo.prototype.getDefaultTitle = function() { 399 AudioPlayer.TrackInfo.prototype.getDefaultTitle = function() {
398 var title = this.url.split('/').pop(); 400 var title = this.url.split('/').pop();
399 var dotIndex = title.lastIndexOf('.'); 401 var dotIndex = title.lastIndexOf('.');
400 if (dotIndex >= 0) title = title.substr(0, dotIndex); 402 if (dotIndex >= 0) title = title.substr(0, dotIndex);
401 title = decodeURIComponent(title); 403 title = decodeURIComponent(title);
402 return title; 404 return title;
(...skipping 12 matching lines...) Expand all
415 }; 417 };
416 418
417 /** 419 /**
418 * @param {Object} metadata The metadata object. 420 * @param {Object} metadata The metadata object.
419 * @param {string} error Error string. 421 * @param {string} error Error string.
420 */ 422 */
421 AudioPlayer.TrackInfo.prototype.setMetadata = function( 423 AudioPlayer.TrackInfo.prototype.setMetadata = function(
422 metadata, error) { 424 metadata, error) {
423 // TODO(yoshiki): Handle error in better way. 425 // TODO(yoshiki): Handle error in better way.
424 // TODO(yoshiki): implement artwork (metadata.thumbnail) 426 // TODO(yoshiki): implement artwork (metadata.thumbnail)
425 this.title = (metadata.media && metadata.media.title) || 427 this.title = metadata.mediaTitle || this.getDefaultTitle();
426 this.getDefaultTitle(); 428 this.artist = error || metadata.mediaArtist || this.getDefaultArtist();
427 this.artist = error ||
428 (metadata.media && metadata.media.artist) || this.getDefaultArtist();
429 }; 429 };
430 430
431 // Starts loading the audio player. 431 // Starts loading the audio player.
432 window.addEventListener('polymer-ready', function(e) { 432 window.addEventListener('polymer-ready', function(e) {
433 AudioPlayer.load(); 433 AudioPlayer.load();
434 }); 434 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698