From 82d3506ff7f8ded5a89e70456ad09f1522e61647 Mon Sep 17 00:00:00 2001 From: Annika Backstrom Date: Sun, 13 Nov 2016 22:46:16 +0000 Subject: [PATCH] Initial version of Python player --- player.py | 58 ++++++++++++++++++++++++++++++++++++++++++++++++ requirements.txt | 3 +++ 2 files changed, 61 insertions(+) create mode 100644 player.py create mode 100644 requirements.txt diff --git a/player.py b/player.py new file mode 100644 index 0000000..374b9e6 --- /dev/null +++ b/player.py @@ -0,0 +1,58 @@ +from pirc522 import RFID +from glob import glob + +import atexit +import os +import time +import signal +import subprocess +import vlc + +rdr = RFID() +util = rdr.util() + +last_seen = None +seen_at = 0 +p = None + +RETRY_TIME = 2 + +#player = subprocess.Popen(["mpg321", "-R", "-"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) +player = subprocess.Popen(["mpg321", "-R", "-"], stdin=subprocess.PIPE) +player.stdin.write("GAIN 100") + +try: + while True: + (error, tag_type) = rdr.request() + if not error: + (error, uid) = rdr.anticoll() + if not error: + tag_id = ''.join(hex(x)[2:].zfill(2) for x in uid) + print("Tag: " + tag_id) + + if tag_id == 'b9506555d9': + print("Stopping playback.") + player.stdin.write("STOP\n") + continue + + if time.time() > (seen_at + RETRY_TIME): + last_seen = uid + seen_at = time.time() + + if tag_id == 'aa89665510': + print("Toggling pause.") + player.stdin.write("PAUSE\n") + continue + + file = glob("media/" + tag_id + " - *.mp3") + if file: + print("Playing file " + file[0]) + player.stdin.write("STOP\n") + player.stdin.write("LOAD " + file[0] + "\n") + + continue +except (KeyboardInterrupt, SystemExit): + os.kill(player.pid, signal.SIGTERM) + +# Calls GPIO cleanup +rdr.cleanup() diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..1f07111 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +pi-rc522==1.1.0 +RPi.GPIO==0.6.3 +SPI-Py==1.0