Bug 212091 - Configure phonon from command line
Summary: Configure phonon from command line
Status: CONFIRMED
Alias: None
Product: Phonon
Classification: Frameworks and Libraries
Component: general (show other bugs)
Version: unspecified
Platform: Ubuntu Unspecified
: VLO wishlist
Target Milestone: ---
Assignee: Harald Sitter
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-10-27 19:01 UTC by Romain Henriet
Modified: 2018-04-20 12:02 UTC (History)
11 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
bash script to redirect audio using Pulse Audio controls (3.67 KB, text/plain)
2016-03-15 22:53 UTC, Joe
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Romain Henriet 2009-10-27 19:01:48 UTC
Version:            (using KDE 4.3.2)
Installed from:    Ubuntu Packages

It would be nice if phonon was able to be configured from a terminal. 
For example, if you want to listen music on another sound card, it is faster to run a small script to change default sound output than opening systemsettings and dragging your device top of phonon's peripherals list.
Comment 1 Harald Sitter 2011-03-02 02:16:09 UTC
When would you need to do this actually? I mean, you should not have to switch devices like that...
Comment 2 Romain Henriet 2011-03-02 08:13:38 UTC
Here is an example :
My computer has small speakers (analog output) and is connected through HDMI to my home theater. When I'm working, I listen to musik on my desktop speakers (using amarok), thus phonon is configured for analog output.
But when I'm in my sofa, I want to listen to music in my HiFi speakers and I want phonon to be configured for HDMI output. For now, I have to open system settings and swith configuration by hand. 
A script would be a lot easier. 
Isn't scripting what makes linux so powerful ?
Comment 3 Harald Sitter 2011-03-02 21:31:43 UTC
The case you highlighted is a genuine problem that, I am certain, more people experience. In particular I think this is a problem that needs to be addressed in accessible manner, i.e. so that everyone can use it, even without scripting skills.

Possibly a Plasma applet could help? I imagine something like profiles for device order. Then you could have a profile 'PC' and a profile 'Home Theater' and using the plasma applet you could quickly switch between them.

What do you think about this approach?
Comment 4 Romain Henriet 2011-03-03 21:25:24 UTC
Yes a plasmoid could be useful for people not willing to deal with scripts.
And such a plasmoid could use phonon's dbus interface !
In fact, plasmoid alone is difficult to integrate into a sequence with other instructions.

Here is my script "pc_hifi":

#!/bin/bash

Moniteur="CRT2"
Tele="DFP2"

while xrandr | grep "$Tele disconnected"
do
    # Output disconnected
    kdialog --warningcontinuecancel "Switch HT on !"
  if test $? -eq 2
    then
        exit 1
    fi
done

xrandr --output $Tele --mode 1680x1050

# Activate "Musique" energy profile
qdbus org.kde.powerdevil /modules/powerdevil setProfile Musique
# Replace phonon's config file to use hdmi
config_phonon "hdmi"
# Switch fan2 off
fan2_ctrl off
# Run amarok and start playing
amarok --play
Comment 5 Harald Sitter 2011-03-03 21:40:33 UTC
Well, you are calling powerdevil's dbus interface, were would be the problem in calling Phonon's?
Comment 6 Romain Henriet 2011-03-03 22:16:54 UTC
None, that what I searched for when I wrote my script but I can't see any interface for Phonon :s.
Is it able to make me switch outputs ?
I didn't find any help on forums so I thought it didn't exist !
Comment 7 Harald Sitter 2011-03-04 13:50:56 UTC
Because it is not there yet. But I imagine the plasmoid to call via dbus to the kded module phononserver, which then conducts the profile switch.
Comment 8 gapon 2011-12-10 08:30:23 UTC
Would be nice to have this implemented.
Comment 9 freeseek 2011-12-15 04:40:24 UTC
I actually have the same problem. When I plug my laptop to HDMI, Phonon 'automatically switches the Hardware Profile from "Analog Stereo Output" to "Digital Stereo (HDMI) Output". This is very annoying as my monitor does not have speakers, so I have to manually revert this unrequested change. It would be nice if there was an automatized way to revert this choice, or even better a way to stop this automatic change from taking place.
Comment 10 Marius Bjørnstad 2012-07-05 16:07:35 UTC
I would like this too. I need to change between headphones and speakers, which are connected to two different outputs. I found a script on an Ubuntu page, but it works on F18: http://askubuntu.com/questions/71863/how-to-change-pulseaudio-sink-with-pacmd-set-default-sink-during-playback . I consider this to be only a workaround, because it's specific to PulseAudio it produces several information popups, and it overrides any specific application -> output mappings one may have done.
Comment 11 Marius Bjørnstad 2012-07-05 17:41:55 UTC
Actually, the script shouldn't be used on KDE, as it only moves running streams, and possibly messes up their config. I found another workaround for me, to always play to both devices using module-combine-sink. Sorry for posting twice, but I think this is on topic (while we wait for a real solution) https://wiki.archlinux.org/index.php/PulseAudio/Examples#Simultaneous_HDMI_and_Analog_Output
Comment 12 Harald Sitter 2012-07-05 18:36:48 UTC
actually Phonon's device priority is exactly the same as PA's when PA is installed and running, so if you change the default there you get the same result

running streams is a different matter tho
Comment 13 Tyrell 2013-03-09 23:15:39 UTC
Is there a direct method of modifying Phonon from the command line yet?  

When I'm at home, I plug my laptop into the home theater via HDMI; Fedora 18 does nothing automatically, so the switch requires me to change the video output to HDMI, the screen resolution to 1024x768, and the audio to HDMI 5.1.  Making the changes by hand is inconvenient.  My school's library also has computer hookups to the group study TVs, and this creates a similarly inconvenient situation; If nothing else, it certainly doesn't do any favors when trying to sell my friends on the greatness of Linux ;)  Finally, when I am running out of the house in the morning, and want to switch over quickly to grab my laptop, this can be quite the time dump.  

Anyway, real world situations aside, it WOULD be really nice if I could change the configuration quickly and easily by running a script from my desktop.  

It's been 8 months since the last comments... Have there been any advancements in the process since then?
Comment 14 Harald Sitter 2013-06-30 10:16:20 UTC
> It's been 8 months since the last comments... Have there been any advancements in the process since then?

No. Feel free to work on it. (it = undefined)
Comment 15 Graeme Hewson 2013-12-24 17:37:14 UTC
OS X has the feature that if you click on the speaker icon in the menu bar while holding the Mac Option (Alt) key, a popup is displayed that allows you to change the input and output devices.

It would be good to have the same feature in the KMix panel applet.
Comment 16 Shervin Emami 2014-05-09 23:41:49 UTC
I get a similar problem on both of my laptops (a Dell Inspiron 14 and a Lenovo W520) and it's the same problem whether I use Debian KDE or the latest Arch KDE:

My sound card supports both HDMI out and Analog out, but I only use the Analog (Stereo Duplex). Normally the "Connector" setting in "Device Configuration" is set to Speakers, so I hear the audio through the laptop speakers. But when I plug headphones into my laptop, it still tries to play through the speakers, instead of switching the "Connector" setting to "Headphones". So I must manually open KMix -> Audio Setup -> Audio Hardware Setup -> Connector and select Headphones whenever I want to start using my headphones, and do the same to switch to speakers when I later unplug my headphones.

Note that this also effects the microphone source. If Connector is set to "Speakers" then it uses the laptop internal microphone, but if I plug in my headset it will still be using the laptop microphone until I set Connector to "Headphones" so that it will start using the microphone in my headset.

If there was some easier way to do this, whether it is a command-line script or a KDE plasmoid or just a global keyboard shortcut, I don't care, since they all would be much better than the current tedious solution (that I often perform about 20 times per day including just before important business meetings through Skype!). Ideally, Phonon would automatically switch between headphones and speakers automatically, since this is what people have been used to for many decades (ie: you buy a radio, it plays sound through the speakers but automatically switches to headphones once you plug headphones into the socket!). But if that is too complex to get working then my next preference would be a global shortcut in KDE, so I can easily switch between headphones and speakers. Command-line or plasmoid would be last option but still much better than what it is now!
Comment 17 Joe 2016-03-15 22:53:29 UTC
Created attachment 97917 [details]
bash script to redirect audio using Pulse Audio controls

Workaround for this issue. Script is somewhat hard coded for my situation, but should be a good starting point for others.
Comment 18 Joe 2016-03-15 23:01:31 UTC
It's been quite awhile since I have visited this. I have worked around this issue using Pulse Audio.
My script is attached.

The issue for developers is that there is no automatic way to determine where you want the audio to go when you activate a new video display. So you do need a user script/gui to handle it the way you want it to work. 

Once you have the script, you can activate it using udev rules (if you can figure out how ;(   ).
Comment 19 Marcelo Bossoni 2016-03-16 16:37:54 UTC
Thanks for the script Joe
I'll probably need to change it to query xrandr instead, since I wan't to route audio only when HDMI video is enabled, not just connected.
Comment 20 Joe 2016-03-16 16:55:45 UTC
(In reply to Marcelo Bossoni from comment #19)
> Thanks for the script Joe
> I'll probably need to change it to query xrandr instead, since I wan't to
> route audio only when HDMI video is enabled, not just connected.

Hack away! It's sufficiently hard-coded so that you have to modify it anyway.
The main deal is that you know where to look for the interface which switches the audio.

I would appreciate a copy of anything you get to work (off list). Especially if it ends up less hard-coded than my version. Of course, that's optional since it's GPL code.