Skip Headers
Oracle® Java Micro Edition Software Development Kit Developer's Guide
Release 3.0.5 for Windows
E24265-04
  Go To Table Of Contents
Contents
Go To Index
Index

Previous
Previous
 
Next
Next
 

18 JSR 135: Mobile Media API Support

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. See the following topics:

For information on programming with MMAPI, see the following articles:

Mobile Media API Overview: http://developers.sun.com/techtopics/mobility/apis/articles/mmapi_overview/

The J2ME Mobile Media API: http://www.jcp.org/en/jsr/detail?id=135

18.1 Media Types

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

MIME Type Description

audio/amr*

Adaptive Multi-Rate Narrow Band

audio/midi

MIDI files

audio/mpeg*

MP3 files

audio/mp4*

MP4 Audio files

audio/sp-midi

Scalable Polyphony MIDI

audio/x-tone-seq

MIDP 2.0 tone sequence

audio/x-wav*

WAV PCM sampled audio

image/gif

GIF 89a (animated GIF)

video/3gpp*

Third generation mobile broadband with video

video/mpeg*

MPEG video

video/mp4*

MP4 video files

video/avi*

Video capture emulation and Audio-Video Interleaved files


In the previous table, an asterisk (*) indicates a media type that requires corresponding DirectShow filters to be installed on your system. For example, MP3 support might require an MP3 Splitter and an MP3 Decoder (these might be two separate DirectShow filters, or they might be combined in one filter). Any appropriate filters can be used, but Java ME SDK 3.0.5 has only been tested with filters from the K-Lite Mega Codec Pack 4.8.0. If no appropriate DirectShow filters are found on your system, JSR 135 Player creation for the media type might fail.

18.1.1 Media Capture

The Java ME SDK emulator supports audio and video capture. Audio capture is supported 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.

18.2 MMAPI MIDlet Behavior

MIDlets have a lifecycle 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 Java ME SDK 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.

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

18.3 Ring Tones

MMAPI can be used to play ring tones, as demonstrated in Section 18.5.1, "Simple Tones" and Section 18.5.2, "Simple Player". The ring tone formats mentioned here are in common use. You can download ring tones or create your own.

18.3.1 Download Ring Tones

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

18.3.2 Ring Tone Formats

This section provides samples of several formats

  • RTTTL, the Ringing Tones text transfer language format, is explained at

    http://www.convertyourtone.com/rtttl.html

  • Nokia Composer

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

    16g1,16g1,16g1,4#d1,16f1,16f1,16f1,4d1,16g1,16g1,16g1,16#d1,

    16#g1,16#g1,16#g1,16g1,16#d2,16#d2,16#d2,4c2,16g1,16g1,16g1,

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

  • Ericsson Composer

    Beethoven's Minuet 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

  • Siemens Composer Format

    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)

  • Motorola Composer

    Beethoven's 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

  • Panasonic Composer

    Beethoven's 9th symphony:

    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**

  • Sony Composer

    Beethoven's 9th symphony:

    444****444****444****111#*****444#****444#****444#****

    111*****(JD)0000444****444****444****111#****444#****

    444#****444#****444****11#****11#****11#****666#*****

    444****444****444****111****444#****444#****

    444#****444****22#****22#****22#****

18.4 Running AudioDemo

Demonstrates audio capabilities, including mixing and playing audio with an animation. Select a MIDlet from the list, and from the menu, select 1, Launch.

18.5 Running MMAPIDemos

The MMAPIDemos application contains four MIDlets that showcase the SDK's multimedia capabilities:

18.5.1 Simple Tones

Simple Tones demonstrates how to use interactive synthetic tones. Select a sample, then click Play on the lower right.

  • Short Single Tone and Long Single Tone use Manager.playTone() to play tones with different pitch.

  • Short MIDI event plays a chord on the interactive MIDI device (locator "device://midi"). The shortMidiEvent() method of MIDIControl is used to trigger the notes of the chord.

  • To run the MMAPI Drummer demo, click or type number keys (0-9). Each number plays a different sound.

18.5.2 Simple Player

The Simple Player application demonstrates the range of audio and video capabilities of the emulator. It includes sample files in a variety of formats and can play files from the emulator's persistent storage or from HTTP URLs.

The player portion uses a generic javax.microedition.media.Player interface. The player displays duration, media time, and controls for running the media file. If metadata is available in a file, the player enables you to view the information, such as author and title. In the case of MIDI files, if karaoke text is present in the file, it displays on the screen during play. Graphical user interface controls can be viewed on the display screen if applicable. You can access these controls by selecting one of the media samples in Simple Player, then pressing the Menu button to view and select the desired command.

Select Simple Player then click Launch. The demo includes the following media samples:

  • Bong plays a short WAV file. You can adjust certain playback features, as described later in this document. The display shows the duration of the sound in minutes:seconds:tenths of a second, for example 00:17:5. This audio sample is a resource file in the MIDlet suite JAR file.

  • MIDI Scale plays a sample musical scale. The display shows the title of the selected music file, the duration of the song, the elapsed time during playback, and the current tempo in beats per minute (bpm). This MIDI file is stored in the MIDlet suite JAR file.

  • Simple Ring Tone plays a short sequence of Beethoven's Fifth Symphony. The display shows the title of the selected music file, the duration of the song, the elapsed time in seconds and tenths of a second during playback, and the current tempo in beats per minute (bpm). This ringtone file (.jts format) is stored in the MIDlet suite JAR file.

  • WAV Music plays a brief audio file. The display shows the title of the audio file, the duration of the audio the elapsed time during playback, and the playback rate in percent. This WAV file is retrieved from an HTTP server.

  • MIDI Scale plays a MIDI file that is retrieved from an HTTP server.

  • The Animated GIF example shows an animated GIF that counts from 1 to 5. The file is stored in the MIDlet suite JAR file.

  • Audio Capture from a default device lets you capture audio from a microphone or connected device. The sound is captured and played back on the speaker. To avoid feedback, use a headset.

  • Video Capture Simulation simulates viewing input video such as might be possible on a device equipped with a camera.

  • MPEG1 Video [http]. Plays an MPEG video found at http://java.sun.com/products/java-media/mma/media/test-mpeg.mpg.

  • [enter URL] allows you to play back media files from arbitrary HTTP servers. Type a valid URL at the insertion point and click OK to play a file. If you want to open an HTTP directory from which to select media, be sure to add a slash to the end of the URL.

In addition, Simple Player parses ring tones in Ringing Tones text transfer language (RTTTL). See http://www.convertyourtone.com/rtttl.html for information on RTTTL.

The Simple Player includes a common set of commands that control media playback. The commands are available from the Simple Player menu, and some have associated keypad buttons. Table 18-1 describes these commands, their availability, and their keypad equivalents. The commands may or may not be available depending on the media type that Simple Player is playing.

Note that a short list of commands and the corresponding keypad buttons is available in the Simple Player application itself. Just choose the Quick Help command from the menu.

Table 18-1 Simple Player Commands 

Command Menu Item Description

Mute/Unmute

1

Turns off sound but the file continues to play. This command toggles to Unmute.

Play

2

Play.

Volume

3

Increases or decreases loudness.

META Data

4

Displays information provided by the media file such as copyright information, title, and track list.

Stop in 5 seconds

5

Pauses the audio play in five seconds when set during playback.

Loopmode

6

After playing, repeat.

Rate

7

Alters the rate of speed of playback.

Tempo

8

Increases or decreases the tempo of the tone sequence or MIDI file.

Pitch

9

Lowers or raises the notes in a MIDI file.

Skip Forward


Skips forward five percent of the duration of the media file. The sound track syncs to the video

Skip Backward


Skips backward five percent of the duration of the media file. The sound track syncs to the video.

Rewind


Returns to the start time of the audio playback.

Quick Help


Displays a list of commands and keypad buttons.


18.5.2.1 Video

The Video application illustrates how the emulator is capable of playing animated GIF files and capturing video. On a real device with a camera, video capture can be used to show the user what the camera sees.

Animated GIFs and video capture can be implemented using either a Form Item or a Canvas. The Video demonstration includes all the possibilities. Animated GIF - Form [jar] shows an animated GIF as a Form Item. The form also includes some information about the playback, including the current time. Choose the Snapshot command to take a snapshot of the running animation. The snapshot will be placed in the form following the animated GIF.

  • Animated GIF - Canvas [jar] shows an animated GIF in a Canvas. A simple indicator shows the progress through the animation. Choose Snapshot to get a still image of the current appearance. The snapshot is shown briefly, then the display goes back to the animation.

  • Video Capture - Form simulates capturing video from a camera or other source and showing it as an Item in a Form. Choose the Snapshot command to take a snapshot of the captured video. The snapshot will be placed in the form following the video capture.

  • Video Capture - Canvas simulates capturing video from a camera or other source and showing it in a Canvas. Choose Snapshot to get a still image of the current appearance. The snapshot is shown briefly, then the display goes back to the video capture.

  • MPEG1 Video - Form, MPEG1 Video - Canvas

    The MPEG1 applications obtain MPEGs from the web, so if you are behind a firewall, you must configure the emulator's proxy server settings, as described in the topic "Section 3.4, "Configuring the Web Browser and Proxy Settings".

    When you play the demo, expect to wait a few seconds while the demo obtains the data. The MPEG1 demos have the same behavior as Video Capture - Form and Video Capture - Canvas, respectively.

18.5.2.2 Attributes for MobileMediaAPI

The MobileMediaAPI applications have the following editable attributes. Right-click on the project and select Properties. Select Application Descriptor and view the Attributes tab.

Table 18-2 Descriptions of MMAPI-specific MIDlet attributes

Attribute Description

PlayerTitle-n

Name of the nth media title to be played back by the Simple Player MIDlet.

PlayerURL-n

Location of the nth media title, PlayerTitle-n, to be played back by the Simple Player MIDlet.

VideoTest-n

The name of the nth media title to be played back by the Video application.

VideoTest-URLn

Location of the nth media title, VideoTest-n, to be played back by the Video application.