[Solved] Audio output switching with toggle switch
-
Hello. I was using retropie for a couple of years before finally wiping and reinstalling this week. I had a python script running in the background for a shutdown button. This script also monitored a toggle switch that changed the audio output from hdmi to headphones and back (and does other things). I copied the file into the fresh install and everything works except the audio switch. It seems to be stuck outputting to both.
The relevant code is "os.system "sudo amixer cset numid=3 1"", toggling the 1 to a 2 and vice versa. I can't figure out what changed in retropie that broke the script. Anyone have any ideas? I have it printing at the same time, so I can actually monitor that the switch is working and changing the value, it's almost like retropie is ignoring the command though.
edit for system details:
Pi 3
RetroPie 4.4, image downloaded from the official site on April 21, 2019
High quality 5.1V 10A power supply (overkill because there's lights).
Keyboard connected, and buttons through the GPIO (confirmed working).italicised text -
Can you post the script - on pastebin.com - to take a look at it ?
So the print commands are working - when you toggle the button - but the OS command is not executed, right ? -
@mitu exactly. The shutdown command works great, the section to play audio via omxplayer works, its just the amixer lines that dont work. Haven't changed a single thing in the file from the older version of retropie. All of them use the os.system command. That's why I'm thinking it's a retropie change to how audio is handled.
I'll get the entire code posted to pastebin tomorrow.
Thanks for responding!
-
@oldspicy RetroPie is not an OS in itself, it just uses Raspbian underneath. So the change is on the OS side or in the python libs used.
-
Here is the python: https://pastebin.com/x9j51eKe
-
The script looks fine - I don't see any problems with it. How are you testing if it works ?
-
@oldspicy said in Audio output switching with toggle switch:
All of them use the os.system command. That's why I'm thinking it's a retropie change to how audio is handled.
why do you not test via CLI to toogle sound. Just enter the command
sudo amixer cset numid=3 2
and see what is happening? As @mitu told there seems no error in the script.PS: Are you in DVI mode? Maybe you can force HDMI sound by adding
hdmi_drive=2
to your/boot/config.txt
-
@cyperghost tried that, still isnt working. The amixer code just isnt activating for some reason.
-
@oldspicy Did you check the volume with
alsamixer
when switching between audio outputs ? -
@mitu both in game and from the command line
-
@mitu I haven't because there is audio out both, but I'll try that in a bit
-
@cyperghost I can force one or the other, but the point is to toggle. Sometimes using hdmi, sometimes using the internal speaker
-
-
@cyperghost @mitu Okay, so I found two more problems. Bluetooth controllers are flaky, and the shutdown script won't work if the screensaver is active. The screensaver holds it and shutdown wont happen.
I still have a build I imaged from jessie when everything was working. It's a bit old and I'll have to rebuild some things, but it might be easier. I haven't noticed a big reason to update. I just did because the files got corrupted and I figured it was a good time to update everything.
But thanks for trying!
-
@oldspicy Can't say I've seen the
shutdown
command being unable to actually shutdown/restart unless there was an I/O kernel operation stuck somewhere. -
@mitu I'm going to try wiping and a fresh install one more time before I give up, maybe something was corrupted that I couldn't find.
-
@cyperghost @mitu Okay, so a clean install fixed everything. I'm not sure what happened the first time, but now the audio switching works, along with the power and bluetooth. Something must have went wrong on the first install. Thanks for taking the time to help me troubleshoot though!
How do I mark the post as solved?
-
@oldspicy said in SOLVED - Audio output switching with toggle switch:
How do I mark the post as solved?
Edit the topic starting post and modify the title - append or prepend [solved] to it.
Contributions to the project are always appreciated, so if you would like to support us with a donation you can do so here.
Hosting provided by Mythic-Beasts. See the Hosting Information page for more information.