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

Side by Side Diff: chrome/browser/resources/file_manager/js/media/audio_player.js

Issue 10384155: [filemanager] Content metadata moved to the cache. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Bug Created 8 years, 7 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 | Annotate | Revision Log
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 document.addEventListener('DOMContentLoaded', function() { 5 document.addEventListener('DOMContentLoaded', function() {
6 // Test harness sets the search string to prevent the automatic load. 6 // Test harness sets the search string to prevent the automatic load.
7 // It calls AudioPlayer.load() explicitly after initializing 7 // It calls AudioPlayer.load() explicitly after initializing
8 // the |chrome| variable with an appropriate mock object. 8 // the |chrome| variable with an appropriate mock object.
9 if (!document.location.search) { 9 if (!document.location.search) {
10 AudioPlayer.load(); 10 AudioPlayer.load();
11 } 11 }
12 }); 12 });
13 13
14 /** 14 /**
15 * @param {HTMLElement} container 15 * @param {HTMLElement} container
16 * @param {string} filesystemRootURL 16 * @param {string} filesystemRootURL
17 * @constructor 17 * @constructor
18 */ 18 */
19 function AudioPlayer(container, filesystemRootURL) { 19 function AudioPlayer(container, filesystemRootURL) {
20 this.container_ = container; 20 this.container_ = container;
21 this.metadataProvider_ = new MetadataProvider(filesystemRootURL); 21 this.metadataCache_ = MetadataCache.createFull();
22 this.currentTrack_ = -1; 22 this.currentTrack_ = -1;
23 this.playlistGeneration_ = 0; 23 this.playlistGeneration_ = 0;
24 24
25 this.container_.classList.add('collapsed'); 25 this.container_.classList.add('collapsed');
26 26
27 function createChild(opt_className, opt_tag) { 27 function createChild(opt_className, opt_tag) {
28 var child = container.ownerDocument.createElement(opt_tag || 'div'); 28 var child = container.ownerDocument.createElement(opt_tag || 'div');
29 if (opt_className) 29 if (opt_className)
30 child.className = opt_className; 30 child.className = opt_className;
31 container.appendChild(child); 31 container.appendChild(child);
(...skipping 13 matching lines...) Expand all
45 'click', this.onExpandCollapse_.bind(this)); 45 'click', this.onExpandCollapse_.bind(this));
46 46
47 this.audioControls_ = new AudioControls( 47 this.audioControls_ = new AudioControls(
48 createChild(), this.advance_.bind(this), this.onError_.bind(this)); 48 createChild(), this.advance_.bind(this), this.onError_.bind(this));
49 49
50 this.audioControls_.attachMedia(createChild('', 'audio')); 50 this.audioControls_.attachMedia(createChild('', 'audio'));
51 51
52 chrome.fileBrowserPrivate.getStrings(function(strings) { 52 chrome.fileBrowserPrivate.getStrings(function(strings) {
53 container.ownerDocument.title = strings['AUDIO_PLAYER_TITLE']; 53 container.ownerDocument.title = strings['AUDIO_PLAYER_TITLE'];
54 this.errorString_ = strings['AUDIO_ERROR']; 54 this.errorString_ = strings['AUDIO_ERROR'];
55 AudioPlayer.TrackInfo.DEFAULT_ARTIST =
56 strings['AUDIO_PLAYER_DEFAULT_ARTIST'];
55 }.bind(this)); 57 }.bind(this));
56 } 58 }
57 59
58 AudioPlayer.load = function() { 60 AudioPlayer.load = function() {
59 document.ondragstart = function(e) { e.preventDefault() }; 61 document.ondragstart = function(e) { e.preventDefault() };
60 document.oncontextmenu = function(e) { e.preventDefault(); }; 62 document.oncontextmenu = function(e) { e.preventDefault(); };
61 63
62 chrome.fileBrowserPrivate.requestLocalFileSystem(function(filesystem) { 64 chrome.fileBrowserPrivate.requestLocalFileSystem(function(filesystem) {
63 var player = new AudioPlayer(document.querySelector('.audio-player'), 65 var player = new AudioPlayer(document.querySelector('.audio-player'),
64 filesystem.root.toURL()); 66 filesystem.root.toURL());
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 this.changeSelectionInList_(this.currentTrack_, newTrack); 135 this.changeSelectionInList_(this.currentTrack_, newTrack);
134 this.changeSelectionInStack_(this.currentTrack_, newTrack); 136 this.changeSelectionInStack_(this.currentTrack_, newTrack);
135 137
136 this.currentTrack_ = newTrack; 138 this.currentTrack_ = newTrack;
137 this.scrollToCurrent_(false); 139 this.scrollToCurrent_(false);
138 140
139 var url = this.urls_[this.currentTrack_]; 141 var url = this.urls_[this.currentTrack_];
140 this.fetchMetadata_(url, function(metadata) { 142 this.fetchMetadata_(url, function(metadata) {
141 var media = this.audioControls_.getMedia(); 143 var media = this.audioControls_.getMedia();
142 // Do not try no stream when offline. 144 // Do not try no stream when offline.
143 media.src = (navigator.onLine && metadata.streamingURL) || url; 145 media.src =
146 (navigator.onLine && metadata.streaming && metadata.streaming.url) ||
147 url;
144 media.load(); 148 media.load();
145 this.audioControls_.play(); 149 this.audioControls_.play();
146 }.bind(this)); 150 }.bind(this));
147 }; 151 };
148 152
149 AudioPlayer.prototype.fetchMetadata_ = function(url, callback) { 153 AudioPlayer.prototype.fetchMetadata_ = function(url, callback) {
150 this.metadataProvider_.fetch( 154 this.metadataCache_.get(url, 'thumbnail|media|streaming',
151 url,
152 function(generation, metadata) { 155 function(generation, metadata) {
153 // Do nothing if another load happened since the metadata request. 156 // Do nothing if another load happened since the metadata request.
154 if (this.playlistGeneration_ == generation) 157 if (this.playlistGeneration_ == generation)
155 callback(metadata); 158 callback(metadata);
156 }.bind(this, this.playlistGeneration_)); 159 }.bind(this, this.playlistGeneration_));
157 }; 160 };
158 161
159 AudioPlayer.prototype.changeSelectionInList_ = function(oldTrack, newTrack) { 162 AudioPlayer.prototype.changeSelectionInList_ = function(oldTrack, newTrack) {
160 this.trackListItems_[newTrack].getBox().classList.add('selected'); 163 this.trackListItems_[newTrack].getBox().classList.add('selected');
161 164
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 216
214 AudioPlayer.prototype.onError_ = function() { 217 AudioPlayer.prototype.onError_ = function() {
215 var track = this.currentTrack_; 218 var track = this.currentTrack_;
216 219
217 this.invalidTracks_[track] = true; 220 this.invalidTracks_[track] = true;
218 221
219 this.fetchMetadata_( 222 this.fetchMetadata_(
220 this.urls_[track], 223 this.urls_[track],
221 function(metadata) { 224 function(metadata) {
222 metadata.error = true; 225 metadata.error = true;
223 metadata.artist = this.errorString_; 226 metadata.media = { artist: this.errorString_ };
224 this.displayMetadata_(track, metadata); 227 this.displayMetadata_(track, metadata);
225 this.scheduleAutoAdvance_(); 228 this.scheduleAutoAdvance_();
226 }.bind(this)); 229 }.bind(this));
227 }; 230 };
228 231
229 AudioPlayer.prototype.scheduleAutoAdvance_ = function() { 232 AudioPlayer.prototype.scheduleAutoAdvance_ = function() {
230 this.cancelAutoAdvance_(); 233 this.cancelAutoAdvance_();
231 this.autoAdvanceTimer_ = setTimeout( 234 this.autoAdvanceTimer_ = setTimeout(
232 function() { 235 function() {
233 this.autoAdvanceTimer_ = null; 236 this.autoAdvanceTimer_ = null;
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 315
313 AudioPlayer.TrackInfo.prototype.getBox = function() { return this.box_ }; 316 AudioPlayer.TrackInfo.prototype.getBox = function() { return this.box_ };
314 317
315 AudioPlayer.TrackInfo.prototype.getDefaultTitle = function() { 318 AudioPlayer.TrackInfo.prototype.getDefaultTitle = function() {
316 var title = this.url_.split('/').pop(); 319 var title = this.url_.split('/').pop();
317 var dotIndex = title.lastIndexOf('.'); 320 var dotIndex = title.lastIndexOf('.');
318 if (dotIndex >= 0) title = title.substr(0, dotIndex); 321 if (dotIndex >= 0) title = title.substr(0, dotIndex);
319 return title; 322 return title;
320 }; 323 };
321 324
325 AudioPlayer.TrackInfo.DEFAULT_ARTIST = 'Unknown Artist';
326
322 AudioPlayer.TrackInfo.prototype.getDefaultArtist = function() { 327 AudioPlayer.TrackInfo.prototype.getDefaultArtist = function() {
323 return 'Unknown Artist'; // TODO(kaznacheev): i18n 328 return AudioPlayer.TrackInfo.DEFAULT_ARTIST;
324 }; 329 };
325 330
326 /** 331 /**
327 * @param {Object} metadata The metadata object 332 * @param {Object} metadata The metadata object.
328 * @param {HTMLElement} container The container for the tracks. 333 * @param {HTMLElement} container The container for the tracks.
329 */ 334 */
330 AudioPlayer.TrackInfo.prototype.setMetadata = function(metadata, container) { 335 AudioPlayer.TrackInfo.prototype.setMetadata = function(metadata, container) {
331 if (metadata.error) { 336 if (metadata.error) {
332 this.art_.classList.add('blank'); 337 this.art_.classList.add('blank');
333 this.art_.classList.add('error'); 338 this.art_.classList.add('error');
334 container.classList.remove('noart'); 339 container.classList.remove('noart');
335 } else if (metadata.thumbnailURL) { 340 } else if (metadata.thumbnail && metadata.thumbnail.url) {
336 this.img_.onload = function() { 341 this.img_.onload = function() {
337 // Only display the image if the thumbnail loaded successfully. 342 // Only display the image if the thumbnail loaded successfully.
338 this.art_.classList.remove('blank'); 343 this.art_.classList.remove('blank');
339 container.classList.remove('noart'); 344 container.classList.remove('noart');
340 }.bind(this); 345 }.bind(this);
341 this.img_.src = metadata.thumbnailURL; 346 this.img_.src = metadata.thumbnail.url;
342 } 347 }
343 this.title_.textContent = metadata.title || this.getDefaultTitle(); 348 this.title_.textContent = metadata.media.title || this.getDefaultTitle();
344 this.artist_.textContent = metadata.artist || this.getDefaultArtist(); 349 this.artist_.textContent = metadata.media.artist || this.getDefaultArtist();
345 }; 350 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698