Hardware Reference
In-Depth Information
Metadata is data that describes some other sort of data. In this case, it is textual
data such as the name of the artist and track, which helps to describe the audio
data stored in an MP3 ile. For MP3s, this can be stored inside the MP3 ile
alongside the audio data.
he vlc library allows you to attach code to certain events , such as when the track is
changed on an MP3 ile. his allows you to have a function that is called any time the
selected event happens during playback.
1. Open jukebox2.py using Python IDLE 3 and edit the code to add the last line:
import glob, random, sys, vlc, time
import RPi.GPIO as GPIO
from Adafruit_CharLCD import *
Here the code has been amended to import the modiied Adafruit_CharLCD
library. You use from Adafruit_CharLCD instead of import because the
class in there is called Adafruit_CharLCD . hat means that, if you didn't use
import * as we have done here, you would have to type Adafruit_CharLCD.
AdafruitCharLCD —which would seem silly!
2. he next part of the code remains the same:
if len(sys.argv) <= 1:
print(“Please specify a folder with mp3 files”)
sys.exit(1)
folder = sys.argv[1]
files = glob.glob(folder+”/*.mp3”)
if len(files) == 0:
print(“No mp3 files in directory”, folder, “..exiting”)
sys.exit(1)
random.shuffle(files)
player = vlc.MediaPlayer()
medialist = vlc.MediaList(files)
mlplayer = vlc.MediaListPlayer()
mlplayer.set_media_player(player)
mlplayer.set_media_list(medialist)
GPIO.setmode(GPIO.BCM)
PLAY_BUTTON=11
STOP_BUTTON=7
BACK_BUTTON=4
FORWARD_BUTTON=10
GPIO.setup(PLAY_BUTTON, GPIO.IN)
Search WWH ::




Custom Search