Linux Switching Audio Device (Script?)
#1
Hey there!
i'm running xbmc Eden stable (ppa:wsnipex/xbmc-xvba-eden) with my tv. usually sound goes via hdmi to my tv. for concerts or music it would be great to use my sound system (stereo), but i couldn't find a way to switch the audio device from hdmi to spdif (custom: plughw:0,3 >>> custom plughw:0,1) automatically. for now i always navigate to system > settings > audio and change it there. is there any way to automate this process?
thankful for any hints Wink

narf!
n.b.: i was able to set up my system with wsnipex' tutorial but my linux skills are ... moderate...HuhHuhHuh
Reply
#2
Take a look at the suggestions in this thread: http://forum.xbmc.org/showthread.php?tid=136111
Reply
#3
hello again!
i tried to set up the script like suggested... well... i hope so. here is my script (toggle.py)

Code:
import os, xbmc
current_audio_mode = xbmc.executehttpapi( "GetGUISetting(0;audiooutput.mode)" ).replace("<li>","")
if current_audio_mode == "1":  # Current audio mode is Coax; set values for switching to HDMI
  audio_mode = 2
  audio_device = "alsa:plug:hdmi"
  audio_output = "HDMI"  # Optional, if notification used
else:  # Current audio mode is not HDMI; set values for switching to Coax
  audio_mode = 1
  audio_device = "custom"
  audio_output = "COAXIAL"  #Optional, if notification used
# Change audio settings and display notification of new mode:
xbmc.executehttpapi( "SetGUISetting(0;audiooutput.mode;%s)" % audio_mode )
xbmc.executehttpapi( "SetGUISetting(3;audiooutput.audiodevice;%s)" % audio_device )
xbmc.executebuiltin( "Notification(Audio output changed to:, %s, 2000)" %audio_output )  # Optional notification
then i assigned the script to a button and when pressing this button the popup comes up but nothing changes in settings / guisettings.xml

audio_device = "alsa:plug:hdmi" and
audio_device = "custom"

are the settings in guisettings.xml working if i change settings manually...
should i be able to run the script from console?

Code:
xbmc@htwz:~/.xbmc/scripts$ python toggle.py
Traceback (most recent call last):
  File "toggle.py", line 1, in <module>
    import os, xbmc
ImportError: No module named xbmc
Reply
#4
me! again!
strange things happen... actually the script works... kind of...
in system>settings>audio nothing changes but the output switches! thats great! BUT: if i change while watching a movie the script popup shows up but nothing changes really... until i change audioSTREAM too. THEN the output device switches like it should... any ideas on this?
Reply
#5
If your video is already playing, it's not going to change audio midstream. The script only changes the settings in guisettings.xml, but that doesn't mean that XBMC will re-read the file to apply the new settings. Run the script to change the settings in guisettings.xml and then start your video.
Reply
#6
Artrafael, thanks for yourinformative post. Do you know if the script you linked to will work with frodo?
Reply
#7
I believe support for httpapi will be dropped in Frodo, so no, the script, as written will no longer work. Maybe with the revamped audio support in Frodo, something like this script won't even be necessary? I don't know, I don't have digital audio.
Reply
#8
alright! it actually switches if i change audiostream after running the script. works fine for me... kind of tricky for my better half :-)
thx for the help!!!
Reply
#9
Thanks... I was afraid of that, especially after I noticed the android remote wasnt working fully with frodo.
The new audio code in frodo makes setting up alot easier but its still a PITA to switch outputs, I go from 2ch stereo via hdmi to 5.1 dts via optical, theres maybe 4-5 options I have to change each time.
I've had a browse through the json-rpc wiki page but I couldnt find anything of use in there...
My understanding is that xbmc reads guisettings.xml before playing a movie/music and based on that it decides on what device to output to.. Is this correct? Changing guisettings.xml on a remote keypress is easy enough to accomplish.
Reply
#10
(2012-11-01, 08:43)teeedubb Wrote: My understanding is that xbmc reads guisettings.xml before playing a movie/music and based on that it decides on what device to output to.. Is this correct?

Sorry, I don't really know the inner workings of XBMC. Also, I don't have digital audio, so I can't perform any empirical tests with switching audio output settings for different media and devices. I'm only able to verify the script can toggle the audio settings in guisettings.xml.

Reply
#11
Tried to change this:
<audiodevice>ALSA:hdmi:CARD=PCH,DEV=0</audiodevice>
to this:
<audiodevice>ALSA:@:CARD=DAC,DEV=0</audiodevice>

on frodo rc3 in guisettings.xml without restarting xbmc and sadly it does not change where the audio is going. Sad

Edit: nvm found this: http://forum.xbmc.org/showthread.php?tid=145430
Reply

Logout Mark Read Team Forum Stats Members Help
Switching Audio Device (Script?)0