Index: ui/file_manager/file_manager/audio_player/elements/audio_player.js |
diff --git a/ui/file_manager/file_manager/audio_player/elements/audio_player.js b/ui/file_manager/file_manager/audio_player/elements/audio_player.js |
index 8b8e262e477e796ea61fa1df3336a0e0b1e0e2cc..ee71220c5904ca606aad4c5f7a35a19a01af967b 100644 |
--- a/ui/file_manager/file_manager/audio_player/elements/audio_player.js |
+++ b/ui/file_manager/file_manager/audio_player/elements/audio_player.js |
@@ -261,15 +261,29 @@ Polymer('audio-player', { |
*/ |
scheduleAutoAdvance_: function(forward, repeat) { |
this.cancelAutoAdvance_(); |
- this.autoAdvanceTimer_ = setTimeout( |
+ var currentTrackIndex = this.currentTrackIndex; |
+ |
+ var timerId = setTimeout( |
function() { |
+ // If the other timer is scheduled, do nothing. |
+ if (this.autoAdvanceTimer_ !== timerId) |
+ return; |
+ |
this.autoAdvanceTimer_ = null; |
+ |
+ // If the track has been changed since the advance was scheduled, do |
+ // nothing. |
+ if (this.currentTrackIndex !== currentTrackIndex) |
+ return; |
+ |
// We are advancing only if the next track is not known to be invalid. |
// This prevents an endless auto-advancing in the case when all tracks |
// are invalid (we will only visit each track once). |
this.advance_(forward, repeat, true /* only if valid */); |
}.bind(this), |
3000); |
+ |
+ this.autoAdvanceTimer_ = timerId; |
}, |
/** |