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.
    tryed use stdin.write('q') stop process before playing again, have few errors can't solve
    can u me issue? think not problem python advanced users...
 
lot in advance!
 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);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);lot in advance!
 
raspberrypi
 
  
Comments
Post a Comment