This commit is contained in:
Lukas Schulz 2020-12-20 13:50:39 +01:00
parent 7a65318ef4
commit f3038a7242

12
main.py
View file

@ -37,6 +37,8 @@ cache_path="/home/pi/.cache-"+username
is_playing = False is_playing = False
is_scrolling_art = False
cover_art_offset_x = 0 cover_art_offset_x = 0
cover_art_offset_y = 96 cover_art_offset_y = 96
@ -99,12 +101,16 @@ def drawCanvas():
canvas = Image.new('RGB', (192, 128), color = 'black') canvas = Image.new('RGB', (192, 128), color = 'black')
was_playing = is_playing was_playing = is_playing
cover_art = get_track() cover_art = get_track()
if (cover_art is None): global is_scrolling_art
if (cover_art is None or is_scrolling_art):
return return
if(was_playing and not is_playing): if(was_playing and not is_playing):
is_scrolling_art = True
scroll = threading.Thread(target=scrollDownSongInfo) scroll = threading.Thread(target=scrollDownSongInfo)
scroll.start() scroll.start()
if(not was_playing and is_playing): if(not was_playing and is_playing):
is_scrolling_art = True
scroll = threading.Thread(target=scrollUpSongInfo) scroll = threading.Thread(target=scrollUpSongInfo)
scroll.start() scroll.start()
if(is_playing): if(is_playing):
@ -128,6 +134,7 @@ def drawCanvas():
showImage(canvas) showImage(canvas)
def scrollDownSongInfo(offset_x=0,offset_y=96): def scrollDownSongInfo(offset_x=0,offset_y=96):
global is_scrolling_art
cover_art = get_track() cover_art = get_track()
if (cover_art is None): if (cover_art is None):
return return
@ -140,8 +147,10 @@ def scrollDownSongInfo(offset_x=0,offset_y=96):
song_info_canvas.paste(cover_art,(0,i)) song_info_canvas.paste(cover_art,(0,i))
showImage(song_info_canvas, offset_x, offset_y) showImage(song_info_canvas, offset_x, offset_y)
time.sleep(0.001) time.sleep(0.001)
is_scrolling_art = False
def scrollUpSongInfo(offset_x=0, offset_y=96): def scrollUpSongInfo(offset_x=0, offset_y=96):
global is_scrolling_art
cover_art = get_track() cover_art = get_track()
if (cover_art is None): if (cover_art is None):
return return
@ -154,6 +163,7 @@ def scrollUpSongInfo(offset_x=0, offset_y=96):
song_info_canvas.paste(cover_art,(0,(33-i))) song_info_canvas.paste(cover_art,(0,(33-i)))
showImage(song_info_canvas, offset_x, offset_y) showImage(song_info_canvas, offset_x, offset_y)
time.sleep(0.001) time.sleep(0.001)
is_scrolling_art = False
def scrolling_text(text,offset_x=0,offset_y=0): def scrolling_text(text,offset_x=0,offset_y=0):
scroll_frame_time = (8/2)/(font.getsize(text)[0]-160) scroll_frame_time = (8/2)/(font.getsize(text)[0]-160)