Use your remote with Amarok and Last.fm
If you have an amplifier (or something similar) with a remote and your computer attached to it, there are probably several buttons that don’t do anything in this configuration. In my case, it’s the buttons available to control a CD or tape deck. Wouldn’t it be neat to repurpose those? In short, all you need is an IR receiver, LIRC and a handful of commands. There are already quite a few tutorials on the net for doing this but many are a bit dated and so I think this post still brings something new, if simply by addressing installing LIRC on Ubuntu Jaunty to use Amarok 2.
First off, get an infrared receiver. I got a serial one off of ebay very cheaply, just search for “lirc.” You can often reuse receivers from other gadgets, LIRC is quite flexible that way. Let’s now begin with a plugged in receiver but nothing else. How do you know it’s even working? First, load the appropriate module. In my case,
lirc_serial. You could let the LIRC script load it but
/etc/modules works just as well. Put the model name for your remote in
/etc/init.d/lirc and you should be mostly done.
The command irw should now return correct values for the remote on individual button signals. If the device cannot be found, consider running the command with root privileges and make sure the LIRC device exists. In Ubuntu, you often have to reference /dev/lirc0 because /dev/lirc is the default many scripts assume.
If your remote doesn’t work, try adding it to
/dev/ttyS0 uart none, of course, adjust ttyS0 as necessary and consider rebooting.
However, what do you do if your remote isn’t in the list of remotes LIRC knows? No problem, LIRC can learn new remote signals, too. Just call irrecord and follow the on-screen instructions.
After that you can move the resulting file to
/etc/lirc/lircd.conf and the remote should work. To complete the setup you still have to tell LIRC what to do when you press a button. There are several alternatives to settings things up but calling
irexec -d from the autostart folder is probably one of the quickest. Irexec by default calls
~/.lircrc. Here is a short excerpt from my configuration, of course the button names of your remote might be completely different.
begin prog = irexec remote = abc123 button = play config = dbus-send --type=method_call --dest=org.kde.amarok /Player org.freedesktop.MediaPlayer.Pause end begin prog = irexec remote = abc123 button = stop config = dbus-send --type=method_call --dest=org.kde.amarok /Player org.freedesktop.MediaPlayer.Stop end
Now, what was this talk about Last.fm earlier? Well, Amarok has decent support for Last.fm built-in and even has a little ❤ button on the main toolbar so you can favorite a song. You can easily call this feature over DBUS, too:
dbus-send --type=method_call --dest=org.kde.amarok /amarok/MainWindow org.kde.amarok.MainWindow.loveTrack
So, now you can flip through your music collection from your couch, skip a track and even favorite it in Last.fm without having to to use your computer. What could be improved? Lots. For one, moving to the MPRIS namespace in DBUS would make the whole thing more flexible, but I’m skeptical that it will ever support things like the ❤ button. Also, I tried org.freedesktop.MediaPlayer.Seek but it didn’t work as expected.