LMS-Community/slimserver

Return 'Random Mix' state in player status message

CDrummond opened this issue · 4 comments

I'd like to be able to indicate if 'Random Mix' is active for a player - similar to how I show the 'DSTM' icon. What I'd like is to have a (e.g.) randomplay property in the status response with (e.g.) inactive, active, continuous (actually I only really care about continuous) When "randomplay":"continuous" is received I'd change the shuffle/DSTM icon to the current 'Random Mix' dice icon - giving visual feedback of the plugin status - the user can then use this to disable random mix.

I'd attempt to implement this myself, but I'm not sure how to get the continuous state from the plugin.

[Edit] OK, I might have figured out hoe to do this, just investigating now...

Would the following be acceptable?

diff --git a/Slim/Control/Queries.pm b/Slim/Control/Queries.pm
index 3979a0c91..90f55bf35 100644
--- a/Slim/Control/Queries.pm
+++ b/Slim/Control/Queries.pm
@@ -3849,6 +3849,18 @@ sub statusQuery {
 
        $request->addResult("playlist_tracks", $songCount);
 
+       if ( exists $INC{'Slim/Plugin/RandomPlay/Plugin.pm'} ) {
+               my $randomplay = "inactive";
+               if (Slim::Plugin::RandomPlay::Plugin::active($client)) {
+                       $randomplay = "active";
+                       my $rpPrefs = preferences('plugin.randomplay');
+                       if ($rpPrefs->get('continuous')) {
+                               $randomplay = "continuous";
+                       }
+               }
+               $request->addResult("randomplay", $randomplay);
+        }
+
        # send client pref for digital volume control
        my $digitalVolumeControl = $prefs->client($client)->get('digitalVolumeControl');
        if ( defined($digitalVolumeControl) ) {

Whilst looking at this I noticed that continuous is a plugin-wide setting. Should it not be player specific? i.e. so one player can be on continuous mode, and another not?

Seeing as continuous is plugin-wide, perhaps just the following would be better (for now at least):

diff --git a/Slim/Control/Queries.pm b/Slim/Control/Queries.pm
index 3979a0c91..e848f2d5b 100644
--- a/Slim/Control/Queries.pm
+++ b/Slim/Control/Queries.pm
@@ -3849,6 +3849,10 @@ sub statusQuery {
 
        $request->addResult("playlist_tracks", $songCount);
 
+       if ( exists $INC{'Slim/Plugin/RandomPlay/Plugin.pm'} ) {
+               $request->addResult("randomplay", Slim::Plugin::RandomPlay::Plugin::active($client) ? 1 : 0);
+       }
+
        # send client pref for digital volume control
        my $digitalVolumeControl = $prefs->client($client)->get('digitalVolumeControl');
        if ( defined($digitalVolumeControl) ) {

Pull request #1124 created. Changes made to Material in its 'dev' branch.

Fixed by #1124 - thanks!