Hardware Reference
In-Depth Information
GPIO.setup(STOP_BUTTON, GPIO.IN)
GPIO.setup(BACK_BUTTON, GPIO.IN)
GPIO.setup(FORWARD_BUTTON, GPIO.IN)
3.
After setting up
vlc
and GPIO, you can set up the LCD screen by typing the
following lines:
lcd = Adafruit_CharLCD()
lcd.clear()
lcd.message(“Hit play!”)
4.
Next, leave a blank line to update the LCD screen when the track changes and
then type the following code:
def handle_changed_track(event, player):
media = player.get_media()
media.parse()
artist = media.get_meta(vlc.Meta.Artist) or “Unknown artist”
title = media.get_meta(vlc.Meta.Title) or “Unknown song ;
title”
album = media.get_meta(vlc.Meta.Album) or “Unknown album”
lcd.clear()
lcd.message(title+”\n”+artist+” - “+album)
playerem = player.event_manager()
playerem.event_attach(vlc.EventType.MediaPlayerMediaChanged,;
handle_changed_track, player)
Let's walk through some of this code. he two lines at the end make it so that the
handle_changed_track
function is called any time the ile being played
changes. his function is called if you start playback or press one of the skip but-
tons, but also when a track inishes and the next one starts.
Looking inside the
handle_changed_track
function,
media.parse(
)
causes the program to read the metadata stored in that MP3 ile (the artist, track
name, and so on).
artist = media.get_meta(vlc.Meta.Artist)
gets the Artist metadata.
he line
artist = media.get_meta(vlc.Meta.Artist) or “Unknown
artist”
is, roughly speaking, a handy short way of writing the following:
if media.get_meta(vlc.Meta.Artist):
artist = media.get_meta(vlc.Meta.Artist)
else
artist = “Unknown artist”
You include this code to handle the case where the MP3 didn't have any embed-
ded metadata.
For the
lcd.message
there are two important things to note. First, anything
after the newline (
\n
) is displayed on the second line of your LCD screen.
Second, you use the
+
character to join strings together into one longer string.