5757import java .io .Closeable ;
5858import java .io .IOException ;
5959import java .util .*;
60+ import java .util .concurrent .Executors ;
61+ import java .util .concurrent .Future ;
62+ import java .util .concurrent .ScheduledExecutorService ;
63+ import java .util .concurrent .TimeUnit ;
6064import java .util .function .Function ;
6165
6266/**
@@ -80,16 +84,16 @@ public class StateWrapper implements DeviceStateHandler.Listener, DealerClient.M
8084 private final PlayerState .Builder state ;
8185 private final Session session ;
8286 private final Player player ;
87+ private final ScheduledExecutorService scheduler = Executors .newSingleThreadScheduledExecutor ();
8388 private final DeviceStateHandler device ;
84- private final PlayerConfiguration conf ;
8589 private AbsSpotifyContext context ;
8690 private PagesLoader pages ;
8791 private TracksKeeper tracksKeeper ;
92+ private Future <?> volumeChangedFuture = null ;
8893
8994 StateWrapper (@ NotNull Session session , @ NotNull Player player , @ NotNull PlayerConfiguration conf ) {
9095 this .session = session ;
9196 this .player = player ;
92- this .conf = conf ;
9397 this .device = new DeviceStateHandler (session , conf );
9498 this .state = initState (PlayerState .newBuilder ());
9599
@@ -347,7 +351,8 @@ public void command(@NotNull DeviceStateHandler.Endpoint endpoint, @NotNull Devi
347351
348352 @ Override
349353 public synchronized void volumeChanged () {
350- device .updateState (Connect .PutStateReason .VOLUME_CHANGED , player .time (), state .build ());
354+ if (volumeChangedFuture != null ) volumeChangedFuture .cancel (false );
355+ volumeChangedFuture = scheduler .schedule (() -> device .updateState (Connect .PutStateReason .VOLUME_CHANGED , player .time (), state .build ()), 500 , TimeUnit .MILLISECONDS );
351356 }
352357
353358 @ Override
0 commit comments