55from datetime import timedelta
66from PIL import Image , ImageTk
77from random import choice
8+ from threading import Thread
89
910from wraplabel import WrapLabel
1011from song import Song , NoSongFound
@@ -45,6 +46,9 @@ def __init__(self, *args, **kwargs):
4546
4647 self .after (1 , self .song_changed )
4748
49+ #Start the update_current_song loop in a separate thread
50+ Thread (target = self .update_current_song , daemon = True ).start ()
51+
4852 self .after (10 , self .loop )
4953
5054
@@ -66,17 +70,19 @@ def song_changed(self):
6670
6771 self .lyrics_menu .update_lyric_labels (lyrics = self .lyrics )
6872
73+ def update_current_song (self ):
74+ while True :
75+ try :
76+ previous_song_id = self .current_song .id
77+ self .current_song = Song (raw_data = self .spotify .currently_playing ())
6978
70- def loop ( self ) :
71- previous_song_id = self .current_song . id
79+ if not self . current_song . id == previous_song_id :
80+ self .song_changed ()
7281
73- try :
74- self .current_song = Song (raw_data = self .spotify .currently_playing ())
75- except Exception as exc :
76- print (exc )
82+ except Exception as exc :
83+ print (exc )
7784
78- if not self .current_song .id == previous_song_id :
79- self .song_changed ()
85+ def loop (self ):
8086
8187 #Update progress bar
8288 self .bottom_menu .song_progess_bar .update_progress (self .current_song .progress , self .current_song .length )
0 commit comments