Abspielen funktioniert, sounds nicht
This commit is contained in:
+28
-22
@@ -14,7 +14,7 @@ from socketIO_client import SocketIO, LoggingNamespace # https://gist.github.com
|
|||||||
from threading import Thread
|
from threading import Thread
|
||||||
|
|
||||||
|
|
||||||
logging.basicConfig(level=logging.INFO, format='%(asctime)s %(levelname)s - %(message)s')
|
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(levelname)s - %(message)s')
|
||||||
logging.info('Initializing TEST')
|
logging.info('Initializing TEST')
|
||||||
|
|
||||||
# Configuration
|
# Configuration
|
||||||
@@ -23,7 +23,7 @@ SOUND_SCANNING = "mnt/INTERNAL/sounds/scanning.mp3"
|
|||||||
SOUND_OK = "mnt/INTERNAL/sounds/ok-05.mp3"
|
SOUND_OK = "mnt/INTERNAL/sounds/ok-05.mp3"
|
||||||
SOUND_SCAN_FAIL = "mnt/INTERNAL/sounds/fail-05.mp3"
|
SOUND_SCAN_FAIL = "mnt/INTERNAL/sounds/fail-05.mp3"
|
||||||
SOUND_PLAYBACK_ERROR = "mnt/INTERNAL/sounds/error.mp3"
|
SOUND_PLAYBACK_ERROR = "mnt/INTERNAL/sounds/error.mp3"
|
||||||
QR_SCANNER_TIMEOUT = 3
|
QR_SCANNER_TIMEOUT = 4
|
||||||
|
|
||||||
|
|
||||||
# photo sensor on PIN 17
|
# photo sensor on PIN 17
|
||||||
@@ -52,7 +52,7 @@ GPIO.setup(PIN_PLAY, GPIO.IN, pull_up_down=GPIO.PUD_UP)
|
|||||||
GPIO.setup(PIN_NEXT, GPIO.IN, pull_up_down=GPIO.PUD_UP)
|
GPIO.setup(PIN_NEXT, GPIO.IN, pull_up_down=GPIO.PUD_UP)
|
||||||
|
|
||||||
|
|
||||||
pending_play = False # to determine whether we should send a play command after we received a pushQueue event
|
pending_play = False # to determine whether we should send a play command after we received a pushState event
|
||||||
is_playing = False # for toggling play/pause (stores the current status from the pushState events)
|
is_playing = False # for toggling play/pause (stores the current status from the pushState events)
|
||||||
|
|
||||||
socketIO = SocketIO('127.0.0.1', 3000)
|
socketIO = SocketIO('127.0.0.1', 3000)
|
||||||
@@ -88,23 +88,28 @@ def next_callback(channel):
|
|||||||
|
|
||||||
def on_pushState(*args):
|
def on_pushState(*args):
|
||||||
logging.debug(args[0]['status'])
|
logging.debug(args[0]['status'])
|
||||||
global is_playing
|
global is_playing, pending_play
|
||||||
if args[0]['status'] == 'play':
|
if args[0]['status'] == 'play':
|
||||||
is_playing = True
|
is_playing = True
|
||||||
|
pending_play = False
|
||||||
else:
|
else:
|
||||||
is_playing = False
|
is_playing = False
|
||||||
|
if pending_play:
|
||||||
|
logging.info("start pending play --------------")
|
||||||
|
socketIO.emit('play')
|
||||||
|
|
||||||
def on_pushQueue(*args):
|
def on_pushQueue(*args):
|
||||||
logging.info("pushQueue")
|
return
|
||||||
logging.info(args[0])
|
# logging.info("pushQueue")
|
||||||
global pending_play
|
# logging.info(args[0])
|
||||||
logging.info(pending_play)
|
# global pending_play
|
||||||
if pending_play:
|
# logging.info(pending_play)
|
||||||
# if not args[0]:
|
# if pending_play:
|
||||||
# play_sound(SOUND_PLAYBACK_ERROR)
|
## if not args[0]:
|
||||||
# else:
|
## play_sound(SOUND_PLAYBACK_ERROR)
|
||||||
socketIO.emit('play')
|
## else:
|
||||||
pending_play = False
|
# socketIO.emit('play', '1')
|
||||||
|
# pending_play = False
|
||||||
|
|
||||||
def queue_events_thread():
|
def queue_events_thread():
|
||||||
socketIO.wait()
|
socketIO.wait()
|
||||||
@@ -116,8 +121,6 @@ GPIO.add_event_detect(PIN_NEXT, GPIO.FALLING, callback=next_callback, bouncetime
|
|||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
play_sound(SOUND_OK)
|
|
||||||
|
|
||||||
socketIO.on('pushQueue', on_pushQueue)
|
socketIO.on('pushQueue', on_pushQueue)
|
||||||
socketIO.on('pushState', on_pushState)
|
socketIO.on('pushState', on_pushState)
|
||||||
listener_thread = Thread(target=queue_events_thread)
|
listener_thread = Thread(target=queue_events_thread)
|
||||||
@@ -129,7 +132,7 @@ try:
|
|||||||
GPIO.wait_for_edge(PIN_SENSOR, GPIO.FALLING) # TEST
|
GPIO.wait_for_edge(PIN_SENSOR, GPIO.FALLING) # TEST
|
||||||
|
|
||||||
logging.info('Photo sensor active, activating light and camera')
|
logging.info('Photo sensor active, activating light and camera')
|
||||||
play_sound(SOUND_SCANNING)
|
#play_sound(SOUND_SCANNING)
|
||||||
|
|
||||||
# turn LED on
|
# turn LED on
|
||||||
GPIO.output(PIN_LED, GPIO.HIGH)
|
GPIO.output(PIN_LED, GPIO.HIGH)
|
||||||
@@ -149,19 +152,20 @@ try:
|
|||||||
if (poll_result):
|
if (poll_result):
|
||||||
|
|
||||||
# play confirmation sound
|
# play confirmation sound
|
||||||
play_sound(SOUND_OK)
|
#play_sound(SOUND_OK)
|
||||||
socketIO.emit('removeFromQueue', 0)
|
#socketIO.emit('removeFromQueue', '0')
|
||||||
|
|
||||||
qr_code = zbarcam.stdout.readline().rstrip()
|
qr_code = zbarcam.stdout.readline().rstrip()
|
||||||
qr_code = qr_code.decode("utf-8") # python3
|
qr_code = qr_code.decode("utf-8") # python3
|
||||||
logging.info("QR Code: " + qr_code)
|
logging.info("QR Code: " + qr_code)
|
||||||
|
|
||||||
pending_play = True
|
socketIO.emit('clearQueue')
|
||||||
|
|
||||||
if qr_code.startswith("http://"):
|
if qr_code.startswith("http://"):
|
||||||
socketIO.emit('addToQueue', {'service':'webradio','uri':qr_code})
|
socketIO.emit('addToQueue', {'service':'webradio','uri':qr_code})
|
||||||
elif qr_code.startswith("spotify:"):
|
elif qr_code.startswith("spotify:"):
|
||||||
socketIO.emit('addToQueue', {'service':'spop','uri':qr_code})
|
#socketIO.emit('addToQueue', {'service':'spop','uri':qr_code})
|
||||||
|
socketIO.emit('addToQueue', {'uri':'mnt/NAS/Audio/Singles/Blazin_Squad_-_Flip_Reverse.mp3'})
|
||||||
else:
|
else:
|
||||||
# create full path
|
# create full path
|
||||||
if (qr_code.startswith("/")):
|
if (qr_code.startswith("/")):
|
||||||
@@ -170,9 +174,11 @@ try:
|
|||||||
logging.info("full_path: " + full_path)
|
logging.info("full_path: " + full_path)
|
||||||
socketIO.emit('addToQueue', {'uri':full_path})
|
socketIO.emit('addToQueue', {'uri':full_path})
|
||||||
|
|
||||||
|
pending_play = True
|
||||||
|
|
||||||
else:
|
else:
|
||||||
logging.warning('Timeout on zbarcam')
|
logging.warning('Timeout on zbarcam')
|
||||||
play_sound(SOUND_SCAN_FAIL)
|
#play_sound(SOUND_SCAN_FAIL)
|
||||||
|
|
||||||
zbarcam.terminate()
|
zbarcam.terminate()
|
||||||
GPIO.output(PIN_LED, GPIO.LOW)
|
GPIO.output(PIN_LED, GPIO.LOW)
|
||||||
|
|||||||
Reference in New Issue
Block a user