Page 1 of 1

Function to know if omxplayer is not running

Posted: Sat May 25, 2019 1:10 pm
by picha
Hello !,

First of all, im new to raspberry and also python.
I want to make a programm which plays videos, when you press a button(s) connected with the gpio.
I already made something that works, but there is one thing in need help from you. If there is no button pressed,
there should be backgroundmusic/video that plays till a button is pushed.
Here is my script so far:

Code: Select all

# -*- coding: iso-8859-1 -*-
import RPi.GPIO as GPIO
import time
import os
import sys
from subprocess import Popen



GPIO.setmode(GPIO.BOARD)

input_pin1 = 11
input_pin2 = 13
input_pin3 = 15
input_pin4 = 16
input_pin5 = 18

GPIO.setup(input_pin1,GPIO.IN, pull_up_down = GPIO.PUD_DOWN)
GPIO.setup(input_pin2,GPIO.IN, pull_up_down = GPIO.PUD_DOWN)          
GPIO.setup(input_pin3,GPIO.IN, pull_up_down = GPIO.PUD_DOWN)  
GPIO.setup(input_pin4,GPIO.IN, pull_up_down = GPIO.PUD_DOWN)  
GPIO.setup(input_pin5,GPIO.IN, pull_up_down = GPIO.PUD_DOWN)
 
movie1 = ("/home/pi/Schreibtisch/halloween.mp4")
movie2 = ("/home/pi/Schreibtisch/halloween2.mp4")
movie3 = ("/home/pi/Schreibtisch/halloween3.mp4")
movie4 = ("/home/pi/Schreibtisch/halloween4.mp4")
movie5 = ("/home/pi/Schreibtisch/halloween4.mp4")
music = ("/home/pi/Schreibtisch/backgroundmusic.mp3")




while True:
    if(GPIO.input(input_pin1)):
        os.system('killall omxplayer.bin')
        omxc = Popen(['omxplayer', '-r', '-olocal', movie1])
        player = True
        time.sleep(1)
        
    elif(GPIO.input(input_pin2)):
        os.system('killall omxplayer.bin')
        omxc = Popen(['omxplayer', '-r', '-olocal', movie2])
        player = True
        time.sleep(1)
      
    elif(GPIO.input(input_pin3)):
        os.system('killall omxplayer.bin')
        omxc = Popen(['omxplayer', '-r', '-olocal', movie3])
        player = True
        time.sleep(1)
        
    elif(GPIO.input(input_pin4)):
        os.system('killall omxplayer.bin')
        omxc = Popen(['omxplayer', '-r', '-olocal', movie4])
        player = True
        time.sleep(1)
        
    elif(GPIO.input(input_pin5)):
        os.system('killall omxplayer.bin')
        omxc = Popen(['omxplayer', '-r', '-olocal', movie5])
        player = True
        time.sleep(1)
 #wait for omxplayer to be killed an then play backgroundmusic
    else('omxplayer' != True):
        os.system('killall omxplayer.bin')
        omxc = Popen(['omxplayer', '-r', '-olocal', music])
        player = True
        time.sleep(1)
The last "else" function is my problem. Is there any function which says

Code: Select all

else ( there isnt any omxplayer active):
I don't know how i should do it any other way, since im in a loop.