possible bug in statemachine.js increasePlaybackTimer

I am running volumio on a RPiB+ and am having problems with the playback queue stopping randomly https://volumio.org/forum/play-stops-midway-through-queue-since-444-t11180.html
I think I traced the problem to the increasePlaybackTimer function in statemachine.js. It seems that the timer function can sometimes not run often enough perhaps on some older slow devices. This leads the timer reset code to miss the end of a playing track before the variable ‘remainingTime’ becomes a negative number.

This fails the conditional to reset the timer in line #467 if(remainingTime>=0 && remainingTime<=500 && this.prefetchDone==true && this.simulateStopStartDone==false) The timer does not reset between tracks and volumio does not send the next track to MPD which then stops.

I think the problem might be related to this change. https://volumio.org/forum/bugs-statemachine-increaseplaybacktimer-method-t10340.html

I fixed the problem on my device by adding a line after #444 to constrain remainingTime from going negative. Of course it could also be fixed by removing the ‘remainingTime>=0’ from line #467 and #445. But I don’t know anything about the workings of volumio so I don’t know if this the right way to fix this.

var remainingTime=this.currentSongDuration-this.currentSeek; if (remainingTime < 0) remainingTime = 0;

Interesting observation.

Do you miss the < 5000 msec if statement, or just the < 500 msec one?
If we assume it’s just the < 500 one then the issue is that when you enter with remainingTime < 0,
you end up at

else setTimeout(this.increasePlaybackTimer.bind(this),250);

instead of inside the if block.
If you move the reset to 0 line down to just before the < 500 case, does your fix still work as expected?

It might help to log the values of the control variables when you are ‘late’

diff --git a/app/statemachine.js b/app/statemachine.js
index 9c3ad55..c617f60 100755
--- a/app/statemachine.js
+++ b/app/statemachine.js
@@ -442,6 +442,13 @@ CoreStateMachine.prototype.increasePlaybackTimer = function () {
                var remainingTime=this.currentSongDuration-this.currentSeek;
+        if (remainingTime < 0)
+        {
+             console.log("remainingTime " + remainingTime);
+             console.log("askedForPrefetch " + this.askedForPrefetch);
+             console.log("simulateStopStartDone " + this.simulateStopStartDone);
+             remainingTime = 0;
+        }
                if(remainingTime>=0 && remainingTime<5000 && this.askedForPrefetch==false)

Thanks for this. I made the patch here (version 2.513), and the problem seems to have completely disappeared. Great job!

I would like to try this, but my knowledge does not reach that level.
Can you indicate in more detail how to do it?
Will this change be reflected in an update of Volumio?
I am using Volumio 2.565.
Thank you.

I did do some logging of remainingTime and saw values going as low as -780. But when I tried to fix the issue by changing only the <=500 if statement it did not work and the playlist still stopped. I guess my understanding and explanation of the problem is not right, I don’t know JavaScript. But I did find out through trial and error that the problem can be fixed by reversing this change https://github.com/volumio/Volumio2/commit/e287d1ae8eee764352dc0ea7d2a3f45d621e90a5#diff-e1a69e9e709db8e4857a8e6148c8f045 and changing both if statements back to the way they were.

Thanks for your work to highlight this issue. It appears my understanding is incomplete too; it’s a curly one.

It would be great if you could open an issue in the tracker (volumio.github.io/docs/User_Man … oting.html)

Hi Guys,

Can anyone post a final solution of this workaround ? :slight_smile:
Which lines have to be changed/added/replaced?


I have struggled this problem since beginning. Still not solved.
Currently I have older Volimio 2.599 because in current version hardware mixer is not available.
I must admit I do not know how to edit statemachine.js, this script can be edited by Putty ?