C H A P T E R  8

Using the Mobile Media API

JSR 135, the Mobile Media API (MMAPI), provides a standard API for rendering and capturing time-based media, like audio or video. The API is designed to be flexible with respect to the media formats, protocols, and features supported by various devices. For information on programming with MMAPI, see the following articles:


8.1 Supported Formats and Protocols

The emulator's MMAPI implementation supports the following media types.

TABLE 8-1 Supported MMAPI Media Formats




Adaptive Multi-Rate


MIDI files


Scalable Polyphony MIDI


MIDP 2.0 tone sequence


WAV PCM sampled audio


GIF 89a (animated GIF)


MPEG video


Video capture

8.2 Adaptive Multi-Rate (AMR) Content

The Sun JavaTM Wireless Toolkit for CLDC simulates support for Adaptive Multi-Rate (AMR) content (http://www.ietf.org/rfc/rfc3267.txt). Although the toolkit cannot decode AMR content, the implementation returns a player for AMR content when requested.

8.2.1 Windows

On Windows, AMR files are converted to regular WAVE files and passed to Qsound. Because the Windows version interfaces with the 3GPP implementation, you do not have to do anything to ge t AMR files to play.

8.2.2 Linux

The AMR support for Linux is based on the 3GPP AMR Narrow Band (AMR-NB) Reference Implementation decoder and the SOX audio processor (AMR Wide Band is not supported). Enabling AMR Support

Follow these steps to enable AMR support.

1. Get the AMR-NB RI provided by 3GPP.

There are several versions available. One can be found here:


2. Open the makefile contained in the package.

Find the line starting with 'CFLAGS = '.

a. Add the DMMS_IO option.

b. Remove the pedantic-errors option.

Save and compile. If you have problems, try removing the the O3 (or O2) optimization flags as well (the binaries will be nearly twice the size).

3. To build the RI , enter: make VAD=VAD1

After the compilation you should have a binary file named decoder. That's the AMR-NB decoder itself.

4. Set the environment variable AMR_DECODER to point to the path to the decoder.

For example, if ~/amr is the path to the decoder, specify:

export AMR_DECODER=~/amr/decoder

5. Set execution access rights for the decoder file.

In the same directory as the decoder, type:

chmod 555 ./decoder

6. Test the decoder as follows:

Run the MobileMediaAPI demo Simple Player as described in Section A.13, MobileMediaAPI. From the main menu select Simple Player and then 'AMR Narrow Band [jar]'. Don't forget to turn your speakers on. AMR Format Support

You may also encounter problems with some "clones" of the AMR-NB. There appear to be at least two file formats for AMR-NB codec data:

This is specified in draft-ietf-avt-rtp-amr-10.txt, Sec. 6.2, which is included with the Ericsson AMR converter tool. (The draft is an early form of RFC 3267). These files are handled by the Ericsson AMR tool and Nokia Series 60 phones. They have a header of #!AMR\n and they're encoded in big-endian.

This format is specified in 3GPP TS 26.101, Appendix A. These are coded and decoded by the 3GPP TS 26.104 floating point reference codec source package. These files have no header and are encoded in little-endian.

To convert from between these formats try this Python script:


8.3 Using MediaControlSkin

The Sun JavaTM Wireless Toolkit for CLDC comes with an emulator skin, MediaControlSkin, that is focused on multimedia playback and control. The skin includes buttons with symbols representing play, stop, volume up and volume down, and other commands. To see the usefulness of MediaControlSkin, try it out with the MobileMediaAPI demonstration application.

8.4 Media Capture

The Sun JavaTM Wireless Toolkit for CLDC emulator supports audio and video capture. Audio capture is supported by using the capture capabilities of the system upon which the emulator runs.

Video capture is supported by simulating a camera input.

Consult the MobileMediaAPI example application for details and source code that demonstrates how to capture audio and video.

8.5 Well-Behaved MIDlets

MIDlets have a life cycle that is defined in the MIDP specification. MIDlets can be paused by events such as incoming phone calls. A well-behaved MIDlet releases important device resources when it is paused and reallocates or restarts those resources when the MIDlet is resumed. In the MMAPI arena, stop any Players that are rendering content when a MIDlet is paused.

The Sun JavaTM Wireless Toolkit for CLDC prints a message to the console if you pause a MIDlet and it does not stop its running Players. You can test this feature using the Pausing Audio Test MIDlet in the MobileMediaAPI demonstration application. See Appendix A for details.

The warning message is printed once only for each running emulator.

8.6 Ring Tones

MMAPI can be used to play ring tones, as demonstrated in Section A.13.1, Simple Tones and Section A.13.2, Simple Player. Several ring tone formats are in common use. You can download ring tones or create your own.

8.6.1 Download Ring Tones

Ring tone files can be downloaded from many internet sites, including the following:

8.6.2 Ring Tone Formats

This section provides samples of several formats


This is a rendition of Beethoven's 9th symphony in Nokia Composer format:



16d1,16#g1,16#g1,16#g1, 16g1,16f2,16f2,16f2,4d2

Beethoven's Menuett in G:

a b + c b + c b + c b + C p + d a B p + c g A

p f g a g a g a g A p b f G p a e F

Beethoven's 9th symphony theme:

f f f # C # d # d # d C p f f f # c # f #f # f f +# c + # c + # c # A ff f c # f # f # f f + # d + # d + # d

Inspector Gadget theme:

C2(1/8) D2(1/16) Dis2(1/8) F2(1/16) G2(1/8)

P(1/16) Dis2(1/8) P(1/16) Fis2(1/8) P(1/16)

D2(1/8) P(1/16) F2(1/8) P(1/16) Dis2(1/8)

P(1/16) C2(1/8) D2(1/16) Dis2(1/8) F2(1/16)

G2(1/8) P(1/16) C3(1/8) P(1/16) B2(1/2) P(1/4)

C2(1/8) D2(1/16) Dis2(1/8) F2(1/16) G2(1/8) P(1/16)

Dis2(1/8) P(1/16) Fis2(1/8) P(1/16) D2(1/8) P(1/16)

F2(1/8) P(1/16) Dis2(1/8) P(1/16) C3(1/8) B2(1/16)

Ais2(1/8) A2(1/16) Gis2(1/2) G2(1/8) P(1/16) C3(1/2)

Beethovens 9th symphony:

4 F2 F2 F2 C#4 D#2 D#2 D#2 C4 R2 F2 F2 F2 C#2 F#2 F#2

F#2 F2 C#+2 C#+2 C#+2 A#4 F2 F2 F2 C2 F#2 F#2 F#2 F2

D#+2 D#+2 D#+2

Beethovens 9thsymphony:

444** 444** 444** 1111* 4444** 4444** 4444** 111*

0** 444** 444** 444** 1111** 4444** 4444** 4444**

444** 11** 11** 11** 6666* 444** 444** 444** 111**

4444** 4444** 4444** 444** 22** 22** 22**

Beethovens 9th sympony: