piplayer3 working!

This commit is contained in:
2017-10-10 23:30:19 +02:00
parent 341539bdab
commit 732996ce62
2 changed files with 142 additions and 23 deletions
+15 -14
View File
@@ -7,16 +7,17 @@ import subprocess
import select # for polling zbarcam, see http://stackoverflow.com/a/10759061/3761783
import os
import requests
import urllib
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')
# Configuration
MUSIC_BASE_DIRECTORY = "/home/pi/music/"
SOUND_SCANNING = "/home/pi/piplayer2/sounds/scanning.mp3"
SOUND_OK = "/home/pi/piplayer2/sounds/ok-05.mp3"
SOUND_SCAN_FAIL = "/home/pi/piplayer2/sounds/fail-05.mp3"
SOUND_PLAYBACK_ERROR = "/home/pi/piplayer2/sounds/error.mp3"
MUSIC_BASE_DIRECTORY = "/media/share/Kinder/"
SOUND_SCANNING = "file:///home/pi/sounds/scanning.mp3"
SOUND_OK = "file:///home/pi/sounds/ok.mp3"
SOUND_SCAN_FAIL = "file:///home/pi/sounds/fail.mp3"
SOUND_PLAYBACK_ERROR = "file:///home/pi/sounds/error.mp3"
QR_SCANNER_TIMEOUT = 3
MOPIDY_URL = 'http://127.0.0.1:6680/mopidy/rpc'
@@ -51,10 +52,6 @@ GPIO.setup(PIN_PREV, GPIO.IN, pull_up_down=GPIO.PUD_UP)
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.add_event_detect(PIN_PREV, GPIO.FALLING, callback=btn1_callback, bouncetime=400)
GPIO.add_event_detect(PIN_PLAY, GPIO.FALLING, callback=btn2_callback, bouncetime=400)
GPIO.add_event_detect(PIN_NEXT, GPIO.FALLING, callback=btn3_callback, bouncetime=400)
def call(method, params=None):
@@ -73,6 +70,7 @@ def add_uri(filename):
def play_sound(filename):
call('core.tracklist.clear')
logging.debug('Cleared tracklist, adding ' + filename)
add_uri(filename)
call('core.playback.play')
@@ -107,6 +105,10 @@ def btn3_callback(channel):
call('core.playback.next')
GPIO.add_event_detect(PIN_PREV, GPIO.FALLING, callback=btn1_callback, bouncetime=400)
GPIO.add_event_detect(PIN_PLAY, GPIO.FALLING, callback=btn2_callback, bouncetime=400)
GPIO.add_event_detect(PIN_NEXT, GPIO.FALLING, callback=btn3_callback, bouncetime=400)
try:
play_sound(SOUND_OK)
@@ -146,7 +148,7 @@ try:
qr_code = qr_code.decode("utf-8") # python3
logging.info("QR Code: " + qr_code)
if (not qr_code.startswith("http://", "spotify:")):
if (not (qr_code.startswith("http://") or qr_code.startswith("spotify:"))):
# create full path
full_path = MUSIC_BASE_DIRECTORY + qr_code
@@ -155,12 +157,11 @@ try:
filenames = list_files(full_path)
for filename in filenames:
if filename.lower().endswith(MUSIC_EXTENSIONS):
file_uri = 'file://' + filename
add_uri(file_uri)
add_uri("file://" + urllib.parse.quote(filename))
else:
logging.debug("It's a file")
add_uri("file://" + full_path)
add_uri("file://" + urllib.parse.quote(full_path))
else:
logging.debug("URL, open directly")