Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.


Channels ▼
RSS

Embedded Systems

Radios, Cell Phones, & Java


Tea is a consultant focusing on security and mobile technology. He can be contacted at [email protected].


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 TunerControl—the 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 states—REALIZED, 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) {}
}



Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.