1

It's my first time posting here as i'm potentially looking to setup a raspberry pi audio player for a non profit event i'm working on this summer. The idea being that we are creating a sound room with a button controlled audio player that will play mp3's randomly from within a directory. I'm looking at setting this up with just two buttons. One button to play / stop and the second being to skip the track.

I've had a look at the following guide ( http://www.pibeginners.com/playing-media-via-cli-gpio/ ) which looks easy enough to follow but before i get going and commit to buying the raspberry pi 3 and all of the electronic components needed can anyone tell me what the edits would look like to use omxplayer so that my buttons perform the actions described perviously? The code reads like this currently which just plays specific names mp3's / mp4's, but as i said i need it to pick random files in a directory or possibly numbered in order for the 'skip' button and the other button to play / pause.

Current script from http://www.pibeginners.com/playing-media-via-cli-gpio/ :

#!/usr/bin/env python

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

GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(17, GPIO.IN)
GPIO.setup(18, GPIO.IN)

print("------------------")
print(" OMXPlayer + GPIO ")
print("------------------")

print("--------------")
print GPIO.input(17)
print GPIO.input(18)
print("--------------")
while True:
if ( GPIO.input(17) == False ):
print("Button Pressed")
os.system('omxplayer -o local ni.mp3 &')
sleep(3)

if ( GPIO.input(18) == False ):
print("Button Pressed")
os.system('omxplayer -o hdmi intro.mp4 &')
sleep(15)

Any help on getting the script to work how we need it would be great and then i can commit to getting this up and running.

Alternatively I could look at the Adafruit setup described here using mpg123 but again I could do with some help with the switches for play, pause and skip.

https://learn.adafruit.com/playing-sounds-and-using-buttons-with-raspberry-pi/bread-board-setup-for-input-buttons

Thanks

MatsK
  • 2,791
  • 3
  • 16
  • 20
SunnyJ
  • 11
  • 3

0 Answers0