Skip to content

Commit

Permalink
Merge pull request #797 from mw9/feature/play_on_reconnect_issues
Browse files Browse the repository at this point in the history
Player restart - fix unexpected playback start on reconnects
  • Loading branch information
mherger committed Aug 19, 2022
2 parents b821d94 + 8b81f02 commit f6b84b8
Show file tree
Hide file tree
Showing 3 changed files with 137 additions and 119 deletions.
1 change: 1 addition & 0 deletions Changelog8.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ <h2><a name="v8.3.0" id="v8.3.0"></a>Version 8.3.0</h2>
<li>Prevent a server crash while re-building the fulltext search index with huge collections.</li>
<li>Don't show online only artists when a virtual library view tells us to do so.</li>
<li>Fix IO::Socket::SSL initialization in the scanner's sync http lookup code.</li>
<li><a href="https://github.com/Logitech/slimserver/pull/797">#797</a> - Fix Power off/Power on behaviour - Player would resume playback of stale track when reconnecting, although nothing to be resumed.</li>
</ul>
<br />

Expand Down
12 changes: 11 additions & 1 deletion Slim/Networking/Slimproto.pm
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,12 @@ sub slimproto_close {
# may change firmware versions before coming back
$client->_needsUpgrade(undef);

# Save client playback state, as if the player is turned off.
# This must be done *_now_*, before the client reconnects, otherwise
# the client->reconnect method may act on stale data. In that case,
# the player may start playback when it absolutely should not.
persistPlaybackStateForPowerOff($client);

# set timer to forget client
if ( $forget_disconnected_time ) {
main::INFOLOG && $log->is_info && $log->info("setting timer to forget client in $forget_disconnected_time secs");
Expand All @@ -295,7 +301,7 @@ sub slimproto_close {
delete($sock2client{$clientsock});
}

sub forget_disconnected_client {
sub persistPlaybackStateForPowerOff {
my $client = shift;
my $cprefs = preferences('server')->client($client);

Expand All @@ -311,6 +317,10 @@ sub forget_disconnected_client {
$cprefs->set('positionAtDisconnect', $position);
main::INFOLOG && $log->is_info && $log->info("disconnected player position $position secs");
}
}

sub forget_disconnected_client {
my $client = shift;

main::INFOLOG && $log->info("forgetting disconnected client");

Expand Down

0 comments on commit f6b84b8

Please sign in to comment.