Initial version of Python player
This commit is contained in:
commit
82d3506ff7
58
player.py
Normal file
58
player.py
Normal file
@ -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()
|
3
requirements.txt
Normal file
3
requirements.txt
Normal file
@ -0,0 +1,3 @@
|
||||
pi-rc522==1.1.0
|
||||
RPi.GPIO==0.6.3
|
||||
SPI-Py==1.0
|
Loading…
Reference in New Issue
Block a user