I want to great a small (local) jukebox without a display. Songs are stored on the SD card and every button is more or less hardwired to one song (always to the song called "1.mp3" on the sd card which could be changed of course) Other then that the functions would be pretty simple: just press button, song plays, press next button song is added to playlist, playlist continous after first song ends.

I now read about Pygame and it seemingly being a good choice for all things music on the Pi. The first issue I read is that it only works when a display screen is attached to the Pi. Is that really the case? And if so are there any good alternatives to Pygame where I dont need a display?

Also on PyGame or an alternative, what would the code rougly look like? Here a try for Pygame: Pretty sure its crappy as it is... first try in Python ^^

import pygame
import time
import RPi.GPIO as GPIO


GPIO.setup(10, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(11, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)


playlist = glob.glob('/home/pi/Music/*.mp3')

def button_1(channel):
if event.type == pygame.USEREVENT:
  pygame.mixer.music.queue ( playlist.1.mp3() )

def button_2(channel):
if event.type == pygame.USEREVENT:
  pygame.mixer.music.queue ( playlist.2.mp3() )


pygame.mixer.music.load ( playlist )

running = True
while running:
   for event in pygame.event.get():


1 Answer 1


To answer my own Question at least to a small extend: VLC seems to offer a something similar to pygame but with the advantage that (to my knowledge) no screen is needed and it plays pretty much every data Format. Here a quick link: https://linuxconfig.org/how-to-play-audio-with-vlc-in-python

As for the code, Iam still greatful for every advice, especially if you have tipps how to use it for the vlc player.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.