Skip Headers
Oracle® Java Micro Edition Software Development Kit Developer's Guide
Release 3.3 for NetBeans on Windows
E24265-05
  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 given 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.

Table 18-1 Supported MIME 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). You can use any appropriate filter, but Java ME SDK 3.3 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 Oracle 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 MMAPIDemo 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 Oracle 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.

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

18.3 Ring Tones

MMAPI plays ring tones, as demonstrated in "Simple Tones" and "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://en.wikipedia.org/wiki/Ring_Tone_Transfer_Language

  • 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.hundredths of a second, for example 00:01.04. 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 ring tone 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.

  • AMR Narrow band. Plays an Adaptive Multi-rate narrow band file. This sample requires an AMR codec. This sample was tested with the K-Lite Mega Codec Pack 4.8.0. This codec is freely downloadable.

  • 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. For example, on a device equipped with a camera.

  • [enter URL] Plays 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 menu lists commands that control media playback.

The first menu item, Quick Help, displays a list of commands and actions mapped to keypad buttons. Some actions are not applicable for every media type.

The remaining menu items vary depending on the media type. Some actions, such as Rate, open a control with which you can arbitrarily change the playback. Click Back to return to the player screen and see or hear your changes.

18.5.3 Video

The Video application illustrates how the emulator is capable of playing animated GIF files and capturing video. On an external device with a camera, video capture shows 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 in a Form. A simple indicator shows the progress through the animation. The form also includes some information about the playback, including the current time.

  • Animated GIF - Canvas [jar] shows an animated GIF in a Canvas. A simple indicator shows the progress through the animation.

  • Video Capture - Form simulates capturing video from a camera or other source and showing it as an Item in a Form. Select Snapshot to take a snapshot of the captured video. The snapshot is placed beneath the video capture for comparison.

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

18.5.4 Pausing Audio Test

This test MIDlet demonstrates the proper use of pauseApp()and the alternative.


WARNING:

Do not run the memory monitor while using this demo.


In the Well-Behaved case suspending uses pauseApp() to close the player and remembers the length of time the audio file played. When the player resumes, it starts playing the audio file at the point that it was suspended.

In the Not Well-Behaved case the player is stopped instead of suspended. When the player is restarted the audio file plays from the beginning.

Test the two cases as follows:

  • Run MMAPIDemos, and launch Pausing Audio Test.

    The music starts playing. The initial value of Current State is Well-Behaved.

  • Select Application > Suspend (or F5), to pause the music.

  • Select Application > Resume (or F6) to resume playing the audio clip from the stopping point.

  • Click the Misbehave soft key.

  • Select Application > Suspend (or F5), to stop the music.

  • Select Application > Resume (or F6). The player restarts but the clip plays from the beginning.