I recently purchased a Nokia E63 cellphone. With a home wifi connection and an ssh client installed on the phone and after getting over the initial excitement of remote-rickrolling the people in my room, I figured that I could use the phone as a remote for MPlayer. This would allow me to watch movies while sitting comfortably on my bed without the need to get up time and again to adjust the volume or pause the movie. Cool!
Requirements
- A phone with an ssh client and wifi support
- A computer running an ssh server (I use openssh-server on Ubuntu)
- The MPlayer movie player
- The lack of a better infrared or bluetooth remote control
- Boredom
Procedure
- Installing the PuTTY ssh client the phone
- Creating the mplayyerremote user
- Creating the python script mplayerremote.py
- Creating the FIFO pipe
- Modifying the .bashrc file for the user mplayerremote
- Modifying the ~/.mplayer/config file
- Creating an MPlayer Remote profile for PuTTY
The Nokia E63 uses the Symbian S60 3rd Edition. PuTTY for Symbian can be downloaded from here.
It may be an unprivileged user. The only purpose for a new user is convenience. I set a phone-friendly password for this user. The user can be added in Ubuntu via System > Administration > Users and Groups. This will also take care of creating the home directory for the user.
Once the user is created, login as the user from a terminal.
sudo login mplayerremote
Once logged in, create a file named mplayerremote.py containing the following code:
#!/usr/bin/env python
import curses.wrapper
pipe_location="/home/mplayerremote/rc"
KEY_ENTER=10 #specific to my phone
def main(stdscr):
stdscr.addstr("MPlayer Remote\n")
while True:
pipe=open(pipe_location,'w')
c=stdscr.getch()
if c==ord('f'):
pipe.write("vo_fullscreen"+"\n")
elif c==curses.KEY_RIGHT:
pipe.write("seek 10"+"\n")
elif c==curses.KEY_LEFT:
pipe.write("seek -10"+"\n")
elif c==ord('/'):
pipe.write("seek 600"+"\n")
elif c==ord('@'):
pipe.write("seek -600"+"\n")
elif c==curses.KEY_UP:
pipe.write("volume +1"+"\n")
elif c==curses.KEY_DOWN:
pipe.write("volume -1"+"\n")
elif c==ord('j'):
pipe.write("sub_select"+"\n")
elif c==ord('o'):
pipe.write("osd"+"\n")
elif c==ord('p') or c==ord(' ') or int(c)==KEY_ENTER:
pipe.write("pause"+"\n")
elif c==ord('q'):
pipe.write("quit"+"\n")
break
pipe.close()
curses.wrapper(main)
The command nano ./mplayerremote.py
can be used to create the file. Run chmod +x ./mplayyerremote.py to make the file executable. I have only basic mplayer commands in this script. Feel free to expand it or change it. The commands I've used are:
f: fullscreen
right-arrow : seek forward 10 seconds
left-arrow : seek backward 10 seconds
up-arrow : volume up
down-arrow : volume down
'/' : seek forward 10 minutes
'@' : seek backward 10 minutes
'p' or [space] or [enter] : pause/resume playback
j: cycle through available subtitles
o: toggle osd mode
q: quit the application and mplayer
I have taken advantage of the Qwerty keyboard of the E63. For numeric keypads, this script would suck unless modified to be more convenient. The script makes use of the Curses library to capture the keystrokes
This named pipe allows us to 'talk' to mplayer. Use the following commands while you are still logged in as mplayerremote:
mkfifo rc
chmod a+rw ./rc
The python script assumes that the pipe is located at /home/mplayerremote/rc . Change the pipelocation variable in the script if you choose to put it in any other location
I wanted the mplayerremote.py script to run automatically whenever I logged in as mplayerremote and exit as soon as I quit the application. To do this, I appended the following two lines in the .bashrc file of mplayyerremote's home directory:
/home/mplayerremote/mplayerremote.py
exit
To make mplayer use the named pipe we created, we need to use the -input file=[path_of_pipe] option with mplayer. To avoid writing this every time, we can edit the ~/.mplayer/config file and append the line: input:file=/home/mplayerremote/rc
Note that this ~/.mplayer/config file is in the home directory of your normal user that usually runs mplayer and not the mplayerremote user. mplayerremote user is just the remote control and nothing more.
PuTTY for S60 allows the creation of profiles. I have created a dedicated profile for mplayerremote with the username saved. Setting the Keepalive interval (to 60 or so) may also help prevent disconnections. Effectively, the only thing I have to do to activate my remote is select the PuTTY profile, choose the home wifi connection and enter my (phone-friendly) password for mplayyerremote.
If you plan to use this, please do so at your own risk. Any suggestions and comments are welcome.
4 comments:
I'm thinking of doing a similar thing: use my humble nokia to control the audio volume on my PC. However, as my nokia does not have wi-fi, i'm thinking of doing the whole thing over bluethooth with some java app on the cellphone side and another app on the pc.
have u considered something like that?
Yes, I did think about it at first, but I'd need to buy a bluetooth dongle for my Desktop. Since I already had Wifi, I didn't pursue it.
Found this nice link that might interest you: http://tuxmobil.org/bluetooth_cell_apps.html
thanks. It took another ~hour to find that (of course) there's a ready made application for what I need and to download it. So it appears that rather than developing one, I'll just use that.
thanks for the link!
Works like a char. Thank you!
Post a Comment