import json
from gpiozero import Button
from time import sleep
from mpd import MPDClient
button = Button(23)
while True:
if button.is_pressed:
client = MPDClient() # create client object
client.timeout = 10 # network timeout in seconds (floats allowed), default: None
client.idletimeout = None # timeout for fetching the result of the idle command is handled seperately, default: None
client.connect("localhost", 6600) # connect to localhost:6600
client.load("Radio")
if (client.status()['state']=="play"):
client.pause()
else:
client.play()
sleep(1.25)
print ("State is:")
print (client.status()['state'])
client.close() # send the close command
client.disconnect() # disconnect from the server
I call this script in my bashrc file:
python ~/scripts/gpio/gpiompdstartstop.py &
I tried increasing the sleep time within the cycle, but it doesn't help at all...
I am considering investigating how to use a subprocess call, but I'm not sure it would help, nor how to go about it.
Thank you for any help.