139139 private final MediaSessionCompat sessionCompat ;
140140 @ Nullable private final MediaButtonReceiver runtimeBroadcastReceiver ;
141141 @ Nullable private final ComponentName broadcastReceiverComponentName ;
142- @ Nullable private VolumeProviderCompat volumeProviderCompat ;
143142 private final boolean playIfSuppressed ;
144143 private final HandlerThread compatSessionInteractionThread ;
145144 private final Handler compatSessionInteractionHandler ;
146145
147146 private volatile long connectionTimeoutMs ;
148147 @ Nullable private FutureCallback <Bitmap > pendingBitmapLoadCallback ;
148+ @ Nullable private VolumeProviderCompat volumeProviderCompat ;
149149 private int sessionFlags ;
150150 @ Nullable private LegacyError legacyError ;
151151 private Bundle legacyExtras ;
@@ -1674,6 +1674,10 @@ public void onAudioAttributesChanged(int seq, AudioAttributes audioAttributes) {
16741674 if (playbackType == DeviceInfo .PLAYBACK_TYPE_LOCAL ) {
16751675 postOrRunForCompatSession (
16761676 () -> {
1677+ if (volumeProviderCompat != null ) {
1678+ // Stale event.
1679+ return ;
1680+ }
16771681 sessionCompat .setPlaybackToLocal (audioAttributes .getStreamType ());
16781682 sessionImpl .onNotificationRefreshRequired ();
16791683 });
@@ -1687,11 +1691,19 @@ public void onDeviceInfoChanged(int seq, DeviceInfo deviceInfo) {
16871691 if (volumeProviderCompat == null ) {
16881692 int streamType = player .getAudioAttributesWithCommandCheck ().getStreamType ();
16891693 postOrRunForCompatSession (() -> {
1694+ if (volumeProviderCompat != null ) {
1695+ // Stale event.
1696+ return ;
1697+ }
16901698 sessionCompat .setPlaybackToLocal (streamType );
16911699 sessionImpl .onNotificationRefreshRequired ();
16921700 });
16931701 } else {
16941702 postOrRunForCompatSession (() -> {
1703+ if (volumeProviderCompat == null ) {
1704+ // Stale event.
1705+ return ;
1706+ }
16951707 sessionCompat .setPlaybackToRemote (volumeProviderCompat );
16961708 sessionImpl .onNotificationRefreshRequired ();
16971709 });
0 commit comments