@@ -19,8 +19,8 @@ public class MediaInfoModule : Module<MediaInfoDataModel>
1919
2020 public override List < IModuleActivationRequirement > ActivationRequirements { get ; } = new ( ) ;
2121
22- private readonly HashSet < MediaSession > _mediaSessions = new ( new MediaSessionComparer ( ) ) ;
23- private readonly HashSet < MediaSession > _albumArtSessions = new ( new MediaSessionComparer ( ) ) ;
22+ private readonly ISet < MediaSession > _mediaSessions = new HashSet < MediaSession > ( new MediaSessionComparer ( ) ) ;
23+ private readonly ISet < MediaSession > _albumArtSessions = new HashSet < MediaSession > ( new MediaSessionComparer ( ) ) ;
2424
2525 [ CanBeNull ]
2626 private MediaSession _currentSession ;
@@ -98,7 +98,7 @@ private void MediaManager_OnAnySessionClosed(MediaSession mediaSession)
9898 _albumArtSessions . Remove ( mediaSession ) ;
9999 if ( _currentSession . Id == mediaSession . Id )
100100 {
101- _currentSession = _mediaSessions . First ( ) ;
101+ _currentSession = _mediaManager . GetFocusedSession ( ) ;
102102 }
103103 UpdateButtons ( _currentSession ) ;
104104 UpdateArtState ( ) ;
@@ -107,6 +107,11 @@ private void MediaManager_OnAnySessionClosed(MediaSession mediaSession)
107107 private async void MediaManager_OnAnyMediaPropertyChanged ( MediaSession mediaSession ,
108108 GlobalSystemMediaTransportControlsSessionMediaProperties mediaProperties )
109109 {
110+ if ( mediaSession . ControlSession == null )
111+ {
112+ MediaManager_OnAnySessionClosed ( mediaSession ) ;
113+ return ;
114+ }
110115 try
111116 {
112117 if ( mediaProperties . Thumbnail is null )
@@ -141,6 +146,7 @@ private void MediaSession_OnPlaybackStateChanged(MediaSession mediaSession,
141146 {
142147 if ( playbackInfo == null || playbackInfo . PlaybackStatus == GlobalSystemMediaTransportControlsSessionPlaybackStatus . Closed )
143148 {
149+ MediaManager_OnAnySessionClosed ( mediaSession ) ;
144150 return ;
145151 }
146152
@@ -176,7 +182,6 @@ private void UpdateButtons(MediaSession mediaSession)
176182
177183 private void UpdateArtState ( )
178184 {
179- _albumArtSessions . TrimExcess ( ) ;
180185 DataModel . HasArt = _albumArtSessions . Any ( ) ;
181186 }
182187
0 commit comments