So here I have created a loop that lists off each file in a folder and plays it using this python code:
global shuffleVar
listOfFiles = os.listdir('/home/pi/mysounds/')
pattern = "*.mp3"
for entry in listOfFiles:
if fnmatch.fnmatch(entry, pattern):
print (entry)
os.system('killall omxplayer.bin')
shuffleVar = "omxplayer -o local -I --vol 0 /home/pi/mysounds/" + (entry) + " &"
os.system(shuffleVar)
To break this down listOfFiles shows the directory of the music that needs tobe shuffled, pattern searches for only mp3 files, and the loop goes through each file and then makes a string to run omxplayer which is executed in os.system. Now before going to the next song i want to be able to have keyboard and mouse inputs to either skip ahead or turn up or down volume. For this i want to use the following loop
#track keyboard and mouse
x_max = 2180 #defines largest position mouse can go (19th LED)
x_min = 0 #defines smallest position mouse can go (9th LED)
y_max = 2180
y_min = 0
async def print_events(device):
async for event in device.async_read_loop():
if event.type == ecodes.EV_KEY: #if the event is a button click
c = categorize(event)
if c.keystate == c.key_down: #only reading key for down press not up
print(c.keycode)
if ("KEY_RIGHT" in c.keycode):
return
if (globals()['correct_event'] == 1):
print("event determination is 1")
for device in keyboardEvent, mouseEvent:
asyncio.ensure_future(print_events(device))
if (globals()['correct_event'] == 2):
print("event determination is 2")
asyncio.ensure_future(print_events(keyboardEvent))
loop = asyncio.get_event_loop()
loop.run_forever()
now here if i press KEY_RIGHT i want to exit the listening to keyboard and mouse loop and have the for loop go to the next song. I have return after it but im not sure where i will return to. What do i do to exit the track keyboard and mouse loop and have the next for loop run through?
pip
but usespython3
.