Long time since doing something in Python and I have an issue.
I have a python script that should imitate a work of an crude jukebox where every GPIO button plays its own mp3 file.
It should run all the time after Raspbian boots.
However, after pushing the button, mp3 file plays for 1 minute and than python script stops working.
Python script:
Code: Select all
#!/usr/bin/env python
import os
import subprocess
import time
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(20, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(21, GPIO.IN, pull_up_down=GPIO.PUD_UP)
p = subprocess.Popen(["mpg123", "--remote"], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
time.sleep(1.0)
while True:
if(GPIO.input(20) == False):
p.stdin.write(b"STOP")
p.stdin.flush()
time.sleep(1.0)
p.stdin.write(b"LOAD hrvatski_def_lim_mono.mp3\n")
p.stdin.flush()
time.sleep(1.0)
if(GPIO.input(21) == False):
p.stdin.write(b"STOP")
p.stdin.flush()
time.sleep(1.0)
p.stdin.write(b"LOAD eng-def_lim_mono.mp3\n")
p.stdin.flush()
time.sleep(1.0)
Code: Select all
#!/bin/sh
#launcher.sh
cd /
cd home/pi/malik
sudo python malik.py
cd /
Code: Select all
@reboot sh /home/pi/malik/launcher.sh >home/pi/logs/cronlog 2>&1
EDIT: just noticed it stops even if I run it in terminal or via Thonny?!
So basically, I need this python script to be running all the time. Please help.
