diff --git a/mopidy_musicbox_webclient/static/mb.appcache b/mopidy_musicbox_webclient/static/mb.appcache index 720bf20..7b69bc6 100644 --- a/mopidy_musicbox_webclient/static/mb.appcache +++ b/mopidy_musicbox_webclient/static/mb.appcache @@ -1,6 +1,6 @@ CACHE MANIFEST -# 2016-04-06:v1 +# 2016-04-12:v1 NETWORK: * diff --git a/mopidy_musicbox_webclient/static/vendors/media_progress_timer/timer.js b/mopidy_musicbox_webclient/static/vendors/media_progress_timer/timer.js index 59145ca..9ca7e85 100644 --- a/mopidy_musicbox_webclient/static/vendors/media_progress_timer/timer.js +++ b/mopidy_musicbox_webclient/static/vendors/media_progress_timer/timer.js @@ -153,12 +153,14 @@ // TODO: Consider wrapping this in a try/catch? this._userCallback(userPosisition, state.duration); - - if (state.position < state.duration) { + // Workaround for https://github.com/adamcik/media-progress-timer/issues/3 + // Mopidy <= 1.1.2 does not always return the correct track position as + // track changes are being done, which can cause the timer to die unexpectedly. + //if (state.position < state.duration) { this._updateId = this._schedule(timestamp); // Schedule update. - } else { - this._updateId = null; // Unset since we didn't reschedule. - } + //} else { + // this._updateId = null; // Unset since we didn't reschedule. + //} }; return ProgressTimer; diff --git a/tests/js/test_synced_timer.js b/tests/js/test_synced_timer.js index 1ab85f6..d921eb2 100644 --- a/tests/js/test_synced_timer.js +++ b/tests/js/test_synced_timer.js @@ -331,15 +331,6 @@ describe('SyncedTimer', function () { expect($('#songelapsed').text()).to.equal('0:01') assert.equal($('#trackslider').val(), 1000) }) - - it('should implement workaround for https://github.com/adamcik/media-progress-timer/issues/3', function () { - syncedProgressTimer.set(1000, 2000).start() - - assert.equal(syncedProgressTimer._duration, 2000) - syncedProgressTimer.set(3000) - assert.equal(syncedProgressTimer._progressTimer._state.position, 1999, 'Expected position to be less than duration') - syncedProgressTimer.stop() - }) }) describe('#start()', function () { @@ -510,4 +501,29 @@ describe('SyncedTimer', function () { syncedProgressTimer.stop() }) }) + + describe('regression tests for https://github.com/adamcik/media-progress-timer/issues/3', function () { + it('should not be possible to set position > duration', function () { + syncedProgressTimer.set(1000, 2000).start() + + assert.equal(syncedProgressTimer._duration, 2000) + syncedProgressTimer.set(3000) + assert.equal(syncedProgressTimer._progressTimer._state.position, 1999, 'Expected position to be less than duration') + syncedProgressTimer.stop() + }) + + it('should keep timer running even if an update would cause position > duration', function () { + setFakeTimers() + + clock.tick(0) + clock.tick(1000) + syncedProgressTimer.set(0, 1000).start() + clock.tick(2000) + + assert.isNotNull(syncedProgressTimer._progressTimer._updateId) + syncedProgressTimer.stop() + + restoreFakeTimers() + }) + }) })