volumio / Volumio2

Volumio 2 - Audiophile Music Player
http://volumio.org
Other
1.37k stars 315 forks source link

repeatSingle status gets out of sync within pushState event #2115

Open Joni-Salminen opened 3 years ago

Joni-Salminen commented 3 years ago

This happens when Repeat single track is enabled, and Repeat is disabled without providing repeatSingle argument. I believe this could be overcome by not nesting repeatSingle check inside repeat check. this would also make the repeatSingle status reflect the actual player status in every scenario.

repeat == false, repeatSingle = false -> Repeat is not enabled repeat == true, repeatSingle = false -> Repeat is enabled repeat == true, repeatSingle = true-> Repeat single is enabled repeat == false, repeatSingle = true -> Repeat is not enabled

I'm not familiar with javascript, but if i'm looking into a correct place this is where we decide next track

CoreStateMachine.prototype.getNextIndex = function () {
  var nextIndex = this.currentPosition + 1;

  var isLastTrack = (this.playQueue.arrayQueue.length - 1) == this.currentPosition;

  // Check if Repeat mode is on and last track is played, note that Random and Consume overrides Repeat
  if (this.currentRepeat) {
    if (this.currentRepeatSingleSong) {
      nextIndex = this.currentPosition;
    } else if (isLastTrack) {
      nextIndex = 0;
    }
  }

but i believe it could be rearranged like so, then the repeatSingle worked always if it was enabled.

  if(this.currentRepeatSingleSong) {
      nextIndex = this.currentPosition;
  } 
  else if (this.currentRepeat && isLastTrack) {
    nextIndex = 0;
  }

Edit: put the code on blocks