The Advanced Multimedia Supplements (JSR-234) is a Java API that provides 30 controls for applications ranging from cameras and media postprocessing to radio tuners and advanced audio (www.jcp.org/en/jsr/detail?id=234). In this article, I focus on TunerControlthe control that lets you create applications that utilize the radios built into mobile devices such as cell phones. To that end, I present an example application called "AMMS Radio" that demonstrates turning on/off the radio, switching between stereo and mono reception, manipulating radio station presets, autodialing to radio stations, and other activities, which will be described in this article. The complete source code and related files that implement AMMS Radio are available at http://www.ddj.com/code/.
Before building any radio applications, however, you need to confirm Advanced Multimedia Supplements (AMMS) and modulation support. For AMMS support, use the system properties to verify the AMMS version and AMMS media capabilities:
System.getProperty ("microedition.amms.version"); System.getProperty ("supports.mediacapabilities");
The current version is "1.0," and the media capabilities must include "tuner" in the return list.
The application should also use tuner.modulations to check for the modulations supported by the phone:
System.getProperty ("tuner.modulations");
Currently, AMMS 1.0 only supports AM and FM modulations.
Once these capabilities are verified, you need to initiate TunerControl by creating a Mobile Media API (MMAPI) player for the built-in radio. You then construct the radio player by setting the player to the REALIZED state. Finally, you create the AMMS TunerControl from the radio player:
Player radioplayer = Manager.createPlayer( "capture://radio"); radioplayer.realize(); tunerControl = (TunerControl) radioplayer.getControl( "TunerControl");
Because the radio can only be started from a PREFETCHED state, use the getState() method to check the state of the radio player:
if (radioplayer.getState()== radioplayer.PREFETCHED) { try { radioplayer.start(); } catch (Exception e) {} }
The radio player can only be in one of four statesREALIZED, PREFETCHED, STARTED, or CLOSED. When the radio is started, its state changes to STARTED. When the radio is stopped, it switches back to PREFETCHED. To stop the radio:
if (radioplayer.getState()== radioplayer.STARTED) { try { radioplayer.stop(); } catch (Exception e) {} }