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

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

Issue 141273004: Play automatically when reloading the audio player with new songs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 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
« no previous file with comments | « no previous file | chrome/browser/resources/file_manager/foreground/js/media/media_controls.js » ('j') | 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 'use strict'; 5 'use strict';
6 6
7 /** 7 /**
8 * TODO(mtomasz): Rewrite the entire audio player. 8 * TODO(mtomasz): Rewrite the entire audio player.
9 * 9 *
10 * @param {HTMLElement} container Container element. 10 * @param {HTMLElement} container Container element.
(...skipping 22 matching lines...) Expand all
33 // two sets of TrackInfo instances. We could fiddle with a single set instead 33 // two sets of TrackInfo instances. We could fiddle with a single set instead
34 // but it would make keeping the list scroll position very tricky. 34 // but it would make keeping the list scroll position very tricky.
35 this.trackList_ = createChild('track-list'); 35 this.trackList_ = createChild('track-list');
36 this.trackStack_ = createChild('track-stack'); 36 this.trackStack_ = createChild('track-stack');
37 37
38 createChild('title-button collapse').addEventListener( 38 createChild('title-button collapse').addEventListener(
39 'click', this.onExpandCollapse_.bind(this)); 39 'click', this.onExpandCollapse_.bind(this));
40 40
41 this.audioControls_ = new FullWindowAudioControls( 41 this.audioControls_ = new FullWindowAudioControls(
42 createChild(), this.advance_.bind(this), this.onError_.bind(this)); 42 createChild(), this.advance_.bind(this), this.onError_.bind(this));
43
44 this.audioControls_.attachMedia(createChild('', 'audio')); 43 this.audioControls_.attachMedia(createChild('', 'audio'));
45 44
46 chrome.fileBrowserPrivate.getStrings(function(strings) { 45 chrome.fileBrowserPrivate.getStrings(function(strings) {
47 container.ownerDocument.title = strings['AUDIO_PLAYER_TITLE']; 46 container.ownerDocument.title = strings['AUDIO_PLAYER_TITLE'];
48 this.errorString_ = strings['AUDIO_ERROR']; 47 this.errorString_ = strings['AUDIO_ERROR'];
49 this.offlineString_ = strings['AUDIO_OFFLINE']; 48 this.offlineString_ = strings['AUDIO_OFFLINE'];
50 AudioPlayer.TrackInfo.DEFAULT_ARTIST = 49 AudioPlayer.TrackInfo.DEFAULT_ARTIST =
51 strings['AUDIO_PLAYER_DEFAULT_ARTIST']; 50 strings['AUDIO_PLAYER_DEFAULT_ARTIST'];
52 }.bind(this)); 51 }.bind(this));
53 52
(...skipping 13 matching lines...) Expand all
67 AudioPlayer.load = function() { 66 AudioPlayer.load = function() {
68 document.ondragstart = function(e) { e.preventDefault() }; 67 document.ondragstart = function(e) { e.preventDefault() };
69 68
70 // TODO(mtomasz): Consider providing an exact size icon, instead of relying 69 // TODO(mtomasz): Consider providing an exact size icon, instead of relying
71 // on downsampling by ash. 70 // on downsampling by ash.
72 chrome.app.window.current().setIcon( 71 chrome.app.window.current().setIcon(
73 'foreground/images/media/2x/audio_player.png'); 72 'foreground/images/media/2x/audio_player.png');
74 73
75 AudioPlayer.instance = 74 AudioPlayer.instance =
76 new AudioPlayer(document.querySelector('.audio-player')); 75 new AudioPlayer(document.querySelector('.audio-player'));
77 reload(); 76 AudioPlayer.instance.load(window.appState);
hirono 2014/01/17 05:12:12 Can we keep the line as reload() since the reload
mtomasz 2014/01/17 05:14:30 What do you mean? Can you clarify, please?
hirono 2014/01/17 05:18:48 This CL replaces "reload()" with "AudioPlayer.inst
mtomasz 2014/01/17 05:27:42 That's right, but I think it is spaghetti to call
hirono 2014/01/17 05:32:27 I got it. Then lgtm!
78 }; 77 };
79 78
80 util.addPageLoadHandler(AudioPlayer.load); 79 util.addPageLoadHandler(AudioPlayer.load);
81 80
82 /** 81 /**
83 * Unload the player. 82 * Unload the player.
84 */ 83 */
85 function unload() { 84 function unload() {
86 if (AudioPlayer.instance) 85 if (AudioPlayer.instance)
87 AudioPlayer.instance.onUnload(); 86 AudioPlayer.instance.onUnload();
88 } 87 }
89 88
90 /** 89 /**
91 * Reload the player. 90 * Reload the player.
92 */ 91 */
93 function reload() { 92 function reload() {
94 if (window.appState) { 93 AudioPlayer.instance.load(window.appState);
95 util.saveAppState();
96 AudioPlayer.instance.load(window.appState);
97 return;
98 }
99 } 94 }
100 95
101 /** 96 /**
102 * Load a new playlist. 97 * Load a new playlist.
103 * @param {Playlist} playlist Playlist object passed via mediaPlayerPrivate. 98 * @param {Playlist} playlist Playlist object passed via mediaPlayerPrivate.
104 */ 99 */
105 AudioPlayer.prototype.load = function(playlist) { 100 AudioPlayer.prototype.load = function(playlist) {
106 this.playlistGeneration_++; 101 this.playlistGeneration_++;
107 this.audioControls_.pause(); 102 this.audioControls_.pause();
108 this.currentTrack_ = -1; 103 this.currentTrack_ = -1;
109 104
110 // Save the app state, in case of restart. 105 // Save the app state, in case of restart. Make a copy of the object, so the
111 window.appState = playlist; 106 // playlist member is not changed after entries are resolved.
107 window.appState = JSON.parse(JSON.stringify(playlist));
112 util.saveAppState(); 108 util.saveAppState();
113 109
114 util.URLsToEntries(playlist.items, function(entries) { 110 util.URLsToEntries(playlist.items, function(entries) {
115 this.entries_ = entries; 111 this.entries_ = entries;
116 this.invalidTracks_ = {}; 112 this.invalidTracks_ = {};
117 this.cancelAutoAdvance_(); 113 this.cancelAutoAdvance_();
118 114
119 if (this.entries_.length <= 1) 115 if (this.entries_.length <= 1)
120 this.container_.classList.add('single-track'); 116 this.container_.classList.add('single-track');
121 else 117 else
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 * @private 205 * @private
210 */ 206 */
211 AudioPlayer.prototype.select_ = function(newTrack, opt_restoreState) { 207 AudioPlayer.prototype.select_ = function(newTrack, opt_restoreState) {
212 if (this.currentTrack_ == newTrack) return; 208 if (this.currentTrack_ == newTrack) return;
213 209
214 this.changeSelectionInList_(this.currentTrack_, newTrack); 210 this.changeSelectionInList_(this.currentTrack_, newTrack);
215 this.changeSelectionInStack_(this.currentTrack_, newTrack); 211 this.changeSelectionInStack_(this.currentTrack_, newTrack);
216 212
217 this.currentTrack_ = newTrack; 213 this.currentTrack_ = newTrack;
218 214
219 if (window.appState) { 215 window.appState.position = this.currentTrack_;
220 window.appState.position = this.currentTrack_; 216 window.appState.time = 0;
221 window.appState.time = 0; 217 util.saveAppState();
222 util.saveAppState();
223 } else {
224 util.platform.setPreference(AudioPlayer.TRACK_KEY, this.currentTrack_);
225 }
226 218
227 this.scrollToCurrent_(false); 219 this.scrollToCurrent_(false);
228 220
229 var currentTrack = this.currentTrack_; 221 var currentTrack = this.currentTrack_;
230 var entry = this.entries_[currentTrack]; 222 var entry = this.entries_[currentTrack];
231 this.fetchMetadata_(entry, function(metadata) { 223 this.fetchMetadata_(entry, function(metadata) {
232 if (this.currentTrack_ != currentTrack) 224 if (this.currentTrack_ != currentTrack)
233 return; 225 return;
234 this.audioControls_.load(entry, opt_restoreState); 226 this.audioControls_.load(entry, opt_restoreState);
235 227
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after
619 * Restore the state after page/app reload. 611 * Restore the state after page/app reload.
620 */ 612 */
621 FullWindowAudioControls.prototype.restorePlayState = function() { 613 FullWindowAudioControls.prototype.restorePlayState = function() {
622 if (this.restoreWhenLoaded_) { 614 if (this.restoreWhenLoaded_) {
623 this.restoreWhenLoaded_ = false; // This should only work once. 615 this.restoreWhenLoaded_ = false; // This should only work once.
624 if (this.decodeState()) 616 if (this.decodeState())
625 return; 617 return;
626 } 618 }
627 this.play(); 619 this.play();
628 }; 620 };
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/resources/file_manager/foreground/js/media/media_controls.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698