@@ -1033,6 +1033,9 @@ public void setVolume(int volume) {
10331033 mVolume = volume ;
10341034 setPlaybackInfoOnRcc (RemoteControlClient .PLAYBACKINFO_VOLUME , volume );
10351035 dispatchRouteVolumeChanged (this );
1036+ if (mGroup != null ) {
1037+ mGroup .memberVolumeChanged (this );
1038+ }
10361039 }
10371040 }
10381041
@@ -1148,6 +1151,7 @@ public void addRoute(RouteInfo route) {
11481151 mRoutes .add (route );
11491152 route .mGroup = this ;
11501153 mUpdateName = true ;
1154+ updateVolume ();
11511155 dispatchRouteGrouped (route , this , at );
11521156 routeUpdated ();
11531157 }
@@ -1171,6 +1175,7 @@ public void addRoute(RouteInfo route, int insertAt) {
11711175 mRoutes .add (insertAt , route );
11721176 route .mGroup = this ;
11731177 mUpdateName = true ;
1178+ updateVolume ();
11741179 dispatchRouteGrouped (route , this , insertAt );
11751180 routeUpdated ();
11761181 }
@@ -1188,6 +1193,7 @@ public void removeRoute(RouteInfo route) {
11881193 mRoutes .remove (route );
11891194 route .mGroup = null ;
11901195 mUpdateName = true ;
1196+ updateVolume ();
11911197 dispatchRouteUngrouped (route , this );
11921198 routeUpdated ();
11931199 }
@@ -1201,6 +1207,7 @@ public void removeRoute(int index) {
12011207 RouteInfo route = mRoutes .remove (index );
12021208 route .mGroup = null ;
12031209 mUpdateName = true ;
1210+ updateVolume ();
12041211 dispatchRouteUngrouped (route , this );
12051212 routeUpdated ();
12061213 }
@@ -1270,11 +1277,15 @@ public void requestUpdateVolume(int direction) {
12701277 }
12711278
12721279 final int routeCount = getRouteCount ();
1280+ int volume = 0 ;
12731281 for (int i = 0 ; i < routeCount ; i ++) {
12741282 final RouteInfo route = getRouteAt (i );
12751283 route .requestUpdateVolume (direction );
1284+ final int routeVol = route .getVolume ();
1285+ if (routeVol > volume ) {
1286+ volume = routeVol ;
1287+ }
12761288 }
1277- final int volume = Math .max (0 , Math .min (mVolume + direction , maxVol ));
12781289 if (volume != mVolume ) {
12791290 mVolume = volume ;
12801291 dispatchRouteVolumeChanged (this );
@@ -1290,6 +1301,26 @@ void memberStatusChanged(RouteInfo info, CharSequence status) {
12901301 setStatusInt (status );
12911302 }
12921303
1304+ void memberVolumeChanged (RouteInfo info ) {
1305+ updateVolume ();
1306+ }
1307+
1308+ void updateVolume () {
1309+ // A group always represents the highest component volume value.
1310+ final int routeCount = getRouteCount ();
1311+ int volume = 0 ;
1312+ for (int i = 0 ; i < routeCount ; i ++) {
1313+ final int routeVol = getRouteAt (i ).getVolume ();
1314+ if (routeVol > volume ) {
1315+ volume = routeVol ;
1316+ }
1317+ }
1318+ if (volume != mVolume ) {
1319+ mVolume = volume ;
1320+ dispatchRouteVolumeChanged (this );
1321+ }
1322+ }
1323+
12931324 @ Override
12941325 void routeUpdated () {
12951326 int types = 0 ;
0 commit comments