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

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

Issue 9664045: [File Manager] Use content url for playing media files from a gdata directory (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments Created 8 years, 9 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 * @constructor 17 * @constructor
17 */ 18 */
18 function AudioPlayer(container) { 19 function AudioPlayer(container, filesystemRootURL) {
19 this.container_ = container; 20 this.container_ = container;
20 this.metadataProvider_ = new MetadataProvider(); 21 this.metadataProvider_ = new MetadataProvider(filesystemRootURL);
21 this.currentTrack_ = -1; 22 this.currentTrack_ = -1;
22 this.playlistGeneration_ = 0; 23 this.playlistGeneration_ = 0;
23 24
24 this.container_.classList.add('collapsed'); 25 this.container_.classList.add('collapsed');
25 26
26 function createChild(opt_className, opt_tag) { 27 function createChild(opt_className, opt_tag) {
27 var child = container.ownerDocument.createElement(opt_tag || 'div'); 28 var child = container.ownerDocument.createElement(opt_tag || 'div');
28 if (opt_className) 29 if (opt_className)
29 child.className = opt_className; 30 child.className = opt_className;
30 container.appendChild(child); 31 container.appendChild(child);
(...skipping 19 matching lines...) Expand all
50 51
51 chrome.fileBrowserPrivate.getStrings(function(strings) { 52 chrome.fileBrowserPrivate.getStrings(function(strings) {
52 container.ownerDocument.title = strings['AUDIO_PLAYER_TITLE']; 53 container.ownerDocument.title = strings['AUDIO_PLAYER_TITLE'];
53 }) 54 })
54 } 55 }
55 56
56 AudioPlayer.load = function() { 57 AudioPlayer.load = function() {
57 document.ondragstart = function(e) { e.preventDefault() }; 58 document.ondragstart = function(e) { e.preventDefault() };
58 document.oncontextmenu = function(e) { e.preventDefault(); }; 59 document.oncontextmenu = function(e) { e.preventDefault(); };
59 60
60 var player = new AudioPlayer(document.querySelector('.audio-player')); 61 chrome.fileBrowserPrivate.requestLocalFileSystem(function(filesystem) {
61 function getPlaylist() { 62 var player = new AudioPlayer(document.querySelector('.audio-player'),
62 chrome.mediaPlayerPrivate.getPlaylist(player.load.bind(player)); 63 filesystem.root.toURL());
63 } 64 function getPlaylist() {
64 getPlaylist(); 65 chrome.mediaPlayerPrivate.getPlaylist(player.load.bind(player));
65 chrome.mediaPlayerPrivate.onPlaylistChanged.addListener(getPlaylist); 66 }
67 getPlaylist();
68 chrome.mediaPlayerPrivate.onPlaylistChanged.addListener(getPlaylist);
69 });
66 }; 70 };
67 71
68 AudioPlayer.prototype.load = function(playlist) { 72 AudioPlayer.prototype.load = function(playlist) {
69 this.playlistGeneration_++; 73 this.playlistGeneration_++;
70 74
71 this.audioControls_.pause(); 75 this.audioControls_.pause();
72 76
73 this.currentTrack_ = -1; 77 this.currentTrack_ = -1;
74 78
75 this.urls_ = playlist.items; 79 this.urls_ = playlist.items;
(...skipping 19 matching lines...) Expand all
95 this.trackStackItems_.push( 99 this.trackStackItems_.push(
96 new AudioPlayer.TrackInfo(this.trackStack_, url, onClick)); 100 new AudioPlayer.TrackInfo(this.trackStack_, url, onClick));
97 } 101 }
98 102
99 this.select_(playlist.position); 103 this.select_(playlist.position);
100 104
101 // This class will be removed if at least one track has art. 105 // This class will be removed if at least one track has art.
102 this.container_.classList.add('noart'); 106 this.container_.classList.add('noart');
103 107
104 // Load the selected track metadata first, then load the rest. 108 // Load the selected track metadata first, then load the rest.
105 this.loadMetadata_(playlist.position); 109 this.displayMetadata_(playlist.position);
106 for (i = 0; i != this.urls_.length; i++) { 110 for (i = 0; i != this.urls_.length; i++) {
107 if (i != playlist.position) 111 if (i != playlist.position)
108 this.loadMetadata_(i); 112 this.displayMetadata_(i);
109 } 113 }
110 }; 114 };
111 115
112 AudioPlayer.prototype.loadMetadata_ = function(track) { 116 AudioPlayer.prototype.displayMetadata_ = function(track) {
113 this.metadataProvider_.fetch( 117 this.fetchMetadata_(
114 this.urls_[track], 118 this.urls_[track],
115 function(generation, metadata) { 119 function(metadata) {
116 // Do nothing if another load happened since the metadata request.
117 if (this.playlistGeneration_ != generation)
118 return;
119
120 if (metadata.thumbnailURL) { 120 if (metadata.thumbnailURL) {
121 this.container_.classList.remove('noart'); 121 this.container_.classList.remove('noart');
122 } 122 }
123 this.trackListItems_[track].setMetadata(metadata); 123 this.trackListItems_[track].setMetadata(metadata);
124 this.trackStackItems_[track].setMetadata(metadata); 124 this.trackStackItems_[track].setMetadata(metadata);
125 }.bind(this, this.playlistGeneration_)); 125 }.bind(this));
126 }; 126 };
127 127
128 AudioPlayer.prototype.select_ = function(newTrack) { 128 AudioPlayer.prototype.select_ = function(newTrack) {
129 if (this.currentTrack_ == newTrack) return; 129 if (this.currentTrack_ == newTrack) return;
130 130
131 this.changeSelectionInList_(this.currentTrack_, newTrack); 131 this.changeSelectionInList_(this.currentTrack_, newTrack);
132 this.changeSelectionInStack_(this.currentTrack_, newTrack); 132 this.changeSelectionInStack_(this.currentTrack_, newTrack);
133 133
134 this.currentTrack_ = newTrack; 134 this.currentTrack_ = newTrack;
135 this.scrollToCurrent_(false); 135 this.scrollToCurrent_(false);
136 136
137 var media = this.audioControls_.getMedia(); 137 var url = this.urls_[this.currentTrack_];
138 media.src = this.urls_[this.currentTrack_]; 138 this.fetchMetadata_(url, function(metadata) {
139 media.load(); 139 var media = this.audioControls_.getMedia();
140 this.audioControls_.play(); 140 media.src = metadata.contentURL || url;
141 media.load();
142 this.audioControls_.play();
143 }.bind(this));
144 };
145
146 AudioPlayer.prototype.fetchMetadata_ = function(url, callback) {
147 this.metadataProvider_.fetch(
148 url,
149 function(generation, metadata) {
150 // Do nothing if another load happened since the metadata request.
151 if (this.playlistGeneration_ == generation)
152 callback(metadata);
153 }.bind(this, this.playlistGeneration_));
141 }; 154 };
142 155
143 AudioPlayer.prototype.changeSelectionInList_ = function(oldTrack, newTrack) { 156 AudioPlayer.prototype.changeSelectionInList_ = function(oldTrack, newTrack) {
144 this.trackListItems_[newTrack].getBox().classList.add('selected'); 157 this.trackListItems_[newTrack].getBox().classList.add('selected');
145 158
146 if (oldTrack >= 0) { 159 if (oldTrack >= 0) {
147 this.trackListItems_[oldTrack].getBox().classList.remove('selected'); 160 this.trackListItems_[oldTrack].getBox().classList.remove('selected');
148 } 161 }
149 }; 162 };
150 163
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 }; 282 };
270 283
271 AudioPlayer.TrackInfo.prototype.setMetadata = function(metadata) { 284 AudioPlayer.TrackInfo.prototype.setMetadata = function(metadata) {
272 if (metadata.thumbnailURL) { 285 if (metadata.thumbnailURL) {
273 this.art_.classList.remove('blank'); 286 this.art_.classList.remove('blank');
274 this.img_.src = metadata.thumbnailURL; 287 this.img_.src = metadata.thumbnailURL;
275 } 288 }
276 this.title_.textContent = metadata.title || this.getDefaultTitle(); 289 this.title_.textContent = metadata.title || this.getDefaultTitle();
277 this.artist_.textContent = metadata.artist || this.getDefaultArtist(); 290 this.artist_.textContent = metadata.artist || this.getDefaultArtist();
278 }; 291 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698