Volumio Player Part 6 - WyrmTech

Go to content

Volumio Player Part 6

Pi Bits > Volumio Player
Tweaks to the Display Settings

N.B. This relates to the 1.5 version of the Nanomesher plugin.
As of the 5th of Feb 2019 they have released a new version 1.6 with a completely revised screen layout and code.

I had a couple of niggles with the way the information was displayed from the NanoSound plugin.
  • The icon for cloud playback had a missing line down it.
  • Scrolling for the Track name
  • Scrolling for the Album name
  • Play, Pause Stop status
  • Mute
  • Elapsed Time

The python script for the display is held at /home/volumio/nanodac_oled.py so I thought I would have a play. Please bear in mind I am not a programmer, this has been done in the spirit of tinkering.

Display startup.
It's not a NanoMesher device so I didn't want it display the NanoSound name when it starts up and for the sake of changing things also decided on a white background and black text.
So in nanodac_oled.py I changed the lines
draw.text((5, 2), "NanoSound v1.5.1",font=font1, fill="white")
        draw.text((1, 18), GetLANIP(),font=font1, fill="white")
draw.text((1, 36), GetWLANIP(),font=font1, fill="white"))
to
draw.rectangle((0, 0, device.width-1, device.height-1), outline="black", fill="white")
draw.text((3, 2), "Volumio 2",font=font1, fill="black")
        draw.text((3, 18), GetLANIP(),font=font1, fill="black")
        draw.text((3, 36), GetWLANIP(),font=font1, fill="black")

The Webradio and Musicfile icons.
The font FontAwesome is used for the icons on the display
The icon for cloud playback,, (u+f1be) that is used I felt didn't look very good, as when it was shown on the small display it just looked like it had a line missing as though the display was broken so I had a look through the character map and decided on this one instead , (u+f0c2) which seems to display well. I also didn't like the icon for the musicfile so that got changed to .
So I changed the lines
webradio="\uf1be"
musicfile="\uf1c7"
headphone="\uf001"
to
webradio="\uf0c2"
musicfile="\uf019"
headphone="\uf001"

Scrolling text.
The scrolling text is controlled by the start / finish position of the displayed text, not by the number of characters, to increase the range I changed the line
for x in range(100,-10,-3):
to
for x in range(125,-25,-3):
This starts the text display at an earlier position and finishes it at a later position so the scroll will start 3 pixels in from the right and scroll for an additional 40 pixels.

I have also altered the behaviour of the scroll, as 18 characters seem to fit on the display, the original only scrolled the track title regardless of whether it fitted on the display  or not.
I have some files with long track names and some with long Artist names (even some with both). So for both the Title and Artist I wanted them to scroll if the text was longer than 18 characters.
The line draw.text((x, 2), title,font=font1, fill="white") scrolls the Title and after a bit of fiddling I came up with this:

# draw.text((x, 2), title,font=font1, fill="white")
w4, h4 = draw.textsize(text=title,font=font1)
left4 = (device.width - w4) / 2
if len(title) > 18:
   draw.text((x, 2), title,font=font1, fill="white")
else:
   draw.text((left4, 2), title,font=font1, fill="white")

Which seems to manage to centralise the text if it is less than 18 Characters, but provide the scroll if greater.
As that worked for me I then applied the same idea to the Artist text (the left position has already been worked out in the original code):

# draw.text((left, 18), artist,font=font1, fill="white")
if len(artist) > 18:
   draw.text((x, 18), artist,font=font1, fill="white")
else:
   draw.text((left, 18), artist,font=font1, fill="white")

Play, Pause, Stop.
I don't plan on using headphones with this player so I thought it would be nice to use the area in the display that shows the music or headphone icon to display the status of the player
The lines:
   if('status' in volstatus):
      state = volstatus['status']
  else:
      state = 'pause'

Were changed to:
   if('status' in volstatus):
      state = volstatus['status']
     # Set icon for play - pause - stop
     if (state=="pause"):
         statusicon = '\uf04c'
     elif (state=="play"):
         statusicon = '\uf04b'
     else:
         statusicon = '\uf04d'
else:
     state = 'pause'
     statusicon = '\uf04c'

That also means changing the lines:
   if(ampon):
draw.text((device.width - 17,36), headphone, font=awesomefont,fill="white")
else:
draw.text((device.width - 17,36), " ", font=awesomefont,fill="white")

To:
   draw.text((device.width - 17,36), statusicon, font=awesomefont,fill="white")

Mute.
It would be nice to differentiate between the volume being set to zero or muted so I added this:
   # Set Icon for mute
  if('mute' in volstatus):
      if(volstatus['mute']):
          mute = '\uf2a4'
          volume = '00'
      else:
          mute = '\uf012'
  else:
      mute = '\uf012'

And changed this:
   draw.text((92, 50), text="\uf028", font=awesomefont,fill="white")
  draw.text((105, 50), volume, fill="white")

To:
   draw.text((92, 50), mute, font=awesomefont,fill="white")
  draw.text((108, 50), volume, fill="white")
This will display this icon for volume between 0 and 100 and this icon when muted and with the volume shown as 00.

Elapsed Time
My other niggle was that when playing Web Radio stations the elapsed time was counting between an odd number of seconds then resetting, then adding various minutes, as the api does not expose how long the track is on webradio, presumably as that information is not available / irrelevant. I thought it would be nice to just not bother with an elapsed time shown for webradio at all.
I tried various ways of setting the variable 'elapsed' to nothing if webradio was detected, most stopped the code working correctly until I hit on using the duration field in volstatus, so I added this:
   # Get duration
  if('duration' in volstatus):
      dura = volstatus['duration']

And changed this:
   draw.text((10, 50), elapsed, fill="white")
To
if (dura == 0):
   draw.text((10, 50), '-:-:- ', fill="white")
else:
   draw.text((10, 50), elapsed, fill="white")

You can grab a copy of the modified nanodac_oled.py here : nanodac_oled.zip


Display showing musicfile, play, pause mute, webradio and volume changed icons.








Visitor Number:
Back to content