@@ -2045,94 +2045,9 @@ protected void cacheVolume(@Nullable Volume volume) {
20452045 if (volume == null ) {
20462046 return ;
20472047 }
2048- boolean setVolume ;
20492048 synchronized (cachedVolumeLock ) {
2050- setVolume = cachedVolume == null ;
20512049 cachedVolume = volume ;
20522050 }
2053-
2054- if (
2055- setVolume &&
2056- volume .getControlType () != VolumeControlType .FIXED &&
2057- volume .getLevel () != null &&
2058- volume .getLevel ().doubleValue () < 1.0
2059- ) {
2060- // There's a long-standing bug in the ChromeCast software that resets
2061- // the device volume to 100% when the device is restarted. It correctly
2062- // reports the volume level it's supposed to have, but audio is played
2063- // back with 100% volume regardless. This little trick is to mitigate
2064- // the bug by setting the volume to what the device reports the first
2065- // time we receive one. Hopefully this won't negatively impact devices
2066- // without the bug.
2067- final double targetLevel = volume .getLevel ().doubleValue ();
2068- final double interrimLevel ;
2069- if (targetLevel > 0.1 ) {
2070- interrimLevel = targetLevel - 0.05 ;
2071- } else {
2072- interrimLevel = targetLevel + 0.05 ;
2073- }
2074-
2075- try {
2076- CastDevice .EXECUTOR .execute (new Runnable () {
2077-
2078- @ Override
2079- public void run () {
2080- try {
2081- send (
2082- null ,
2083- "urn:x-cast:com.google.cast.receiver" ,
2084- new SetVolume (new Volume (null , Double .valueOf (interrimLevel ), null , null )),
2085- PLATFORM_SENDER_ID ,
2086- PLATFORM_RECEIVER_ID ,
2087- null ,
2088- 0L
2089- );
2090- } catch (Exception e ) {
2091- LOGGER .warn (
2092- CAST_API_MARKER ,
2093- "Failed to set the initial interrim volume on {}: {}" ,
2094- remoteName ,
2095- e .getMessage ()
2096- );
2097- LOGGER .trace (CAST_API_MARKER , "" , e );
2098- }
2099- }
2100- });
2101- CastDevice .EXECUTOR .execute (new Runnable () {
2102-
2103- @ Override
2104- public void run () {
2105- try {
2106- Thread .sleep (150L );
2107- send (
2108- null ,
2109- "urn:x-cast:com.google.cast.receiver" ,
2110- new SetVolume (new Volume (null , Double .valueOf (targetLevel ), null , null )),
2111- PLATFORM_SENDER_ID ,
2112- PLATFORM_RECEIVER_ID ,
2113- null ,
2114- 0L
2115- );
2116- } catch (Exception e ) {
2117- LOGGER .warn (
2118- CAST_API_MARKER ,
2119- "Failed to set the initial volume on {}: {}" ,
2120- remoteName ,
2121- e .getMessage ()
2122- );
2123- LOGGER .trace (CAST_API_MARKER , "" , e );
2124- }
2125- }
2126- });
2127- } catch (RejectedExecutionException e ) {
2128- LOGGER .warn (
2129- CAST_API_MARKER ,
2130- "Failed to refresh the initial volume on {} because the executor rejected executing the task: {}" ,
2131- remoteName ,
2132- e .getMessage ()
2133- );
2134- }
2135- }
21362051 }
21372052
21382053 /**
0 commit comments