slimserver icon indicating copy to clipboard operation
slimserver copied to clipboard

Player restart - fix unexpected playback start on reconnects

Open mw9 opened this issue 3 years ago • 5 comments

I have been recently suffering some very unexpected behaviour from one of my Squeezebox Radios. It would randomly start playing back at all hours of the day and night.

I eventually realized that the behaviour derived from:

  • My Power On Resume setting, which is Pause at power off / Resume at power on,
  • the fact that this particular Radio occasionally loses its 'heartbeat' connection to LMS, before successfully reconnecting,
  • the fact that I had exercised the power off button about a week ago, while the Radio was playing, and
  • the changes effected by #699.

The nub of the problem is that, when Slim::Networking::Slimproto::slimproto_close closes the connection on loss of heartbeat, the Radio's current playing state is not immediately saved. Saving is tied to forget_disconnected_client, which doesn't happen for 5 minutes. And it doesn't happen at all in my circumstances, because the Radio reconnects well within 5 minutes.

So when the Radio reconnected, within some 30/40 seconds, its playing state was always assessed to be 'On'. That derives from my exercise of the 'Power off' button, a week or so ago. Unwanted playback ensued, frequently.

Proposed changes:

  • Fix client playback start on reconnect

This removes the 5 minute wait to save the client's current playing state, so the state is saved as soon as the connection is closed. It fixes the immediate issue. I've used a subroutine, persistPlaybackStateForPowerOff, for readability.

  • Client playback start on power on/reconnect - add robustness

This attempts to add some robustness/hardening to the process.

The client's playing state is saved in a, persistent, preference playingAtPowerOff. If 'On', playback will resume on Power on/reconnect. Once that is done, the goal has been achieved and the 'On' state is no longer valid. So it should be immediately reset.

This would have prevented the issue I experienced.

  • White space changes - Player.pm

Just that, an attempt to make the above more readable.

mw9 avatar Jul 04 '22 16:07 mw9

@philippe44 - any opinion other than "this is a nightmare"? 😂

michaelherger avatar Jul 26 '22 05:07 michaelherger

@philippe44 - any opinion other than "this is a nightmare"? 😂

I'll be back at a real computer in a few days and will be able to be more constructive 😃

philippe44 avatar Jul 26 '22 07:07 philippe44

I believe this makes sense. Could you please add a one liner in Changelog8.html? Thanks!

Now done. Edit: Moved to 'bug fix' section.

mw9 avatar Jul 31 '22 11:07 mw9

@michaelherger

I think that I have addressed the point that you raised. Is there anything else that I can do to clarify ?

mw9 avatar Aug 14 '22 14:08 mw9

I had hoped that @philippe44 could give some feedback, too.

mherger avatar Aug 15 '22 04:08 mherger

Let's give this a try. Thanks @mw9!

mherger avatar Aug 19 '22 13:08 mherger

I'm finally really back home now and restarting everything. I will have a look

philippe44 avatar Aug 19 '22 16:08 philippe44