Play video with omxplayer by pressing a GPIO button - Raspberry Pi Forums


hi all,

i'm newbie in python , i'm trying create script can play video/audio when user press gpio button. so, need stop previous playback before playing again. there's 1 file, pi must waiting button press without playing file, , when pressing play file, if user press button again file must replayed beggining.

found code in forum , i'm trying edit purpose, when press button file plays 2 times each time press button , doesn't stop previous.

code: select all

#!/usr/bin/env python   time import sleep import rpi.gpio gpio import os  gpio.setmode(gpio.bcm)   gpio.setup(17, gpio.in, pull_up_down=gpio.pud_up)  def input_3(channel):     print 'button 3';     os.system('sudo omxplayer -o local /home/pi/desktop/flores.mp3 & < /var/omx_fifo &');      sleep(5);  gpio.add_event_detect(17, gpio.falling, callback=input_3, bouncetime=5)  while true:     sleep(5);
tryed use stdin.write('q') stop process before playing again, have few errors can't solve

code: select all

from time import sleep import rpi.gpio gpio import os  gpio.setmode(gpio.bcm) gpio.setup(17, gpio.in, pull_up_down = gpio.pud_up)  myprocess = none  def input_3(channel):     print 'button 3';     if myprocess not none:     myprocess.stdin.write('q')     myprocess = none     gpio.cleanup()     myprocess = 'sudo omxplayer /home/pi/desktop/flores.mp3 &';     else:         myprocess = 'sudo omxplayer /home/pi/desktop/flores.mp3 &';  gpio.add_event_detect(17, gpio.rising, callback=input_3, bouncetime=10);
can u me issue? think not problem python advanced users...

lot in advance!



raspberrypi



Comments

Popular posts from this blog

VIDIOC_S_FMT error 16, Device or resource busy - Raspberry Pi Forums

using a laptop skeleton to build a pi laptop - Raspberry Pi Forums

Forum for Joomla? - Joomla! Forum - community, help and support