2011-12-06

anyremote j2me client

I purchased a couple low-cost, used j2me-capable phones on eBay recently for a j2me development project. While watching a movie with my wife on our desktop computer the other day (we do not have a TV) and getting up repeatedly from the couch to walk over to the desktop to adjust the volume, I got the idea to write a simple j2me MIDlet that could use a phone's bluetooth interface to function as a remote control for the desktop.

It turns out that there is already an open source project for that called anyRemote. There are packages for it in debian stable:

1
sudo apt-get install anyremote

I know that one of my phones, a Nokia 5130-c2 with T-Mobile firmware, will throw a SecurityException if an unsigned MIDlet tries to access any APIs that require permissions (including bluetooth). The GNU autotools-based build for anyremote-j2me-client does not include options to sign your MIDlet. Since I already wrote a portable ant-based build system for another j2me MIDlet that includes a step to sign a jad and also ensures that jar MANIFEST and jad metadata are consistent, I ported my build scripts to the anyremote j2me client.

I published my build of the anyremote-j2me-client on github.

If you will be running the anyremote j2me client on a Nokia and need to sign your MIDlet, check out my previous blog post on installing self-signed code-signing certificates on nokia s40 handsets.

It took a little trial and error to get the client working with VLC. I'm pasting my notes below.

vlc with anyremote

I tried the ganyremote gtk client for anyremote, but I didn't have any luck with it. Having said that, I spent no more than a minute trying to get it to work with VLC, and I did not RTFM at all.

I figured out how to use the console-based anyremote server after a quick scan of the manpage, and that's what I document below.

First we need to configure VLC to play a media file, and run an embedded HTTP server on host:port localhost:8080 to accept commands from remote clients:

1
vlc -I http --http-host localhost:8080 mymovie.avi

Then we need to configure the anyremote server to listen on our bluetooth interface, using a configuration customized for remote VLC control. In the following example, the anyremote server listens on bluetooth channel 19:

1
anyremote -s bluetooth:19 -f /usr/share/anyremote/cfg-data/Server-mode/vlc.cfg

To find a list of cfg files installed with anyremote, run:

1
dpkg -L anyremote-data |grep cfg

Down the road, I will play around with customizing the config file and store my modified file in some subdirectory of $HOME.

As root, we need to make our bluetooth adapter visible to external bluetooth client scans:

1
sudo hciconfig hci0 piscan

Once the anyremote server is running and our hci0 interface allows remote clients to scan the channels, the anyremote-j2me-client can search for peers, find the anyremote server, and then connect to the service.

Then the remote control interface will be launched on the client, and we can pause, stop, fast forward, rewind, and adjust volume.

anyremote-j2me-client build for nokia 5130c2

My Nokia 5130 has a 240x320 resolution. The default vlc configuration for anyremote uses 4-rows of buttons. I found that the 48-pixel icon set is the best size for the nokia screen. I'm guessing that, for any given j2me device, you should calculate:

icon_size_max = vertical_resolution / 6

And then choose the larges available icon size that is < icon_size_max. For me that is 48-pixels, which means that I built my anyremote-j2me-client using:

1
ant -Dicon.size=48 -Dsign.app=true clean package

No comments:

Post a Comment