jehutting / omxplayer-player

A player controlling omxplayer by gpio.
8 stars 3 forks source link

ALSA Audio not working w/ Adafruit Speaker Bonnet #1

Closed ProjectileObjects closed 6 years ago

ProjectileObjects commented 6 years ago

If I run command line: omxplayer -b -o alsa:hw0,0 --loop --no-osd /(Video file) this will play the video in omxplayer on loop and the audio comes out of the adafruit speaker bonnet.

But if I add -o alsa:hw0,0 to this player script as an OMXPLAYER_ARG it doesn't play the audio out of the speaker bonnet. If I run this player script 1st after booting, it then disables audio to the speaker bonnet. Why does this ARG work by default in command line, but not in .py script?

Thanks

jehutting commented 6 years ago

Hello,

Well "omxplayer -o alsa:hw1,0 ..." doesn't work with my omxplayer and needs to be "omxplayer -o alsa:hw:1,0 ..." notice :)) the extra colon ':' between the hw and the 1,0 (my card selection).

I see that my example OMXPLAYER_ARG for the alsa is incorrect. Sorry for that.

The argument as well as its eventual value needs to have an own list entry. So, the '-o alsa' must be splitted into '-o', 'alsa'. In your case the '-o alsa' is to be splitted into '-o', 'alsa:hw:0,0'.

To be complete: OMXPLAYER_ARGS = [

'--display=4', # Raspberry Pi touchscreen

 '-o', 'alsa:hw:0,0', # ALSA device (USB Audio dongle)
 '--no-osd' # Do not display status information on screen
]
ProjectileObjects commented 6 years ago

Thanks for getting back to me.

I tried the arguments in that order with the proper '.' separating them to no avail. Do I need to import alsaaudio at in the beginning and call upon it? If I run '-o', 'alsa:hw:1,0', in the script then it causes a blank and the pi zero to freeze up for a minute. '-o', 'alsa:hw:0,0', works by default in the command line with omxplayer. I'm still not sure why this python script is killing the audio out after it runs. It is almost as if it changes the audio config, or runs a subprocess disabling after execute. The adafruit speaker bonnet connects through the GPIO headers and uses pins #18, #19, & #21 or (GPIO 24, 10, 9). I changed the pins for the buttons in the script to avoid conflicts.

The speaker bonnet sample python code uses pygame to play audio https://learn.adafruit.com/adafruit-speaker-bonnet-for-raspberry-pi/audio-with-pygame

Anymore more help would be appreciated. Thanks

jehutting commented 6 years ago

No, you don't need to import alsaaudio. It should all be handled by the subprocess call, which should do the same as the normal command line command. Should, but apparently it doesn't. Interesting.

Could you run the script and output the logging of it to a file (python omxplayer-player.py > logging 2>&1) and send me the created file?

Also I would like to know the omxplayer version ( omxplayer -v), the Raspbian OS ( cat /etc/os-release) and the modified script (to see the GPIO remapping).

With this info I will try it out tonight on my own Pi Zero W. Not having an Adafuit speaker bonnet shouldn't :-) be much of a difference.

ProjectileObjects commented 6 years ago

(sorry for the "very" delayed response).

I solved the Adafruit Pi hat audio Q, with this bit of code: `# the REAL OMXPlayer OMXPLAYER = 'omxplayer'

REAL OMXPLAYER options

OMXPLAYER_ARGS = [

'--display=4', # Raspberry Pi touchscreen

 '-o','alsa:hw:0,0',#Fingers Crosses Alsa ARGS for Adafruit Speaker Bonnet
 '-b', # adds black background
 '--loop', # enables loop function
 '--no-osd' # Do not display status information on screen
]

`

and I this button configuration: ` self.omxplayer = OMXPlayer()

    # -----H A R D W A R E   d e f i n i t i o n ---------------------------
    btnPlay = Button("Play", 17, self.__onPlayButtonChanged) # GPIO header pin 11 
    btnPrevious = Button("Previous", 27, self.__onPreviousButtonChanged) # GPIO header pin 13
    btnNext = Button("Next", 04, self.__onNextButtonChanged) # GPIO header pin 7
    #self.ledPlay = Led("Play", 22) # GPIO header pin 15
    # ----------------------------------------------------------------------

    return_code = 0 # OK`

Posting here and hope it may help someone else in the future. Thanks Jozef

jehutting commented 6 years ago

Thanks for sharing your solution.