@@ -173,13 +173,18 @@ def _on_media_properties_changed(self, session: Session, args: MediaPropertiesCh
173
173
if DEBUG :
174
174
self ._log .debug ('MediaCallback: _on_media_properties_changed' )
175
175
try :
176
- asyncio .get_event_loop ()
176
+ # Only for the initial timer based update, because it is called from an event loop
177
+ asyncio .create_task (self ._update_media_properties (session ))
177
178
except RuntimeError :
178
179
with self ._media_info_lock :
179
180
self ._event_loop .run_until_complete (self ._update_media_properties (session ))
180
- else :
181
- # Only for the initial timer based update, because it is called from an event loop
182
- asyncio .create_task (self ._update_media_properties (session ))
181
+
182
+ if self ._media_info and self ._is_media_info_empty (self ._media_info ):
183
+ sessions = self ._session_manager .get_sessions ()
184
+
185
+ # If current session isn't in the list of sessions, switch the session
186
+ if not any (self ._are_same_sessions (sessions [i ],self ._current_session )for i in range (sessions .size )):
187
+ self .switch_session (1 )
183
188
184
189
@_current_session_only
185
190
async def _update_media_properties (self ,session :Session ):
@@ -244,6 +249,12 @@ async def get_thumbnail(thumbnail_stream_reference: IRandomAccessStreamReference
244
249
# Close the stream
245
250
readable_stream .close ()
246
251
252
+ @staticmethod
253
+ def _is_media_info_empty (media_info :dict [str ,Any ])-> bool :
254
+ keys = ['album_artist' ,'album_title' ,'album_track_count' ,'artist' ,'playback_type' ,'subtitle' ,'title' ,'track_number' ]
255
+ # Check if all keys have 'zero' values
256
+ return all (not media_info .get (key )for key in keys )
257
+
247
258
def _are_same_sessions (self ,session1 :Session ,session2 :Session )-> bool :
248
259
return session1 .source_app_user_model_id == session2 .source_app_user_model_id
249
260
@@ -262,9 +273,11 @@ def switch_session(self, direction: int):
262
273
idx = (current_session_idx + direction )% len (sessions )
263
274
if self ._are_same_sessions (sessions [idx ],self ._current_session ):
264
275
return
265
- self ._log .info (f"Switching to session{ idx } ({ sessions [idx ].source_app_user_model_id } )" )
276
+ if DEBUG :
277
+ self ._log .info (f"Switching to session{ idx } ({ sessions [idx ].source_app_user_model_id } )" )
266
278
self ._current_session = sessions [idx ]
267
- self ._on_current_session_changed (self ._session_manager ,None ,is_overridden = True )
279
+
280
+ self ._on_current_session_changed (self ._session_manager ,None ,is_overridden = True )
268
281
269
282
def play_pause (self ):
270
283
with self ._current_session_lock :