Player restart - fix unexpected playback start on reconnects
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.
@philippe44 - any opinion other than "this is a nightmare"? 😂
@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 😃
I believe this makes sense. Could you please add a one liner in Changelog8.html? Thanks!
Now done. Edit: Moved to 'bug fix' section.
@michaelherger
I think that I have addressed the point that you raised. Is there anything else that I can do to clarify ?
I had hoped that @philippe44 could give some feedback, too.
Let's give this a try. Thanks @mw9!
I'm finally really back home now and restarting everything. I will have a look