I am creating an MP3 music player with lyrics synchronization feature. I want to stop the synchronization of lyrics when the user presses on the pause button (tkinter). The code looks like this:
def highlightlyrics():
a=threading.Thread(target=SyncLyrics)
a.start()
# code of lyrics synchronization
def SyncLyrics():
global playing
pygame.mixer.music.pause()
try:
# this if statement is for when the user uploads an lrc
if playing and TimePlaying_value>=1:
NoToRoundOff=TimePlaying_value
# list contains the nearest lyrics timestamps to the time of the song
dictionary=[]
# this list contains the position of timestamps
pos=[]
# this for loop is for finding the nearest lyrics of timestamps of the song
for x in range(len(LYRICS)):
if times[x]-NoToRoundOff>0:
dictionary.append(times[x]-NoToRoundOff)
pos.append(x)
ls.select_set(min(pos)-2)
pygame.mixer.music.unpause()
break
# this for loop is for continuation of synchronization
for x in range(min(pos),len(LYRICS)):
ls.select_clear(x-1)
ls.select_set(x)
time.sleep(float((format(times[x+1]-times[x],'.2f'))))
except Exception as e:
raise e
thread._stop()
#I tried to create a variable where a Boolean value is stored when the user #clicks on the pause button the variable data goes to true
#The code i tried to fix this:
def change():
global is_paused
if PlayButton['image']==str(PLay):
pygame.mixer.music.unpause()
PlayButton['image']=PAuse
PlayButton.pack()
is_paused=False
else:
pygame.mixer.music.pause()
PlayButton['image']=PLay
PlayButton.pack()
is_paused=True
def SyncLyrics():
global playing
pygame.mixer.music.pause()
try:
# this if statement is for when the user uploads [lyrics ](https://en.wikipedia.org/wiki/LRC_(file_format)) file after the song is started
if playing and TimePlaying_value>=1:
NoToRoundOff=TimePlaying_value
# list contains the nearest lyrics timestamps to the time of the song
dictionary=[]
# this list contains the position of timestamps
pos=[]
# this for loop is for finding the nearest lyrics of timestamps of the song
if not is_paused:
for x in range(len(LYRICS)):
if times[x]-NoToRoundOff>0:
dictionary.append(times[x]-NoToRoundOff)
pos.append(x)
ls.select_set(min(pos)-2)
pygame.mixer.music.unpause()
break
for x in range(min(pos),len(LYRICS)):
ls.select_clear(x-1)
ls.select_set(x)
time.sleep(float((format(times[x+1]-times[x],'.2f'))))
else:
pass
print(is_paused)# When I clicked on the pause button it shows me the output as false. But it had to give true.
# this for loop is for continuation of synchronization
for x in range(min(pos),len(LYRICS)):
ls.select_clear(x-1)
ls.select_set(x)
time.sleep(float((format(times[x+1]-times[x],'.2f'))))
except Exception as e:
raise e
thread._stop()
The main problem of the code is that the is_paused variable doesn't gets update to true when i click on paused button If you have understood the question please answer. IF you have any type of query comment it.