Hi all, I’m having trouble with my MPD script, what I’m trying to do is whenever I press a button, it should perform an action in MPD.
What I’m finding is that all of my MPD codes are executed when the python script is run, instead of when a button is pressed.
If I press a button, I’ve found it won’t perform the MPD command, and execute another part of the code i.e print(“Japa”)
Could someone have a look at this and tell me where I’m going wrong?
I’ve also tired this with using subprocess, and the MPD python library and get similar results, below is an example code I used to test if the basic functions are working.
if you put three ` then your code, followed by another three of those it will put your code in code tags like so your code here
On my keyboard its the key below the esc key with the ~ on it.That will maintain its structure.
I can’t make a whole lot of sense out of your code but one thing I don’t see is a “while true” loop?
I’m no python expert but I think that is needed for what your trying to do.
Without that, as far as I know, it will just do the one run and stop.
Thank you for the quick reply, I’m not sure if this looks any better:
_ import signal_
_ import buttonshim_
_ import subprocess_
_ import os_
_ @buttonshim.on_press(buttonshim.BUTTON_A)_
_ def button_a(button, pressed):_
_ buttonshim.set_pixel(0x94, 0x00, 0xd3)_
_ _
_ print(“Japa”)_
os.system (‘mpc clear’)_
os.system(‘mpc load Japa’)_
os.system(‘mpc repeat on’)_
os.system(‘mpc play’)
signal.pause()```
-----------------------------
MPC/MPD is a MusicPlayerDaemon and MusicPlayerClient for Linux/RPI, which allow music to be played and controlled by other devices. In this scenario, I want to be able it to load a playlist.
In terms of the loop, the runs and if I press the corresponding button i.e A, it will execute apart of the code i.e Print("Japa"), I based the syntax of my code on some of the examples provided with the Button Shim exmaples, which work without a loop
Looking at the examples I think you may be missing a try:
statement or two?
But to be honest, I can’t make much sense out of the code you posted. That may just be me though, I’m no Python expert. I’m about average with my Python skills.
If you open your python file for editing in say Idle. And clip and past from there, adding the code tags to just that. It should keep the formatting and get ride of all the _ etc. Keep your comments outside of the code tags though and that part will be normal and easy to read. ;)
If you open your file in Idle, and do a Run > check module from the menu. It will flage any issues with indentation. You may get messages saying something like unexpected indent where no indent was expected, lol.
EDIT: those in the know will tell you to use the tab key, not the space key.
Thats good to here. Thats something about Python that will give you headaches trying to sort out. Especially progressive indents, tab, tab tab, tab tab tab.
Anyway, have fun. =)