1

I am working on my project that can display video when a magnet (signal ) is detected using a hall-effect sensor. Then after, if the magnet is removed from the sensor the video has to pause (not to terminate or stop). So can any one help me. I got the code to stop (terminate) the video but I am looking for a command that can pause my video with out using a keyboard. My python script is shown below. I have used the dbuscontrol.sh file to pause the video but for some reason it is not working. The video displays properly but the pause command doesn't work. Can some one give me any clues?

GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)

hallpin = 18
sleepTime = 5

GPIO.setup( hallpin, GPIO.IN)


 video1 = ("/home/pi/Videos/myvideo.mp4")

while True:
    if(GPIO.input(hallpin) == False):
        #print("magnet detected")
        omxc=subprocess.Popen(['omxplayer',video1],stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE, close_fds=True)

    else:
        #print("magnet not detected")
        #os.system('killall omxplayer.bin')
        os.system('dbuscontrol.sh pause')

    sleep(sleepTime)
  • you have not included all of the information ..... your script has two print() statements, yet you said nothing about anything being printed ..... there is no way to guess if the sensor is working – jsotola Nov 17 '18 at 20:29
  • Thank you for your reply...but i am not talking about what it is going to print out ...the sensor is working perfectly ....the video also displayed when the magnet is detected ..but my question is how can i pause it when the magnet is remived from the sensor ...thank you very much again. – Fate Nov 17 '18 at 21:58
  • First of all: try using the full path to dbuscontrol.sh. You could also use a python dbus wrapper for omxplayer e.g. pypi.org/project/omxplayer-wrapper (there may be others) – Dirk Nov 18 '18 at 23:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.