Thursday, January 24, 2013

LastFm plays on my headless RPi wifi radio

At the outset, I'll point out that there will be no staggeringly huge breakthrough announced here.
Getting LastFm to play on a Raspberry Pi is really no big deal.
It's readily available as a binary in the Raspbian repos and in Gentoo on the RPi you can emerge lastfmplayer to provide the same thing.

OK, so why the post?
The problem with a headless RPi, is that no X-server is running and LastFm will only run on an X-server.
So, you need to ssh into your headless RPi and configure it for X11 forwarding.
This requires opening /etc/ssh/sshd_conf in a text editor and ensuring the line

X11Forwarding Yes
is uncommented.
Actually, these days it seems to be uncommented (or enabled) by default in all distros that I've looked at  on the RPi (Raspbian and Gentoo).

Now, on the client computer, issue the command
ssh -X [username]@[ipaddress of headless RPi]
Assuming LastFm has been installed on the headless radio and you have a valid subscription to Last.Fm, you can issue a command of the type
lastfm lastfm://artist/beatles
and a Last.Fm window should open in your client computer and start playing your preferred artist from your wifi radio.

Now, as I've already mentioned, you can ssh into, and control, your radio from your iPad.
Previously, I had used SSH Terminal for iPad which works fine to play the radio.
However, as LastFm only runs in X11, SSH terminal cannot handle it.
But, the iSSH console for iPad has an X capability and can readily play LastFm from your headless radio.
However, while the SSH Terminal cost less than €1, the iSSH cost €9 which would buy you about 4 months subscription to Last.Fm (if you pay in US$ rather than €).

The X Server configurations I used in iSSH are:

Only Tunneled Connections         OFF 
Use X Server                                 ON 
Use DWM                                     ON 
X11 Screen                                   1280x800
and this works fine for connection to the headless RPi.
When you connect and issue a command to launch Last.Fm, a small window pops up telling you that the X Client (the iPad) is connected and asks if you want to display the X Server (your RPi).
Of course, you will tap Yes and shortly you'll see the Last.Fm window opening just as it did in the client computer above.

Now, I've done quite a bit of automation to facilitate using Last.Fm on the RPi.
So, in my radio menu, I have a menu item called last_fm.
Choosing this will open another menu (opened, as with all menus on my radio, with Hai's script) which contain my preferred artists.
Each of these "artists" is actually an executable script of this type
#!/bin/bash 
killall -9 lastfm 
sudo /etc/init.d/mpd stop 
lastfm lastfm://artist/[whoever you want to hear?]
If this is chosen, LastFm will open in iSSH (after you choose to display the X Server) and play "whoever you want to hear".

I've also included one menu entry called blank which just opens an empty Last.Fm window, position the cursor in the appropriate window and sits ready for you to type in whatever you want.
This script is as follows:

#!/bin/bash 
sudo /etc/init.d/mpd stop 
killall -9 lastfm 
lastfm "$@" & 
sleep 1 
xdotool key Tab Tab 
exit
















No comments:

Post a Comment