Raspberry Pi 3 can only play a sound once with VLC

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Raspberry Pi 3 can only play a sound once with VLC



this will be my first post here, hope it will go well!



I am new to both Raspberry Pi3 and Python, but I wanted to give it a try. I have connected my Pi to a button, and when I push it, I want to play a sound. When I run my code, everything looks ok, and when I push the button, VLC plays the wav-file. All good. But... VLC will only play the wav-file once, when I press the button again, only the "Now func1 is done" appears on the screen, but no more sound:(



I need to close and re-run my program to be able to hear the wav again, and only once. How do I get my program to run the wav everytime I push my button without restarting?



Thx!


import RPi.GPIO as GPIO
from time import sleep
import vlc

GPIO.setmode(GPIO.BOARD)

player = vlc.MediaPlayer("/home/pi/Desktop/ljud/aliengun.wav")

stime = 1
button = 11

GPIO.setup(button, GPIO.IN, pull_up_down=GPIO.PUD_UP)

def func1():
player.play()
print("Now func1 is done")

try:
while True:
input_state = GPIO.input(button)
if input_state != 1:
func1()
sleep(stime)

finally:
GPIO.cleanup()





Try calling player.play_item_at_index(0) instead, in case the problem is that VLC attempts to play an item at the end of the playlist.
– AKX
Aug 6 at 20:09


player.play_item_at_index(0)





Also, instead of using VLC, you could os.system('aplay /home/pi/Desktop/ljud/aliengun.wav'). :)
– AKX
Aug 6 at 20:09


os.system('aplay /home/pi/Desktop/ljud/aliengun.wav')









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

Creating a leaderboard in HTML/JS