The following python code works fine from Mu. When run from terminal the following error message is received.
"vlcpulse audio output error: PulseAudio server connection failure: Connection refused"
Is this some sort of python permissions problem?
import vlc
import time
import threading as th
from gpiozero import Button, LED
from signal import pause
buttons = [Button(2), Button(3), Button(4)]
LEDS = [LED(16), LED(21), LED(20)]
path = '/media/media/EMPTY/'
sounds = ['audiofileA.mp3', 'audiofileB.mp3', 'audiofileC.mp3']
Play = [False, False, False]
VOLUME = 100
def debounce(p):
Play[p] = False
LEDS[p].off()
def player(p):
LEDS[p].on()
print("Button " + str(p + 1) + " Pressed")
global Play
if(Play[p] == False):
print("Playing " + str(p + 1))
Play[p] = True
player = vlc.MediaPlayer(path + sounds[p])
vlc.libvlc_audio_set_volume(player, VOLUME)
player.stop()
player.play()
S = th.Timer(0.5, debounce, [p])
S.start()
else:
return
def button1_pressed():
player(0)
buttons[0].when_pressed = button1_pressed
def button2_pressed():
player(1)
buttons[1].when_pressed = button2_pressed
def button3_pressed():
player(2)
buttons[2].when_pressed = button3_pressed
while True:
continue