-
Notifications
You must be signed in to change notification settings - Fork 0
/
mfrc522_vlc
43 lines (37 loc) · 1.14 KB
/
mfrc522_vlc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env python3
from RPi import GPIO
from time import sleep
from vlc import MediaPlayer
from mfrc522 import SimpleMFRC522
GPIO.setwarnings(False)
reader = SimpleMFRC522()
TITELDICT = {
705344242517 : MediaPlayer('/home/pi/Musik/Chip1.mp3'),
219776782654 : MediaPlayer('/home/pi/Musik/Chip2.mp3'),
566343866225 : MediaPlayer('/home/pi/Musik/Chip12.mp3')
}
def set_sound(set_key):
mediatest = 0
for get_key, media in TITELDICT.items():
if media.is_playing():
print("Player läuft bereits, ich stoppe ihn jetzt.")
mediatest = 1
media.stop() # Stoppt den Player beim dranhalten eines neuen Chips, wenn erwünscht
sleep(1)
for get_key, media in TITELDICT.items():
if get_key == set_key and mediatest == 0:
media.stop()
media.play()
sleep(1)
def main():
while True:
id_rfid, text = reader.read()
print("ID:{}".format(id_rfid))
set_sound(id_rfid)
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
print("Abbruch durch Benutzer.")
finally:
GPIO.cleanup()