Amarok 2 was released last December and after I first tried the beta, I really didn't like it. Amarok 1.4 was my music player of choice, you see, but the times, they are a changin'. In the upcoming release of Ubuntu (Jaunty Jackelope, 9.04) Amarok is due to be replaced by version 2. I decided to try out Amarok 2 again, figuring I will either have to get used to it, or find myself a new player.
Truth is, I still hate Amarok 2. And while I could go into details on that, it is not the reason I am here. When I was first trying to learn to love Amarok 2, I spent a while trying to fix one of my main annoyances with it:
As I found out, this guide will also work for other music players. In addition to an already set up LIRC daemon and remote control, you will need an audio player with either global hotkey support (
Step 1: Global Hotkeys
The first thing you need to do is set your global hotkeys to your media buttons.
Step 2: Set LIRC to use acpi scripts
There are scripts in /etc/acpi/ that will actually control these multimedia button functions, and if you tell LIRC to use them, you can get your remote to tell the computer that you actually hit that button on the keyboard. The associated scripts are are called playbtn.sh, stopbtn.sh, nextbtn.sh, and prevbtn.sh. You can use irexec to run these scripts by setting them up in the ~/.lircrc file. For example, I have included the play button and stop button from my .lircrc file:
*Note, your "remote =" and "button=" will vary depending on how you set up your LIRC daemon. In my example, I named my remote "AtiRW", my play button "play" and my stop button "stop". These values come from your lircd.conf file when you set it up.begin
prog = irexec
remote = AtiRW
button = play
config = /etc/acpi/playbtn.sh
end
begin
prog = irexec
remote = AtiRW
button = stop
config = /etc/acpi/stopbtn.sh
end
Set all of the buttons you want. You can even set up the vol+/vol-/mute buttons on your keyboard if you have them to change the master volume, though I prefer to use aumix or amixer to do that because there is no OSD.
When you are done setting up your keys in ~/.lircrc, save the file and close it. Then run irexec as root in the terminal with "sudo irexec" (It should have been installed with LIRC, but if it hasn't, you can install it with apt-get first.) If you have set up everything correctly, at this point you can press the buttons on your remote and it should cause the music player to function accordingly. If it doesn't work, make sure A) You set up LIRC correctly (I didn't cover that here), B) LIRC is currently running, C)You ran irexec AS ROOT (you will get an error otherwise), and D) Your media buttons on your keyboard work.
Step 3: Get irexec to run at boot
For me, irexec (the program that tells other programs/scripts to run based on LIRC input) was automatically told to run at start up with LIRC. However, even if that is the case for you too, to run these scripts irexec has to be running as root so you will have to do this next step either way. For whatever reason, and the sources I found on the internet seem to confirm it, the usual methods for starting irexec always seem to result in them being run as a normal user. We are going to have to get around that.
It would be a good time to note that, for good reason, running programs as root should be done with the utmost caution, and the only reason we are running irexec as root is because running the acpi scripts have to be run as root. (I even tried copying them to my home directory and changing the permissions/ownership with no luck.) Anybody with an alternative method that does not require irexec to be run as root should leave a comment on how to do it and I will update accordingly.
The only way I managed to get irexec to run as root was found here thanks to Ubuntu forums user Kipee. They suggest adding it to crontab. Edit crontab with:
You may be asked which editor to use, if so just select whichever one you are most comfortable with. Add a new line and insert the following, replacing USER with your username:sudo crontab -e
@reboot sleep 30 && export DISPLAY=:0 &&/usr/bin/irexec -d /home/USER/.lircrc
"@reboot" tells it to run when the machine is booted. "sleep 30" causes irexec to wait 30 seconds before starting, and is only to make sure that the LIRC daemon is running before trying to run irexec. (Note: in Kipee's post, they use 120, but two whole minutes seems longer than necessary in my experience). Close out of crontab (ctrl+x if you are editing with nano) and make sure to save it. Now reboot. When the machine reboots, irexec should now start running (remember, after 30 seconds), and when you open up your favorite media player, it should respond to remote control input.
Other Considerations
These directions assume you have multimedia buttons on your keyboard, and I am not entirely sure how one could achieve the same effect without those multimedia buttons. (If you try running the acpi scripts without assigning them to a key, they don't work!) If you are using a player with configurable shortcut keys (like Amarok 2), I would imagine it would be possible, though I haven't tried it, to use irxevent to fake keypresses in that program
And in case you were wondering, I switched to Exaile, and now that I've bypassed the hurdle of being able to use my remote, I am loving it.