From bdf0d139b5e25c422be55aeb81be8e9fbc73036e Mon Sep 17 00:00:00 2001 From: tilman Date: Wed, 28 Dec 2016 23:16:45 +0100 Subject: [PATCH] prev vs. jump --- code/piplayer2.py | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/code/piplayer2.py b/code/piplayer2.py index 06a8cc5..d5b9a4d 100644 --- a/code/piplayer2.py +++ b/code/piplayer2.py @@ -15,7 +15,6 @@ SOUND_OK = "/home/pi/piplayer2/sounds/ok.mp3" SOUND_SCAN_FAIL = "/home/pi/piplayer2/sounds/fail.mp3" SOUND_PLAYBACK_ERROR = "/home/pi/piplayer2/sounds/error.mp3" QR_SCANNER_TIMEOUT = 3 -BUTTON_PAUSE = 400 logging.basicConfig(level=logging.DEBUG, format='%(asctime)s.%(msecs)d %(levelname)s - %(message)s') @@ -40,10 +39,24 @@ GPIO.setup(10, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(11, GPIO.IN, pull_up_down=GPIO.PUD_UP) -def btn1_callback(channel): - logging.debug('mocp --previous') - subprocess.call(["mocp", "--previous"]) +position = 0 +def btn1_callback(channel): + logging.debug('PREV_CALLBACK') + out, err = subprocess.Popen(['mocp','--info'], stdout=subprocess.PIPE).communicate() + info = out.splitlines() + for s in info: + s = s.decode("utf-8") + if s.startswith('CurrentSec'): + position = s[s.rfind(' ')+1:] + logging.debug(int(position)) + if (int(position) < 4): + logging.debug('mocp --previous') + subprocess.call(["mocp", "--previous"]) + else: + logging.debug('mocp --jump 0s') + subprocess.call(["mocp", "--jump", "0s"]) + def btn2_callback(channel): logging.debug('mocp --toggle-pause') subprocess.call(["mocp", "--toggle-pause"]) @@ -54,9 +67,9 @@ def btn3_callback(channel): -GPIO.add_event_detect(9, GPIO.FALLING, callback=btn1_callback, bouncetime=BUTTON_PAUSE) -GPIO.add_event_detect(10, GPIO.FALLING, callback=btn2_callback, bouncetime=BUTTON_PAUSE) -GPIO.add_event_detect(11, GPIO.FALLING, callback=btn3_callback, bouncetime=BUTTON_PAUSE) +GPIO.add_event_detect(9, GPIO.FALLING, callback=btn1_callback, bouncetime=1000) +GPIO.add_event_detect(10, GPIO.FALLING, callback=btn2_callback, bouncetime=400) +GPIO.add_event_detect(11, GPIO.FALLING, callback=btn3_callback, bouncetime=400) try: logging.info('Start moc server')