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

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

Issue 2305623003: Support to repeat one song in Audio Player. (Closed)
Patch Set: Created 4 years, 3 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 Polymer({ 5 Polymer({
6 is: 'audio-player', 6 is: 'audio-player',
7 7
8 listeners: { 8 listeners: {
9 'toggle-pause-event': 'onTogglePauseEvent_', 9 'toggle-pause-event': 'onTogglePauseEvent_',
10 'small-forward-skip-event': 'onSmallForwardSkipEvent_', 10 'small-forward-skip-event': 'onSmallForwardSkipEvent_',
(...skipping 23 matching lines...) Expand all
34 34
35 /** 35 /**
36 * Whether the shuffle button is ON. 36 * Whether the shuffle button is ON.
37 */ 37 */
38 shuffle: { 38 shuffle: {
39 type: Boolean, 39 type: Boolean,
40 notify: true 40 notify: true
41 }, 41 },
42 42
43 /** 43 /**
44 * Whether the repeat button is ON. 44 * What mode the repeat button idicates.
45 * repeat-modes can be "repeat-none", "repeat-all", "repeat-one".
45 */ 46 */
46 repeat: { 47 repeat: {
47 type: Boolean, 48 type: String,
48 notify: true 49 notify: true
49 }, 50 },
50 51
51 /** 52 /**
52 * The audio volume. 0 is silent, and 100 is maximum loud. 53 * The audio volume. 0 is silent, and 100 is maximum loud.
53 */ 54 */
54 volume: { 55 volume: {
55 type: Number, 56 type: Number,
56 notify: true 57 notify: true
57 }, 58 },
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 200
200 if (this.$.audio.readyState !== 0) 201 if (this.$.audio.readyState !== 0)
201 this.$.audio.currentTime = this.time / 1000; 202 this.$.audio.currentTime = this.time / 1000;
202 }, 203 },
203 204
204 /** 205 /**
205 * Invoked when the next button in the controller is clicked. 206 * Invoked when the next button in the controller is clicked.
206 * This handler is registered in the 'on-click' attribute of the element. 207 * This handler is registered in the 'on-click' attribute of the element.
207 */ 208 */
208 onControllerNextClicked: function() { 209 onControllerNextClicked: function() {
209 this.advance_(true /* forward */, true /* repeat */); 210 this.advance_(true /* forward */, "repeat-all");
210 }, 211 },
211 212
212 /** 213 /**
213 * Invoked when the previous button in the controller is clicked. 214 * Invoked when the previous button in the controller is clicked.
214 * This handler is registered in the 'on-click' attribute of the element. 215 * This handler is registered in the 'on-click' attribute of the element.
215 */ 216 */
216 onControllerPreviousClicked: function() { 217 onControllerPreviousClicked: function() {
217 this.advance_(false /* forward */, true /* repeat */); 218 this.advance_(false /* forward */, "repeat-all");
218 }, 219 },
219 220
220 /** 221 /**
221 * Invoked when the playback in the audio element is ended. 222 * Invoked when the playback in the audio element is ended.
222 * This handler is registered in this.ready(). 223 * This handler is registered in this.ready().
223 */ 224 */
224 onAudioEnded: function() { 225 onAudioEnded: function() {
225 this.playcount++; 226 this.playcount++;
226 this.advance_(true /* forward */, this.repeat); 227 this.advance_(true /* forward */, this.repeat);
227 }, 228 },
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 // Changes the current time back to the beginning, regardless of the current 261 // Changes the current time back to the beginning, regardless of the current
261 // status (playing or paused). 262 // status (playing or paused).
262 this.$.audio.currentTime = 0; 263 this.$.audio.currentTime = 0;
263 this.time = 0; 264 this.time = 0;
264 this.$.audio.play(); 265 this.$.audio.play();
265 }, 266 },
266 267
267 /** 268 /**
268 * Goes to the previous or the next track. 269 * Goes to the previous or the next track.
269 * @param {boolean} forward True if next, false if previous. 270 * @param {boolean} forward True if next, false if previous.
270 * @param {boolean} repeat True if repeat-mode is enabled. False otherwise. 271 * @param {string} repeatMode Repeat mode name.
271 * @private 272 * @private
272 */ 273 */
273 advance_: function(forward, repeat) { 274 advance_: function(forward, repeatMode) {
fukino 2016/09/02 12:11:48 I think we don't need to change this advance_ func
harukam 2016/09/05 04:35:03 scheduleAutoAdvance_ is called only when error hap
fukino 2016/09/05 11:44:13 I think this should work: 1) On onAudioEnded, we r
harukam 2016/09/09 04:54:50 OK. Thanks.
275 console.assert(repeatMode == "repeat-none" || repeatMode === "repeat-all" ||
276 repeatMode == "repeat-one");
277
274 this.cancelAutoAdvance_(); 278 this.cancelAutoAdvance_();
275 279
280 if(repeatMode === "repeat-one") {
281 this.playing = true;
282 this.$.audio.currentTime = 0;
283 this.$.trackList.fire('current-track-index-changed');
harukam 2016/09/02 11:27:27 Question, do you think this line is necessary? Acc
fukino 2016/09/02 12:11:48 According to https://codereview.chromium.org/16818
harukam 2016/09/05 04:35:03 Thanks for the link. It works without the event fi
fukino 2016/09/05 11:44:13 Maybe we can drop the current-track-index-changed
harukam 2016/09/09 04:54:50 Acknowledged.
284 return;
285 }
286
287 var repeat = repeatMode === "repeat-all";
276 var nextTrackIndex = this.$.trackList.getNextTrackIndex(forward, true); 288 var nextTrackIndex = this.$.trackList.getNextTrackIndex(forward, true);
277 var isNextTrackAvailable = 289 var isNextTrackAvailable =
278 (this.$.trackList.getNextTrackIndex(forward, repeat) !== -1); 290 (this.$.trackList.getNextTrackIndex(forward, repeat) !== -1);
279 291
280 this.playing = isNextTrackAvailable; 292 this.playing = isNextTrackAvailable;
281 293
282 var shouldFireEvent = this.$.trackList.currentTrackIndex === nextTrackIndex; 294 var shouldFireEvent = this.$.trackList.currentTrackIndex === nextTrackIndex;
283 this.$.trackList.currentTrackIndex = nextTrackIndex; 295 this.$.trackList.currentTrackIndex = nextTrackIndex;
284 this.$.audio.currentTime = 0; 296 this.$.audio.currentTime = 0;
285 // If the next track and current track is the same, 297 // If the next track and current track is the same,
286 // the event will not be fired. 298 // the event will not be fired.
287 // So we will fire the event here. 299 // So we will fire the event here.
288 // This happenes if there is only one song. 300 // This happenes if there is only one song.
289 if (shouldFireEvent) { 301 if (shouldFireEvent) {
290 this.$.trackList.fire('current-track-index-changed'); 302 this.$.trackList.fire('current-track-index-changed');
291 } 303 }
292 }, 304 },
293 305
294 /** 306 /**
295 * Timeout ID of auto advance. Used internally in scheduleAutoAdvance_() and 307 * Timeout ID of auto advance. Used internally in scheduleAutoAdvance_() and
296 * cancelAutoAdvance_(). 308 * cancelAutoAdvance_().
297 * @type {number?} 309 * @type {number?}
298 * @private 310 * @private
299 */ 311 */
300 autoAdvanceTimer_: null, 312 autoAdvanceTimer_: null,
301 313
302 /** 314 /**
303 * Schedules automatic advance to the next track after a timeout. 315 * Schedules automatic advance to the next track after a timeout.
304 * @param {boolean} forward True if next, false if previous. 316 * @param {boolean} forward True if next, false if previous.
305 * @param {boolean} repeat True if repeat-mode is enabled. False otherwise. 317 * @param {string} repeatMode Repeat mode name.
306 * @private 318 * @private
307 */ 319 */
308 scheduleAutoAdvance_: function(forward, repeat) { 320 scheduleAutoAdvance_: function(forward, repeatMode) {
309 this.cancelAutoAdvance_(); 321 this.cancelAutoAdvance_();
310 var currentTrackIndex = this.currentTrackIndex; 322 var currentTrackIndex = this.currentTrackIndex;
311 323
312 var timerId = setTimeout( 324 var timerId = setTimeout(
313 function() { 325 function() {
314 // If the other timer is scheduled, do nothing. 326 // If the other timer is scheduled, do nothing.
315 if (this.autoAdvanceTimer_ !== timerId) 327 if (this.autoAdvanceTimer_ !== timerId)
316 return; 328 return;
317 329
318 this.autoAdvanceTimer_ = null; 330 this.autoAdvanceTimer_ = null;
319 331
320 // If the track has been changed since the advance was scheduled, do 332 // If the track has been changed since the advance was scheduled, do
321 // nothing. 333 // nothing.
322 if (this.currentTrackIndex !== currentTrackIndex) 334 if (this.currentTrackIndex !== currentTrackIndex)
323 return; 335 return;
324 336
325 // We are advancing only if the next track is not known to be invalid. 337 // We are advancing only if the next track is not known to be invalid.
326 // This prevents an endless auto-advancing in the case when all tracks 338 // This prevents an endless auto-advancing in the case when all tracks
327 // are invalid (we will only visit each track once). 339 // are invalid (we will only visit each track once).
328 this.advance_(forward, repeat); 340 this.advance_(forward, repeatMode);
329 }.bind(this), 341 }.bind(this),
330 3000); 342 3000);
331 343
332 this.autoAdvanceTimer_ = timerId; 344 this.autoAdvanceTimer_ = timerId;
333 }, 345 },
334 346
335 /** 347 /**
336 * Cancels the scheduled auto advance. 348 * Cancels the scheduled auto advance.
337 * @private 349 * @private
338 */ 350 */
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 }, 498 },
487 499
488 /** 500 /**
489 * Big skip backword. 501 * Big skip backword.
490 * @private 502 * @private
491 */ 503 */
492 onBigBackwordSkipEvent_: function(event) { 504 onBigBackwordSkipEvent_: function(event) {
493 this.$.audioController.bigSkip(false); 505 this.$.audioController.bigSkip(false);
494 }, 506 },
495 }); 507 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698