I also have an HDMI splitter that goes to a female HDMI port in the side of the box in case I want to plug the system into TV. In this instance I want to disable the 3.5mm jack and push audio through HDMI. Unfortunately, as both screens run of HDMI, auto switching won't work. Therefore I am including a momentary push button to allow the audio output to be switched easily. I know I could do this in Retropie menu but I plan on removing the menu item once everything is setup correctly so friends to mess it up. Also a button will be quicker and easier than going through the menu system.
Will the below work? I've read that os.system isn't the preferred command anymore so should I change it and if so what should the python script below (that will be added to rc.local) be altered to?
Edit: Below script updated and works for me. If you have any issues it will be due to the spacing of lines. Default audio is set to the speaker and if I plug in the hdmi I simply press the momentary button switch to swap to HDMI out.
Code: Select all
import RPi.GPIO as GPIO Import time import subprocess import os GPIO.setmode(GPIO.BCM) GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_UP) set = 0 while True: input_state = GPIO.input(18) if input_state == False and set = 0: os.system("amixer -c 0 cset numid=3 1") time.sleep(1) set =1 input_state = GPIO.input(18) if input_state == False and set = 1: os.system("amixer -c 0 cset numid=3 2") time.sleep(1) set =0