@@ -23,16 +23,18 @@ class WinampApplication(displayio.Group):
2323 :param playlist_file: json file containing the playlist of songs
2424 :param skin_image: BMP image file for skin background
2525 :param skin_config_file: json file containing color values
26+ :param pyportal_titano: boolean value. True if using Titano, False otherwise.
2627 """
2728
2829 STATE_PLAYING = 0
2930 STATE_PAUSED = 1
30-
31+ # pylint: disable=too-many-statements
3132 def __init__ (
3233 self ,
3334 playlist_file = "playlist.json" ,
3435 skin_image = "/base_240x320.bmp" ,
3536 skin_config_file = "base_config.json" ,
37+ pyportal_titano = False ,
3638 ):
3739 self .SKIN_IMAGE = skin_image
3840 self .SKIN_CONFIG_FILE = skin_config_file
@@ -50,15 +52,35 @@ def __init__(
5052
5153 # initialize clock display
5254 self .clock_display = ClockDisplay (text_color = self .CONFIG_DATA ["time_color" ])
53- self .clock_display .x = 44
54- self .clock_display .y = 22
55+ if not pyportal_titano :
56+ # standard PyPortal and pynt clock display location
57+ # and playlist display parameters
58+ self .clock_display .x = 44
59+ self .clock_display .y = 22
60+ _max_playlist_display_chars = 30
61+ _rows = 3
62+ else :
63+ # PyPortal Titano clock display location
64+ # and playlist display parameters
65+ self .clock_display .x = 65
66+ self .clock_display .y = 37
67+ _max_playlist_display_chars = 42
68+ _rows = 4
5569
5670 # initialize playlist display
5771 self .playlist_display = PlaylistDisplay (
58- text_color = self .CONFIG_DATA ["text_color" ]
72+ text_color = self .CONFIG_DATA ["text_color" ],
73+ max_chars = _max_playlist_display_chars ,
74+ rows = _rows ,
5975 )
60- self .playlist_display .x = 13
61- self .playlist_display .y = 234
76+ if not pyportal_titano :
77+ # standard PyPortal and pynt playlist display location
78+ self .playlist_display .x = 13
79+ self .playlist_display .y = 234
80+ else :
81+ # PyPortal Titano playlist display location
82+ self .playlist_display .x = 20
83+ self .playlist_display .y = 354
6284
6385 # set playlist into playlist display
6486 self .playlist_display .from_files_list (self .PLAYLIST ["playlist" ]["files" ])
@@ -69,15 +91,26 @@ def __init__(
6991 self .playlist_display .current_track_number - 1
7092 ]
7193
94+ if not pyportal_titano :
95+ # standard PyPortal and pynt max characters for track title
96+ _max_chars = 22
97+ else :
98+ # PyPortal Titano max characters for track title
99+ _max_chars = 29
72100 # initialize ScrollingLabel for track name
73101 self .current_song_lbl = scrolling_label .ScrollingLabel (
74102 terminalio .FONT ,
75103 text = self .playlist_display .current_track_title ,
76104 color = self .CONFIG_DATA ["text_color" ],
77- max_characters = 22 ,
105+ max_characters = _max_chars ,
78106 )
79107 self .current_song_lbl .anchor_point = (0 , 0 )
80- self .current_song_lbl .anchored_position = (98 , 19 )
108+ if not pyportal_titano :
109+ # standard PyPortal and pynt track title location
110+ self .current_song_lbl .anchored_position = (98 , 19 )
111+ else :
112+ # PyPortal Titano track title location
113+ self .current_song_lbl .anchored_position = (130 , 33 )
81114
82115 # Setup the skin image file as the bitmap data source
83116 self .background_bitmap = displayio .OnDiskBitmap (self .SKIN_IMAGE )
@@ -193,8 +226,15 @@ def next_track(self):
193226 # increment current track number
194227 self .playlist_display .current_track_number += 1
195228
196- # start playing track
197- self .play_current_track ()
229+ try :
230+ # start playing track
231+ self .play_current_track ()
232+ except OSError as e :
233+ # file not found
234+ print ("Error playing: {}" .format (self .current_song_file_name ))
235+ print (e )
236+ self .next_track ()
237+ return
198238
199239 def previous_track (self ):
200240 """
@@ -209,8 +249,15 @@ def previous_track(self):
209249 # decrement current track number
210250 self .playlist_display .current_track_number -= 1
211251
212- # start playing track
213- self .play_current_track ()
252+ try :
253+ # start playing track
254+ self .play_current_track ()
255+ except OSError as e :
256+ # file not found
257+ print ("Error playing: {}" .format (self .current_song_file_name ))
258+ print (e )
259+ self .previous_track ()
260+ return
214261
215262 def pause (self ):
216263 """
@@ -244,17 +291,24 @@ class PlaylistDisplay(displayio.Group):
244291
245292 :param text_color: Hex color code for the text in the list
246293 :param song_list: Song names in the list
247- :param current_track_number: initial track number shown at the top of the list.
294+ :param current_track_number: initial track number shown at the top of the list.l
295+ :param max_chars: int max number of characters to show in a row. Excess characters are cut.
296+ :param rows: how many rows to show. One track per row. Default 3 rows
248297 """
249298
250- def __init__ (self , text_color , song_list = None , current_track_number = 0 ):
299+ def __init__ (
300+ self , text_color , song_list = None , current_track_number = 0 , max_chars = 30 , rows = 3
301+ ):
251302 super ().__init__ ()
252303
304+ self ._rows = rows
253305 if song_list is None :
254306 song_list = []
255307 self ._song_list = song_list
256308 self ._current_track_number = current_track_number
257309
310+ self ._max_chars = max_chars
311+
258312 # the label to show track titles inside of
259313 self ._label = bitmap_label .Label (terminalio .FONT , color = text_color )
260314
@@ -275,13 +329,15 @@ def update_display(self):
275329
276330 # get the current track plus the following 2
277331 _showing_songs = self .song_list [
278- self .current_track_number - 1 : self .current_track_number + 3 - 1
332+ self .current_track_number - 1 : self .current_track_number + self . _rows - 1
279333 ]
280334
281335 # format the track titles into a single string with newlines
282336 _showing_string = ""
283337 for index , song in enumerate (_showing_songs ):
284- _cur_line = "{}. {}" .format (self .current_track_number + index , song [:30 ])
338+ _cur_line = "{}. {}" .format (
339+ self .current_track_number + index , song [: self ._max_chars ]
340+ )
285341 _showing_string = "{}{}\n " .format (_showing_string , _cur_line )
286342
287343 # put it into the label
0 commit comments