Win How to switch audio output easily?
#16
So you want to have your audio from the tv and from your amp at the same time ?
Or do you want sometimes your audio from the tv and another time from your amp depending on time and mood or something like that ?
If so you're able to use profiles,
I presume you know upfront when you want your audio from your tv or amp.
LibreElec Kodi | Aeon MQ ?
Reply
#17
edit double
Reply
#18
Using profiles for different audio settings seems lime a really clunky way of doing things, especially when you can change all the settings via jsonrpc (in Gotham) - maintaining practically 2 xbmc installs and having to reselect a movie if you decide to turn on the avr half way through the movie imo seems painful...
Reply
#19
(2014-05-25, 23:20)TRaSH Wrote: So you want to have your audio from the tv and from your amp at the same time ?
Or do you want sometimes your audio from the tv and another time from your amp depending on time and mood or something like that ?
If so you're able to use profiles,
I presume you know upfront when you want your audio from your tv or amp.


Let me do an example

My Setup:

Tv Panasonic Vt 60
Mediaplayer : popcorn hour a300
AmplBig Grinenon x2000

Connection:Hdmi

With popcorn hour if Amplifier is off i hear the audio from TV, if i switch on the amplifier i hear the audio from the speakers of ht

That's all..only using power of the remote amplifier


(2014-05-25, 23:15)teeedubb Wrote: Use a script to toggle audio outputs/speaker config/pass through mode/etc via jsonrpc (example above) and map it to a remote/keyboard key. I have a script running in the background which pings my avr, if its on it automatically switches xbmcs audio settings. Works really well.

@ teeedubb

I'm so newbie that i didn't already understand where to run the script Big Grin (i also checked in the addons.... )

I didn't find anywhere in the wiki (probably also why english is not my mother language)

So i'm studying on it Wink

thx
Reply
#20
I can post my script later but for now get the basics working, follow the info in post 7, and get the audio switching working via ssh first (you're using OE right?). Get the commands that you need to switxh settings to your liking(number of channels, pass through codecs, pass through device etc), then worry about automating it.

See this thread for more info + a list of settings that can be toggled.

http://forum.xbmc.org/showthread.php?tid=192491
Reply
#21
I need to setup a pc in my ht room with oe installed and then i will try with ssh and putty from my pc with windows.

So i will come back in few days

Thank you
Reply
#22
Ok i installed open elec on a notebook and downloaded putty

So i login to ssh using root access and i tried your script (yes i know that i need to edit with my output but i start to see if connection works correctly)

curl -v -H "Content-type: application/json" -X POST -d '{"jsonrpc":"2.0","method":"Settings.SetSettingValue", "params":{"setting":"audiooutput.audiodevice","value":"ALSA:hdmi:CARD=NVidia,DEV=1"},"id":1}' http://localhost:9191/jsonrpc

but it give me this error:

* Hostname was NOT found in DNS cache
* Trying 127.0.0.1...
* connect to 127.0.0.1 port 9191 failed: Connection refused
* Trying 127.0.0.1...
* connect to 127.0.0.1 port 9191 failed: Connection refused
* Failed to connect to localhost port 9191: Connection refused
* Closing connection 0
curl: (7) Failed to connect to localhost port 9191: Connection refused
* Hostname was found in DNS cache
* Trying 127.0.0.1...
* connect to 127.0.0.1 port 9191 failed: Connection refused
* Trying 127.0.0.1...
* connect to 127.0.0.1 port 9191 failed: Connection refused
* Failed to connect to localhost port 9191: Connection refused
* Closing connection 1


So i tried to edit the script with ip of open elec hardware instead of local host so:

curl -v -H "Content-type: application/json" -X POST -d '{"jsonrpc":"2.0","method":"Settings.SetSettingValue", "params":{"setting":"audiooutput.audiodevice","value":"ALSA:hdmi:CARD=NVidia,DEV=1"},"id":1}' http://192.168.2.13:9191/jsonrpc

but:


* Hostname was NOT found in DNS cache
* Trying 192.168.2.13...
* connect to 192.168.2.13 port 9191 failed: Connection refused
* Failed to connect to 192.168.2.13 port 9191: Connection refused
* Closing connection 0
curl: (7) Failed to connect to 192.168.2.13 port 9191: Connection refused


It's not a good start Big Grin
Reply
#23
Do you have 9191 set as the port and control XBMC from other devices on in settings?
Reply
#24
Mmh i don't know Big Grin ( sorry first time i use ssh)

In open elec system menú i don't see any port setting

I will check better later

Putty default port is 22 but i see on wiki that it doesn't matter

I login correctly to open elec with root acces and command such dir works with no permission error
Reply
#25
You need to enable jsonrpc in xbmc

http://wiki.xbmc.org/?title=JSON-RPC_API...g_JSON-RPC

From memory xbmcs default port is 8080
Reply
#26
Yeah, you are great

The port was 80 and now work correctly local host


So the code is:

Code:
Enable passthrough

curl -v -H "Content-type: application/json" -X POST -d '{"jsonrpc":"2.0","method":"Settings.SetSettingValue", "params":{"setting":"audiooutput.passthrough","value":true},"id":1}' http://localhost:80/jsonrpc

Disable passthrough

curl -v -H "Content-type: application/json" -X POST -d '{"jsonrpc":"2.0","method":"Settings.SetSettingValue", "params":{"setting":"audiooutput.passthrough","value":false},"id":1}' http://localhost:80/jsonrpc

So now how can i with my remote (harmony 650) create a button to switch the two options ?
Reply
#27
Does your avr have network connectivity? If you can tell whether the avr is on or off via network you can automate the sxript.
Reply
#28
Here is my script, its for linux but because its pretty basic something similar should be possible in win via a batch file, plus its got a few examples of audio setting switching commands. It first checks to see if jsonrpc is up, then it pings the avr, if it gets a response it switches xbmcs settings to avr mode, if no response it switches xbmc into TV mode. It displays a popup 'audio output tv/avr' on every switch. Runs at boot and loops continuously. I have setup my htpc to listen for the avr power button press so it displays a pop up for 10seconds (about the time it takes from avr power up to being ready to use) saying 'please wait, switching audio output' using irexec (windows users can use eventghost)
Code:
#!/bin/bash
export DISPLAY=:0

echo starting loop..

while true ; do

until [[ $(nmap -p 9191 192.168.1.32 |grep -i open) ]] ; do
   sleep 1
   echo sleeping 1s, waiting for xbmc json-rpc
done


if [ "`ping -c 1 192.168.1.201 | grep "64 bytes from 192.168.1.201"`" ] ; then

if [ -f /tmp/avr.on ] ; then

    echo avr on , avr.on exists

else

    echo avr on, no avr.on
    curl -v -H "Content-type: application/json" -X POST -d '{"jsonrpc":"2.0","method":"Settings.SetSettingValue", "params":{"setting":"audiooutput.passthroughdevice","value":"ALSA:hdmi:CARD=NVidia,DEV=1"},"id":1}' http://localhost:9191/jsonrpc
    curl -v -H "Content-type: application/json" -X POST -d '{"jsonrpc":"2.0","method":"Settings.SetSettingValue", "params":{"setting":"audiooutput.passthrough","value":true},"id":1}' http://localhost:9191/jsonrpc
    curl -v -H "Content-type: application/json" -X POST -d '{"jsonrpc":"2.0","method":"Settings.SetSettingValue", "params":{"setting":"audiooutput.channels","value":8},"id":1}' http://localhost:9191/jsonrpc
    rm -f /tmp/avr.off
    touch /tmp/avr.on
    curl -v -H "Content-type: application/json" -X POST -d '{"id":1,"jsonrpc":"2.0","method":"GUI.ShowNotification","params":{"title":"AUDIO OUTPUT","message":"AVR","image":"/home/xbmc/.config/media/tw/images/speaker3.png"}}' http://localhost:9191/jsonrpc

fi

else

if [ -f /tmp/avr.off ] ; then

    echo avr off , avr.off exists

else

    echo avr off, no avr.off
    curl -v -H "Content-type: application/json" -X POST -d '{"jsonrpc":"2.0","method":"Settings.SetSettingValue", "params":{"setting":"audiooutput.passthrough","value":false},"id":1}' http://localhost:9191/jsonrpc
    curl -v -H "Content-type: application/json" -X POST -d '{"jsonrpc":"2.0","method":"Settings.SetSettingValue", "params":{"setting":"audiooutput.channels","value":1},"id":1}' http://localhost:9191/jsonrpc
    rm -f /tmp/avr.on
    touch /tmp/avr.off
    curl -v -H "Content-type: application/json" -X POST -d '{"id":1,"jsonrpc":"2.0","method":"GUI.ShowNotification","params":{"title":"AUDIO OUTPUT","message":"TV","image":"/home/xbmc/.config/media/tw/images/speaker3.png"}}' http://localhost:9191/jsonrpc

fi

fi


    echo end of script
    echo sleeping...
sleep 1

done

A simpler toggle script can be found here http://askubuntu.com/questions/147080/sh...o-commands

Make the script executable and on Linux use irexec or win use eventghost to run the script, or if you like you can point advanced launcher to toggle it via xbmcs GUI.



EDIT: because I feel so bad posting all this Linux info in the windows section Tongue , here is a link to a batch file to toggle between two commands (answer by Alex looks about right) http://superuser.com/a/567586

EDIT2 I think this is the icon I used for the on screen notifications, it has the same name..
http://ie.microsoft.com/TEStdrive/Browse...eaker3.png
Reply
#29
You are great, but there is a little problem.
My htpc doesn't run on win or linux, it runs on open elec

I will study if it's possible to add a script to open elec, lucky my avr is on the same lan.

I was hoping that i could launch the json rpc command through my harmony remote Big Grin

Thank you for all, i will add a reputation if i can Wink

EditBig Grinone!
Reply
#30
OE is Linux, so all that info will work. If you want to use your remote you'll need to setup irexec to execute that script. It is possible to do it completely in xbmc, but I'm not sure on how to do it. Cheers for the rep.[/b]
Reply

Logout Mark Read Team Forum Stats Members Help
How to switch audio output easily?0