Commit 8b1ace10 authored by yoshiki's avatar yoshiki Committed by Commit bot

Audio Player: Cancel scheduled advance if the track has been changed

BUG=348487
TEST=manual

Review URL: https://codereview.chromium.org/534493002

Cr-Commit-Position: refs/heads/master@{#292910}
parent d4972e38
...@@ -261,15 +261,29 @@ Polymer('audio-player', { ...@@ -261,15 +261,29 @@ Polymer('audio-player', {
*/ */
scheduleAutoAdvance_: function(forward, repeat) { scheduleAutoAdvance_: function(forward, repeat) {
this.cancelAutoAdvance_(); this.cancelAutoAdvance_();
this.autoAdvanceTimer_ = setTimeout( var currentTrackIndex = this.currentTrackIndex;
var timerId = setTimeout(
function() { function() {
// If the other timer is scheduled, do nothing.
if (this.autoAdvanceTimer_ !== timerId)
return;
this.autoAdvanceTimer_ = null; 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. // 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 // This prevents an endless auto-advancing in the case when all tracks
// are invalid (we will only visit each track once). // are invalid (we will only visit each track once).
this.advance_(forward, repeat, true /* only if valid */); this.advance_(forward, repeat, true /* only if valid */);
}.bind(this), }.bind(this),
3000); 3000);
this.autoAdvanceTimer_ = timerId;
}, },
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment