Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Player restart - fix unexpected playback start on reconnects #797

Merged

Conversation

mw9
Copy link
Contributor

@mw9 mw9 commented Jul 4, 2022

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 Player restart proposal #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.

Copy link
Member

@michaelherger michaelherger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Slim/Player/Player.pm Show resolved Hide resolved
@michaelherger
Copy link
Member

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

@philippe44
Copy link
Contributor

@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 😃

@mw9 mw9 force-pushed the feature/play_on_reconnect_issues branch from af74f15 to bfbe4bc Compare July 31, 2022 11:29
@mw9
Copy link
Contributor Author

mw9 commented Jul 31, 2022

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 mw9 force-pushed the feature/play_on_reconnect_issues branch from 9369282 to 6b00288 Compare July 31, 2022 12:38
mw9 added 4 commits July 31, 2022 13:50
This is a fix to the changes introduced by Player restart proposal LMS-Community#699,
LMS-Community#699.

A client that disappears/disconnects for a few seconds/minutes before
reconnecting may start playing immediately it reconnects, for no good reason.

This change ensures that a client's playing state is recorded as soon as the
client disappears/disconnects. The playing state is used to determine if the
client should restart playback when it connects to LMS, so it is essential
that it is recorded as soon as the client is disconnected.

At present, the playing state (recorded in preference 'playingAtPowerOff') is
not recorded until LMS starts to 'forget' the disconnected client. This will
take place 5 minutes after 'slimproto_close', via a timer that calls
'forget_disconnected_client'.

But if the client reconnects in the interim, '_hello_handler' will kill the
relevant timer, and the true playing state is not recorded. It may, in fact,
reflect a condition that existed some days/weeks in the past.
On power on, or reconnection, clients will automatically start playback
if the persistent preference setting 'playingAtPowerOff' is enabled.

Once acted upon, this setting is no longer valid. LMS will set it again if
required, i.e. on Power off, or a player disconnection.

This "belt & braces" change explicitly resets 'playingAtPowerOff' once it has
been acted upon. It is intended to protect against unexpected resumption of
playback that may occur in otherwise unforeseen circumstances.
@mw9 mw9 force-pushed the feature/play_on_reconnect_issues branch from 6b00288 to 8b81f02 Compare July 31, 2022 12:52
@mw9 mw9 mentioned this pull request Aug 9, 2022
@mw9
Copy link
Contributor Author

mw9 commented Aug 14, 2022

@michaelherger

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

@mherger
Copy link
Contributor

mherger commented Aug 15, 2022

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

@mherger
Copy link
Contributor

mherger commented Aug 19, 2022

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

@mherger mherger merged commit f6b84b8 into LMS-Community:public/8.3 Aug 19, 2022
@philippe44
Copy link
Contributor

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

@mw9 mw9 deleted the feature/play_on_reconnect_issues branch August 25, 2022 16:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants