I am developing a small media player app on raspberry pi. So This have two main functions. Namely radio and file player. If entered into file player below is the code :
process = subprocess.Popen(['omxplayer',songs[0],'-o','local'], stdout=subprocess.PIPE )
#stdout = process.communicate()[0]
nxt=0
while True:
print("looping")
output = process.stdout.readline()
if nxt>1:
process = subprocess.Popen(['omxplayer', songs[nxt],'-o','local'], stdout=subprocess.PIPE)
output = process.stdout.readline()
#stdout = process.communicate()[0]
if output =='' :
print("2")
if output:
print("finshed")
nxt=nxt+1
if GPIO.input(7)==0:
break
The problem is code after and outside this loop doesnt work before the subprocess is finished. How can I use ayncio so that some gpio readings can be taken and exit this loop once needed ? I really spent 8 hours to figureout this googling this. But all available tutorials are very difficult to understand.